From 871f7d902952b9073ca524e8d2792ea73d6bd5b7 Mon Sep 17 00:00:00 2001 From: Ezekiel Elin Date: Tue, 19 Jun 2018 14:32:59 -0400 Subject: [PATCH 1/2] Corrected an issue with `#date` when no format is provided --- Sources/TemplateKit/Tag/DateFormat.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/TemplateKit/Tag/DateFormat.swift b/Sources/TemplateKit/Tag/DateFormat.swift index 4d61b5c..ed8a316 100644 --- a/Sources/TemplateKit/Tag/DateFormat.swift +++ b/Sources/TemplateKit/Tag/DateFormat.swift @@ -19,7 +19,11 @@ public final class DateFormat: TagRenderer { /// Assume the date is a floating point number let date = Date(timeIntervalSinceReferenceDate: tag.parameters[0].double ?? 0) /// Set format as the second param or default to ISO-8601 format. - formatter.dateFormat = tag.parameters[1].string ?? "yyyy-MM-dd HH:mm:ss" + if tag.parameters.count == 2, let param = tag.parameters[2].string { + formatter.dateFormat = param + } else { + formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + } /// Return formatted date return Future.map(on: tag) { .string(formatter.string(from: date)) } From 8e66399c8f9563ca710328c679d9c99be6194b67 Mon Sep 17 00:00:00 2001 From: Ezekiel Elin Date: Tue, 19 Jun 2018 14:54:29 -0400 Subject: [PATCH 2/2] Fixed off-by-one index --- Sources/TemplateKit/Tag/DateFormat.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/TemplateKit/Tag/DateFormat.swift b/Sources/TemplateKit/Tag/DateFormat.swift index ed8a316..e38b33e 100644 --- a/Sources/TemplateKit/Tag/DateFormat.swift +++ b/Sources/TemplateKit/Tag/DateFormat.swift @@ -19,7 +19,7 @@ public final class DateFormat: TagRenderer { /// Assume the date is a floating point number let date = Date(timeIntervalSinceReferenceDate: tag.parameters[0].double ?? 0) /// Set format as the second param or default to ISO-8601 format. - if tag.parameters.count == 2, let param = tag.parameters[2].string { + if tag.parameters.count == 2, let param = tag.parameters[1].string { formatter.dateFormat = param } else { formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"