Skip to content

Commit 09ee2ed

Browse files
authored
Revert "Implement actual locale-aware datetime formatting (#932)" (#939)
This reverts commit 6780d72.
1 parent 3497111 commit 09ee2ed

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

src/main/java/com/hubspot/jinjava/objects/date/StrftimeFormatter.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.hubspot.jinjava.objects.date;
22

3-
import static com.hubspot.jinjava.objects.date.StrftimeFormatter.ConversionComponent.localized;
43
import static com.hubspot.jinjava.objects.date.StrftimeFormatter.ConversionComponent.pattern;
54

65
import com.google.common.collect.ImmutableMap;
@@ -34,7 +33,7 @@ public class StrftimeFormatter {
3433
.put('A', pattern("EEEE"))
3534
.put('b', pattern("MMM"))
3635
.put('B', pattern("MMMM"))
37-
.put('c', localized(FormatStyle.MEDIUM, FormatStyle.MEDIUM))
36+
.put('c', pattern("EEE MMM dd HH:mm:ss yyyy"))
3837
.put('d', pattern("dd"))
3938
.put('e', pattern("d")) // The day of the month like with %d, but padded with blank (range 1 through 31).
4039
.put('f', pattern("SSSSSS"))
@@ -51,8 +50,8 @@ public class StrftimeFormatter {
5150
.put('U', pattern("ww"))
5251
.put('w', pattern("e"))
5352
.put('W', pattern("ww"))
54-
.put('x', localized(FormatStyle.SHORT, null))
55-
.put('X', localized(null, FormatStyle.MEDIUM))
53+
.put('x', pattern("MM/dd/yy"))
54+
.put('X', pattern("HH:mm:ss"))
5655
.put('y', pattern("yy"))
5756
.put('Y', pattern("yyyy"))
5857
.put('z', pattern("Z"))
@@ -177,9 +176,5 @@ static ConversionComponent pattern(String targetPattern) {
177176
stripLeadingZero ? targetPattern.substring(1) : targetPattern
178177
);
179178
}
180-
181-
static ConversionComponent localized(FormatStyle dateStyle, FormatStyle timeStyle) {
182-
return (builder, stripLeadingZero) -> builder.appendLocalized(dateStyle, timeStyle);
183-
}
184179
}
185180
}

src/test/java/com/hubspot/jinjava/lib/filter/DateTimeFormatFilterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void itConvertsToLocaleSpecificDateTimeFormat() {
116116
"en-US"
117117
)
118118
)
119-
.isEqualTo("10/11/18 1:09:45 PM - Oct 11, 2018, 1:09:45 PM");
119+
.isEqualTo("10/11/18 13:09:45 - Thu Oct 11 13:09:45 2018");
120120
assertThat(
121121
filter.filter(
122122
1539277785000L,
@@ -126,7 +126,7 @@ public void itConvertsToLocaleSpecificDateTimeFormat() {
126126
"de-DE"
127127
)
128128
)
129-
.isEqualTo("11.10.18 13:09:45 - 11.10.2018, 13:09:45");
129+
.isEqualTo("10/11/18 13:09:45 - Do. Okt. 11 13:09:45 2018");
130130
}
131131

132132
@Test

src/test/java/com/hubspot/jinjava/objects/date/StrftimeFormatterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public void testWithNoPcts() {
5454

5555
@Test
5656
public void testDateTime() {
57-
assertThat(StrftimeFormatter.format(d, "%c")).isEqualTo("Nov 6, 2013, 2:22:00 PM");
57+
assertThat(StrftimeFormatter.format(d, "%c")).isEqualTo("Wed Nov 06 14:22:00 2013");
5858
}
5959

6060
@Test
6161
public void testDate() {
62-
assertThat(StrftimeFormatter.format(d, "%x")).isEqualTo("11/6/13");
62+
assertThat(StrftimeFormatter.format(d, "%x")).isEqualTo("11/06/13");
6363
}
6464

6565
@Test
@@ -69,12 +69,12 @@ public void testDayOfWeekNumber() {
6969

7070
@Test
7171
public void testTime() {
72-
assertThat(StrftimeFormatter.format(d, "%X")).isEqualTo("2:22:00 PM");
72+
assertThat(StrftimeFormatter.format(d, "%X")).isEqualTo("14:22:00");
7373
}
7474

7575
@Test
7676
public void testMicrosecs() {
77-
assertThat(StrftimeFormatter.format(d, "%X %f")).isEqualTo("2:22:00 PM 123000");
77+
assertThat(StrftimeFormatter.format(d, "%X %f")).isEqualTo("14:22:00 123000");
7878
}
7979

8080
@Test

0 commit comments

Comments
 (0)