void test1() { Locale[] available = Locale.getAvailableLocales(); List<Locale> jreimplloc = Arrays.asList( LocaleProviderAdapter.forJRE().getTimeZoneNameProvider().getAvailableLocales()); List<Locale> providerLocales = Arrays.asList(tznp.getAvailableLocales()); String[] ids = TimeZone.getAvailableIDs(); for (Locale target : available) { // pure JRE implementation OpenListResourceBundle rb = ((ResourceBundleBasedAdapter) LocaleProviderAdapter.forJRE()) .getLocaleData() .getTimeZoneNames(target); boolean jreSupportsTarget = jreimplloc.contains(target); for (String id : ids) { // the time zone TimeZone tz = TimeZone.getTimeZone(id); // JRE string array for the id String[] jrearray = null; if (jreSupportsTarget) { try { jrearray = rb.getStringArray(id); } catch (MissingResourceException mre) { } } for (int i = 1; i <= (tz.useDaylightTime() ? 4 : 2); i++) { // the localized name String name = tz.getDisplayName(i >= 3, i % 2, target); // provider's name (if any) String providersname = null; if (providerLocales.contains(target)) { providersname = tznp.getDisplayName(id, i >= 3, i % 2, target); } // JRE's name String jresname = null; if (jrearray != null) { jresname = jrearray[i]; } checkValidity( target, jresname, providersname, name, jreSupportsTarget && jresname != null); } } } }
/** This code borrowed from Piesquared on irc.nexuswar.com */ private TimeZone tZF(String search) { if (search.equals("")) return TimeZone.getTimeZone("GMT"); search = search.toLowerCase(); search = search.replace("+", "\\+"); search = search.replace("*", "\\*"); search = search.replace("?", "\\?"); String[] zones = TimeZone.getAvailableIDs(); for (int i = 0; i < zones.length; i++) if (zones[i].toLowerCase().equals(search)) return TimeZone.getTimeZone(zones[i]); for (int i = 0; i < zones.length; i++) if (zones[i].toLowerCase().matches(".*" + search + ".*")) return TimeZone.getTimeZone(zones[i]); return TimeZone.getTimeZone("GMT"); }
private void writeTimeZone(MarkupWriter writer) { if (timeZone == TimeZoneVisibility.NONE) return; TimeZone tz = timeZoneTracker.getClientTimeZone(); writer.element("span", "class", "tx-datefield-timezone"); switch (timeZone) { case DISPLAY: writer.write(" "); writer.write(tz.getDisplayName(locale)); break; case SELECT: writer.element("select", "name", getControlName() + "$timezone"); for (TimeZone option : F.flow(TimeZone.getAvailableIDs()).map(ID_TO_TIME_ZONE).sort(timeZoneComparator)) { writer.element("option", "value", option.getID()); if (tz.equals(option)) writer.attributes("selected", "selected"); int offset = option.getRawOffset() / (1000 * 60 * 60); writer.write(String.format("UTC%+03d %s", offset, option.getID())); writer.end(); } writer.end(); default: break; } writer.end(); }