diff --git a/Swift/macroses/common.utils.twig b/Swift/macroses/common.utils.twig index 97df266..59da91a 100644 --- a/Swift/macroses/common.utils.twig +++ b/Swift/macroses/common.utils.twig @@ -65,7 +65,11 @@ {% endmacro %} {%- macro formatEncodingDate(field) -%} - ApiDateFormattingService.string(from: {{ field.name -}}, format: .{{- dateFormatToName(field.type.dateFormat) -}}) + {%- if field.type.dateFormats is not empty -%} + ApiDateFormattingService.string(from: {{ field.name -}}, format: .{{- dateFormatToName(field.type.dateFormats[0]) -}}) + {%- else -%} + ApiDateFormattingService.string(from: {{ field.name -}}, format: .{{- dateFormatToName(field.type.dateFormat) -}}) + {%- endif -%} {%- endmacro -%} {%- macro formatEncodingStringDecimal(field) -%} diff --git a/Swift/macroses/complexField.utils.twig b/Swift/macroses/complexField.utils.twig index 333bdcc..ad4b97c 100644 --- a/Swift/macroses/complexField.utils.twig +++ b/Swift/macroses/complexField.utils.twig @@ -43,10 +43,14 @@ {%- macro commonDateInit(field) -%} {%- import _self as self -%} - {{ self.dateInit(field.name, field.type.dateFormat) }} - {%- for dateFormat in field.type.dateFormats -%} - else {{ self.dateInit(field.name, dateFormat) }} - {%- endfor -%} + {%- if field.type.dateFormats is not empty -%} + {{ self.dateInit(field.name, field.type.dateFormats[0]) }} + {%- for dateFormat in field.type.dateFormats|slice(1, field.type.dateFormats|length) -%} + else {{ self.dateInit(field.name, dateFormat) }} + {%- endfor -%} + {%- else -%} + {{ self.dateInit(field.name, field.type.dateFormat) }} + {%- endif -%} else { throw LeadKitError.failedToDecode(reason: "Unable to decode date from string") } @@ -56,5 +60,5 @@ {%- set dateTimeInit = "ApiDateFormattingService.date(from: %s, format: .%s, parsedIn: nil)"|format(name, dateFormatToName(dateFormat)) -%} if let value = {{ dateTimeInit }} { self.{{ name }} = value - } + } {%- endmacro -%} \ No newline at end of file