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:
Ivan Babkin 2019-09-09 15:14:43 +03:00 committed by GitHub
commit 7237efe641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 4 deletions

View File

@ -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`.

View File

@ -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"

View File

@ -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:

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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: