update for SwiftDate 5.0
This commit is contained in:
parent
7992a9d494
commit
dadfebb4c1
|
|
@ -11,8 +11,8 @@ enum ApiDateFormat: String, LeadKit.DateFormat {
|
|||
{% for format in dateFormats -%}
|
||||
case {{ format.name }} = "{{ format.format }}"
|
||||
{% endfor %}
|
||||
var swiftDateFormat: SwiftDate.DateFormat {
|
||||
return SwiftDate.DateFormat.custom(rawValue)
|
||||
var swiftDateFormat: DateToStringStyles {
|
||||
return .custom(rawValue)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ final class ApiDateFormattingService: DateFormattingService, Singleton {
|
|||
|
||||
typealias DateFormatType = ApiDateFormat
|
||||
|
||||
var currentRegion: Region = .Local()
|
||||
var currentRegion: Region = .local
|
||||
|
||||
static let shared = ApiDateFormattingService()
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
{{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}}
|
||||
.string(format: ApiDateFormat.{{ dateFormatToName(field.type.dateFormat) }}.swiftDateFormat)
|
||||
.toString(ApiDateFormat.{{ dateFormatToName(field.type.dateFormat) }}.swiftDateFormat)
|
||||
{%- elseif field.type.type.baseTypeName == "Decimal" -%}
|
||||
{{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}}
|
||||
.decimalValue
|
||||
|
|
@ -103,12 +103,12 @@
|
|||
|
||||
{% macro initExpr(field) %}
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
if let date = DateInRegion(string: {{ field.name }}, format: ApiDateFormat.{{ dateFormatToName(field.type.dateFormat) }}.swiftDateFormat, fromRegion: ApiDateFormattingService.shared.currentRegion) {
|
||||
if let date = ApiDateFormattingService.date(from: {{ field.name }}, format: "{{ field.type.dateFormat }}") {
|
||||
self.{{ field.name }} = date
|
||||
} else {
|
||||
throw LeadKitError.failedToDecode(reason: "init?(string:format:fromRegion:) returned nil")
|
||||
}
|
||||
{%- elseif field.type.type.baseTypeName == "Decimal" -%}
|
||||
{%- elseif field.type.type.baseTypeName == "Decimal" -%}
|
||||
self.{{ field.name }} = NSDecimalNumber(decimal: {{ field.name }})
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
|
@ -133,7 +133,7 @@
|
|||
{%- elseif baseTypeName == "String" -%}
|
||||
""
|
||||
{%- elseif baseTypeName == "DateTime" -%}
|
||||
Date().inRegion()
|
||||
Date().inDefaultRegion()
|
||||
{%- elseif baseTypeName == "Double" -%}
|
||||
0.0
|
||||
{%- elseif baseTypeName == "Long" or baseTypeName == "Int" -%}
|
||||
|
|
|
|||
Loading…
Reference in New Issue