Merge pull request #36 from TouchInstinct/feature/swift_date_migration_part_2
SwiftDate 5.0 migration part 2
This commit is contained in:
commit
ed75f2571f
|
|
@ -6,12 +6,16 @@
|
|||
import LeadKit
|
||||
import SwiftDate
|
||||
|
||||
enum ApiDateFormat: String, LeadKit.DateFormat {
|
||||
enum ApiDateFormat: String, DateFormat {
|
||||
|
||||
{% for format in dateFormats -%}
|
||||
case {{ format.name }} = "{{ format.format }}"
|
||||
{% endfor %}
|
||||
var swiftDateFormat: DateToStringStyles {
|
||||
var dateToStringFormat: DateToStringStyles {
|
||||
return .custom(rawValue)
|
||||
}
|
||||
|
||||
var stringToDateFormat: StringToDateStyles {
|
||||
return .custom(rawValue)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@
|
|||
{%- import _self as self -%}
|
||||
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
{{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}}
|
||||
.toString(ApiDateFormat.{{ dateFormatToName(field.type.dateFormat) }}.swiftDateFormat)
|
||||
ApiDateFormattingService.string(from: {{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}}, format: .{{ dateFormatToName(field.type.dateFormat) }})
|
||||
{%- elseif field.type.type.baseTypeName == "Decimal" -%}
|
||||
{{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}}
|
||||
.decimalValue
|
||||
|
|
@ -103,7 +102,7 @@
|
|||
|
||||
{% macro initExpr(field) %}
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
if let date = ApiDateFormattingService.date(from: {{ field.name }}, format: "{{ field.type.dateFormat }}") {
|
||||
if let date = ApiDateFormattingService.date(from: {{ field.name }}, format: .{{ dateFormatToName(field.type.dateFormat) }}, parsedIn: nil) {
|
||||
self.{{ field.name }} = date
|
||||
} else {
|
||||
throw LeadKitError.failedToDecode(reason: "init?(string:format:fromRegion:) returned nil")
|
||||
|
|
|
|||
Loading…
Reference in New Issue