diff --git a/src/main/java/com/hubspot/jinjava/objects/date/StrftimeFormatter.java b/src/main/java/com/hubspot/jinjava/objects/date/StrftimeFormatter.java index fe06ccffb..898aa4f51 100644 --- a/src/main/java/com/hubspot/jinjava/objects/date/StrftimeFormatter.java +++ b/src/main/java/com/hubspot/jinjava/objects/date/StrftimeFormatter.java @@ -48,7 +48,7 @@ public class StrftimeFormatter { CONVERSIONS['y'] = "yy"; CONVERSIONS['Y'] = "yyyy"; CONVERSIONS['z'] = "Z"; - CONVERSIONS['Z'] = "ZZZZ"; + CONVERSIONS['Z'] = "z"; CONVERSIONS['%'] = "%"; NOMINATIVE_CONVERSIONS['B'] = "LLLL"; diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java index 16287c472..2b7cd180b 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java @@ -66,6 +66,16 @@ public void itSupportsTimezones() throws Exception { assertThat(filter.filter(1539277785000L, interpreter, "%B %d, %Y, at %I:%M %p", "UTC+8")).isEqualTo("October 12, 2018, at 01:09 AM"); } + @Test + public void itOutputsTimezoneName() { + assertThat(filter.filter(1539277785000L, interpreter, "%l:%M %p %Z", "America/Los_Angeles")).isEqualTo("10:09 AM PDT"); + } + + @Test + public void itOutputsTimezoneOffset() { + assertThat(filter.filter(1539277785000L, interpreter, "%l:%M %p %z", "America/Los_Angeles")).isEqualTo("10:09 AM -0700"); + } + @Test(expected = InvalidDateFormatException.class) public void itThrowsExceptionOnInvalidTimezone() throws Exception { filter.filter(1539277785000L, interpreter, "%B %d, %Y, at %I:%M %p", "Not a timezone"); diff --git a/src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java b/src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java index 6ad664d2a..683bb568c 100644 --- a/src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java +++ b/src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Locale; @@ -85,8 +86,9 @@ public void testFinnishMonths() { @Test public void testZoneOutput() { - assertThat(StrftimeFormatter.format(d, "%z")).isEqualTo("+0000"); - assertThat(StrftimeFormatter.format(d, "%Z")).isEqualTo("GMT"); + d = ZonedDateTime.of(d.toLocalDateTime(), ZoneId.of("America/Los_Angeles")); + assertThat(StrftimeFormatter.format(d, "%z")).isEqualTo("-0800"); + assertThat(StrftimeFormatter.format(d, "%Z")).isEqualTo("PST"); } @Test