Skip to content

Commit e6dfb71

Browse files
authored
Preserve The Specified Timezone In Parse (#633)
* Preserve The Specified Timezone In Parse When parsing a string into a Time using the optional timezone parameter, set the location of the Time to the timezone's location so that Format uses that timezone. * Add More Tests for Preserving Timezone Add test when timezone is used to parse a date-time. Add test when timezone is irrelevant because it's a date.
1 parent ae2a9df commit e6dfb71

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

builtin/builtin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ var Builtins = []*Function{
502502
if err != nil {
503503
return nil, err
504504
}
505+
t = t.In(tz)
505506
return t, nil
506507
}
507508

builtin/builtin_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func TestBuiltin(t *testing.T) {
113113
{`duration("1h")`, time.Hour},
114114
{`date("2006-01-02T15:04:05Z")`, time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)},
115115
{`date("2006.01.02", "2006.01.02")`, time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC)},
116+
{`date("2023-04-23T00:30:00.000+0100", "2006-01-02T15:04:05-0700", "America/Chicago").Format("2006-01-02")`, "2023-04-22"},
117+
{`date("2023-04-23T00:30:00", "2006-01-02T15:04:05", "America/Chicago").Format("2006-01-02")`, "2023-04-23"},
118+
{`date("2023-04-23", "2006-01-02", "America/Chicago").Format("2006-01-02")`, "2023-04-23"},
116119
{`first(ArrayOfString)`, "foo"},
117120
{`first(ArrayOfInt)`, 1},
118121
{`first(ArrayOfAny)`, 1},

0 commit comments

Comments
 (0)