File tree 2 files changed +33
-0
lines changed
Sources/LeafKit/LeafSyntax
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,15 @@ struct DateTag: LeafTag {
87
87
throw " Unable to convert date format to string "
88
88
}
89
89
formatter. dateFormat = string
90
+ case 3 :
91
+ guard let string = ctx. parameters [ 1 ] . string else {
92
+ throw " Unable to convert date format to string "
93
+ }
94
+ formatter. dateFormat = string
95
+ guard let timeZone = ctx. parameters [ 2 ] . string else {
96
+ throw " Unable to convert time zone to string "
97
+ }
98
+ formatter. timeZone = TimeZone ( identifier: timeZone)
90
99
default :
91
100
throw " invalid parameters provided for date "
92
101
}
Original file line number Diff line number Diff line change @@ -208,6 +208,30 @@ class TagTests: XCTestCase {
208
208
try XCTAssertEqual ( render ( template, [ " now " : . int( now) ] ) , expected)
209
209
}
210
210
211
+ func testDateWithCustomFormatAndTimeZone( ) throws {
212
+ let now = 1604932200 - Calendar. current. timeZone. secondsFromGMT ( )
213
+
214
+ let templateNewYork = """
215
+ The date is #date(now, " yyyy-MM-dd'T'HH:mm " , " America/New_York " )
216
+ """
217
+
218
+ let expectedNewYork = """
219
+ The date is 2020-11-09T09:30
220
+ """
221
+
222
+ try XCTAssertEqual ( render ( templateNewYork, [ " now " : . int( now) ] ) , expectedNewYork)
223
+
224
+ let templateCalifornia = """
225
+ The date is #date(now, " yyyy-MM-dd'T'HH:mm " , " America/Los_Angeles " )
226
+ """
227
+
228
+ let expectedCalifornia = """
229
+ The date is 2020-11-09T06:30
230
+ """
231
+
232
+ try XCTAssertEqual ( render ( templateCalifornia, [ " now " : . int( now) ] ) , expectedCalifornia)
233
+ }
234
+
211
235
func testDumpContext( ) throws {
212
236
let data : [ String : LeafData ] = [ " value " : 12345 ]
213
237
let template = """
You can’t perform that action at this time.
0 commit comments