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

Commit

Permalink
Merge pull request #23 from ezfe/master
Browse files Browse the repository at this point in the history
Fixed out-of-bounds crash with #date tag
  • Loading branch information
tanner0101 authored Jun 21, 2018
2 parents 241ec06 + 8e66399 commit f7f0fea
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit f7f0fea

Please sign in to comment.