@Override public int parse(DateTimeParseContext context, CharSequence text, int position) { // this is a poor implementation that handles some but not all of the spec // JDK8 has a lot of extra information here Map<String, String> ids = new TreeMap<String, String>(LENGTH_COMPARATOR); for (String id : ZoneId.getAvailableZoneIds()) { ids.put(id, id); TimeZone tz = TimeZone.getTimeZone(id); int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT); String textWinter = tz.getDisplayName(false, tzstyle, context.getLocale()); if (id.startsWith("Etc/") || (!textWinter.startsWith("GMT+") && !textWinter.startsWith("GMT+"))) { ids.put(textWinter, id); } String textSummer = tz.getDisplayName(true, tzstyle, context.getLocale()); if (id.startsWith("Etc/") || (!textSummer.startsWith("GMT+") && !textSummer.startsWith("GMT+"))) { ids.put(textSummer, id); } } for (Entry<String, String> entry : ids.entrySet()) { String name = entry.getKey(); if (context.subSequenceEquals(text, position, name, 0, name.length())) { context.setParsed(ZoneId.of(entry.getValue())); return position + name.length(); } } return ~position; }
@Override public int parse(DateTimeParseContext context, CharSequence text, int position) { // this is a poor implementation that handles some but not all of the spec // JDK8 has a lot of extra information here Map<String, String> ids = new TreeMap<String, String>(LENGTH_COMPARATOR); for (String id : ZoneId.getAvailableZoneIds()) { ids.put(id, id); TimeZone tz = TimeZone.getTimeZone(id); int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT); String textWinter = tz.getDisplayName(false, tzstyle, context.getLocale()); if (id.startsWith("Etc/") || (!textWinter.startsWith("GMT+") && !textWinter.startsWith("GMT+"))) { ids.put(textWinter, id); } String textSummer = tz.getDisplayName(true, tzstyle, context.getLocale()); if (id.startsWith("Etc/") || (!textSummer.startsWith("GMT+") && !textSummer.startsWith("GMT+"))) { ids.put(textSummer, id); } } for (Entry<String, String> entry : ids.entrySet()) { String name = entry.getKey(); if (context.subSequenceEquals(text, position, name, 0, name.length())) { context.setParsed(ZoneId.of(entry.getValue())); return position + name.length(); } } return ~position; }