Skip to content

Commit

Permalink
make date parsing working for latest JDK16 again (#2187)
Browse files Browse the repository at this point in the history
* make date parsing working for latest JDK16 again, #2186

* ENGLISH not ROOT

* make short names of month static
  • Loading branch information
karussell committed Feb 12, 2021
1 parent d05e580 commit 9d4d2ac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ matrix:
- jdk: openjdk8
- env: JDK='OpenJDK 15'
install: . ./install-jdk.sh -F 15 -C --url 'https://api.adoptopenjdk.net/v3/binary/latest/15/ga/linux/x64/jdk/hotspot/normal/adoptopenjdk'
#- env: JDK='OpenJDK 16'
# install: . ./install-jdk.sh -F 16 -C --url 'https://api.adoptopenjdk.net/v3/binary/latest/16/ea/linux/x64/jdk/hotspot/normal/adoptopenjdk'
- env: JDK='OpenJDK 16'
install: . ./install-jdk.sh -F 16 -C --url 'https://api.adoptopenjdk.net/v3/binary/latest/16/ea/linux/x64/jdk/hotspot/normal/adoptopenjdk'

# avoid default dependency command for maven, 'true' means 'return true' and continue
install: true
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/com/graphhopper/util/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ public static DateFormat createFormatter() {
}

/**
* Creates a SimpleDateFormat with the UK locale.
* Creates a SimpleDateFormat with ENGLISH locale.
*/
public static DateFormat createFormatter(String str) {
DateFormat df = new SimpleDateFormat(str, Locale.UK);
DateFormat df = new SimpleDateFormat(str, Locale.ENGLISH);
df.setTimeZone(UTC);
return df;
}
Expand Down
3 changes: 2 additions & 1 deletion core/files/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
3.0
CustomWeighting language breaks old format but is more powerful and easier to read; it also allows factors >1 for server-side CustomModels
renamed GHUtilities.setProperties to setSpeed
renamed GHUtilities.setProperties to setSpeed
Helper.createFormatter is using the ENGLISH Locale instead of UK, see #2186
the name of an encoded value can only contain lower letters, underscore or numbers. It has to start with a lower letter
default for GraphHopperMatrixWeb (client for Matrix API) is now the sync POST request without the artificial polling delay in most cases
refactored TransportationMode to better reflect the usage in source data parsing only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.graphhopper.util.Helper;

import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
Expand All @@ -37,11 +39,11 @@
* @author Robin Boldt
*/
public class DateRangeParser implements ConditionalValueParser {
private static final DateFormat YEAR_MONTH_DAY_DF = createFormatter("yyyy MMM dd");
private static final DateFormat MONTH_DAY_DF = createFormatter("MMM dd");
private static final DateFormat YEAR_MONTH_DAY_DF = create3CharMonthFormatter("yyyy MMM dd");
private static final DateFormat MONTH_DAY_DF = create3CharMonthFormatter("MMM dd");
private static final DateFormat MONTH_DAY2_DF = createFormatter("dd.MM");
private static final DateFormat YEAR_MONTH_DF = createFormatter("yyyy MMM");
private static final DateFormat MONTH_DF = createFormatter("MMM");
private static final DateFormat YEAR_MONTH_DF = create3CharMonthFormatter("yyyy MMM");
private static final DateFormat MONTH_DF = create3CharMonthFormatter("MMM");
private static final List<String> DAY_NAMES = Arrays.asList("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa");

private Calendar date;
Expand Down Expand Up @@ -145,4 +147,12 @@ public static DateRangeParser createInstance(String day) {
}
return new DateRangeParser(calendar);
}

private static SimpleDateFormat create3CharMonthFormatter(String pattern) {
DateFormatSymbols formatSymbols = new DateFormatSymbols(Locale.ENGLISH);
formatSymbols.setShortMonths(new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"});
SimpleDateFormat df = new SimpleDateFormat(pattern, formatSymbols);
df.setTimeZone(Helper.UTC);
return df;
}
}

0 comments on commit 9d4d2ac

Please sign in to comment.