Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Fixed out-of-bounds crash with #date tag #23

Merged
merged 2 commits into from
Jun 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/TemplateKit/Tag/DateFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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[1].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)) }
Expand Down