Merge pull request #218 from TouchInstinct/feature/date_formats_support
Add method for DateFormattingService that parses date from string in …
This commit is contained in:
commit
7237efe641
|
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
### 0.9.27
|
||||
- **Add**: method `date(from string:formats:parsedIn:)` method for `DateFormattingService` that parses date from string in one of the given formats with current region.
|
||||
|
||||
### 0.9.26
|
||||
- **Add**: method `processResultFromConfigurationSingle` for `TotalCountCursor` that allows to get server response.
|
||||
- **Add**: possibility to inherit from `TotalCountCursor`.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "LeadKit"
|
||||
s.version = "0.9.26"
|
||||
s.version = "0.9.27"
|
||||
s.summary = "iOS framework with a bunch of tools for rapid development"
|
||||
s.homepage = "https://github.com/TouchInstinct/LeadKit"
|
||||
s.license = "Apache License, Version 2.0"
|
||||
|
|
|
|||
|
|
@ -40,6 +40,18 @@ public extension DateFormattingService {
|
|||
return format.stringToDateFormat.toDate(string, region: region)
|
||||
}
|
||||
|
||||
func date(from string: String, formats: [DateFormatType], parsedIn: Region?) -> DateInRegion? {
|
||||
let region = parsedIn ?? currentRegion
|
||||
|
||||
for format in formats {
|
||||
if let parsedDate = format.stringToDateFormat.toDate(string, region: region) {
|
||||
return parsedDate
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func string(from date: DateRepresentable, format: DateFormatType) -> String {
|
||||
return format.dateToStringFormat.toString(date)
|
||||
}
|
||||
|
|
@ -81,6 +93,17 @@ public extension DateFormattingService where Self: Singleton {
|
|||
return shared.date(from: string, format: format, parsedIn: parsedIn)
|
||||
}
|
||||
|
||||
/// Method parses date from string in one of the given formats with current region.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - string: String to use for date parsing.
|
||||
/// - formats: Formats that should be used for date parsing.
|
||||
/// - parsedIn: A region that should be used for date parsing. In case of nil defaultRegion will be used.
|
||||
/// - Returns: Date parsed from given string or default date if parsing did fail.
|
||||
static func date(from string: String, formats: [DateFormatType], parsedIn: Region?) -> DateInRegion? {
|
||||
return shared.date(from: string, formats: formats, parsedIn: parsedIn)
|
||||
}
|
||||
|
||||
/// Method format date in given format.
|
||||
///
|
||||
/// - Parameters:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.9.26</string>
|
||||
<string>0.9.27</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.9.26</string>
|
||||
<string>0.9.27</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.9.26</string>
|
||||
<string>0.9.27</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
|
|
|
|||
|
|
@ -49,6 +49,15 @@ public protocol DateFormattingService {
|
|||
/// - Returns: Date parsed from given string or default date if parsing did fail.
|
||||
func date(from string: String, format: DateFormatType, parsedIn: Region?) -> DateInRegion?
|
||||
|
||||
/// Method parses date from string in one of the given formats with current region.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - string: String to use for date parsing.
|
||||
/// - formats: Formats that should be used for date parsing.
|
||||
/// - parsedIn: A region that should be used for date parsing. In case of nil defaultRegion will be used.
|
||||
/// - Returns: Date parsed from given string or default date if parsing did fail.
|
||||
func date(from string: String, formats: [DateFormatType], parsedIn: Region?) -> DateInRegion?
|
||||
|
||||
/// Method format date in given format.
|
||||
///
|
||||
/// - Parameters:
|
||||
|
|
|
|||
Loading…
Reference in New Issue