Skip to content

Commit 9d4d2ac

Browse files
authored
make date parsing working for latest JDK16 again (graphhopper#2187)
* make date parsing working for latest JDK16 again, graphhopper#2186 * ENGLISH not ROOT * make short names of month static
1 parent d05e580 commit 9d4d2ac

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ matrix:
1414
- jdk: openjdk8
1515
- env: JDK='OpenJDK 15'
1616
install: . ./install-jdk.sh -F 15 -C --url 'https://api.adoptopenjdk.net/v3/binary/latest/15/ga/linux/x64/jdk/hotspot/normal/adoptopenjdk'
17-
#- env: JDK='OpenJDK 16'
18-
# install: . ./install-jdk.sh -F 16 -C --url 'https://api.adoptopenjdk.net/v3/binary/latest/16/ea/linux/x64/jdk/hotspot/normal/adoptopenjdk'
17+
- env: JDK='OpenJDK 16'
18+
install: . ./install-jdk.sh -F 16 -C --url 'https://api.adoptopenjdk.net/v3/binary/latest/16/ea/linux/x64/jdk/hotspot/normal/adoptopenjdk'
1919

2020
# avoid default dependency command for maven, 'true' means 'return true' and continue
2121
install: true

api/src/main/java/com/graphhopper/util/Helper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ public static DateFormat createFormatter() {
343343
}
344344

345345
/**
346-
* Creates a SimpleDateFormat with the UK locale.
346+
* Creates a SimpleDateFormat with ENGLISH locale.
347347
*/
348348
public static DateFormat createFormatter(String str) {
349-
DateFormat df = new SimpleDateFormat(str, Locale.UK);
349+
DateFormat df = new SimpleDateFormat(str, Locale.ENGLISH);
350350
df.setTimeZone(UTC);
351351
return df;
352352
}

core/files/changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
3.0
22
CustomWeighting language breaks old format but is more powerful and easier to read; it also allows factors >1 for server-side CustomModels
3-
renamed GHUtilities.setProperties to setSpeed
3+
renamed GHUtilities.setProperties to setSpeed
4+
Helper.createFormatter is using the ENGLISH Locale instead of UK, see #2186
45
the name of an encoded value can only contain lower letters, underscore or numbers. It has to start with a lower letter
56
default for GraphHopperMatrixWeb (client for Matrix API) is now the sync POST request without the artificial polling delay in most cases
67
refactored TransportationMode to better reflect the usage in source data parsing only

core/src/main/java/com/graphhopper/reader/osm/conditional/DateRangeParser.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import com.graphhopper.util.Helper;
2121

2222
import java.text.DateFormat;
23+
import java.text.DateFormatSymbols;
2324
import java.text.ParseException;
25+
import java.text.SimpleDateFormat;
2426
import java.util.Arrays;
2527
import java.util.Calendar;
2628
import java.util.List;
@@ -37,11 +39,11 @@
3739
* @author Robin Boldt
3840
*/
3941
public class DateRangeParser implements ConditionalValueParser {
40-
private static final DateFormat YEAR_MONTH_DAY_DF = createFormatter("yyyy MMM dd");
41-
private static final DateFormat MONTH_DAY_DF = createFormatter("MMM dd");
42+
private static final DateFormat YEAR_MONTH_DAY_DF = create3CharMonthFormatter("yyyy MMM dd");
43+
private static final DateFormat MONTH_DAY_DF = create3CharMonthFormatter("MMM dd");
4244
private static final DateFormat MONTH_DAY2_DF = createFormatter("dd.MM");
43-
private static final DateFormat YEAR_MONTH_DF = createFormatter("yyyy MMM");
44-
private static final DateFormat MONTH_DF = createFormatter("MMM");
45+
private static final DateFormat YEAR_MONTH_DF = create3CharMonthFormatter("yyyy MMM");
46+
private static final DateFormat MONTH_DF = create3CharMonthFormatter("MMM");
4547
private static final List<String> DAY_NAMES = Arrays.asList("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa");
4648

4749
private Calendar date;
@@ -145,4 +147,12 @@ public static DateRangeParser createInstance(String day) {
145147
}
146148
return new DateRangeParser(calendar);
147149
}
150+
151+
private static SimpleDateFormat create3CharMonthFormatter(String pattern) {
152+
DateFormatSymbols formatSymbols = new DateFormatSymbols(Locale.ENGLISH);
153+
formatSymbols.setShortMonths(new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"});
154+
SimpleDateFormat df = new SimpleDateFormat(pattern, formatSymbols);
155+
df.setTimeZone(Helper.UTC);
156+
return df;
157+
}
148158
}

0 commit comments

Comments
 (0)