/** * Gets the short name of this datetime zone suitable for display using * the default locale. * <p> * If the name is not available for the locale, then this method returns a * string in the format <code>[+-]hh:mm</code>. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the name for * @return the human-readable short name in the default locale */ public final String getShortName(long instant) { return getShortName(instant, null); }
/** * Gets the short name of this datetime zone suitable for display using * the default locale. * <p> * If the name is not available for the locale, then this method returns a * string in the format <code>[+-]hh:mm</code>. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the name for * @return the human-readable short name in the default locale */ public final String getShortName(long instant) { return getShortName(instant, null); }
private String print(long instant, DateTimeZone displayZone, Locale locale) { if (displayZone == null) { return ""; // no zone } switch (iType) { case LONG_NAME: return displayZone.getName(instant, locale); case SHORT_NAME: return displayZone.getShortName(instant, locale); } return ""; }
private String print(long instant, DateTimeZone displayZone, Locale locale) { if (displayZone == null) { return ""; // no zone } switch (iType) { case LONG_NAME: return displayZone.getName(instant, locale); case SHORT_NAME: return displayZone.getShortName(instant, locale); } return ""; }
private static void updateTimeZoneNames(Locale locale) { long time1 = new SUTime.IsoDate(2013,1,1).getJodaTimeInstant().getMillis(); long time2 = new SUTime.IsoDate(2013,6,1).getJodaTimeInstant().getMillis(); CollectionValuedMap<String,DateTimeZone> tzMap = new CollectionValuedMap<>(); for (DateTimeZone dtz:TimeZoneIdComponent.timeZonesById.values()) { // standard timezones tzMap.add(dtz.getShortName(time1, locale).toLowerCase(), dtz); tzMap.add(dtz.getName(time1, locale).toLowerCase(), dtz); // Add about half a year to get day light savings timezones... tzMap.add(dtz.getShortName(time2, locale).toLowerCase(), dtz); tzMap.add(dtz.getName(time2, locale).toLowerCase(), dtz); // tzMap.add(dtz.getNameKey(time).toLowerCase(), dtz); // tzMap.add(dtz.getID().toLowerCase(), dtz); } // Order by length for regex List<String> tzNames = new ArrayList<>(tzMap.keySet()); Collections.sort(tzNames, STRING_LENGTH_REV_COMPARATOR); String tzRegex = makeRegex(tzNames); synchronized (TimeZoneComponent.class) { timeZoneNames.put(locale,tzNames); timeZonesByName.put(locale,tzMap); timeZoneRegexes.put(locale,tzRegex); } }
@Test public void testGetShortNameNullKey() { DateTimeZone zone = new MockDateTimeZone("Europe/London"); assertEquals("Europe/London", zone.getShortName(TEST_TIME_SUMMER, Locale.ENGLISH)); }
/** * Gets the short name of this datetime zone suitable for display using * the default locale. * <p> * If the name is not available for the locale, then this method returns a * string in the format <code>[+-]hh:mm</code>. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the name for * @return the human-readable short name in the default locale */ public final String getShortName(long instant) { return getShortName(instant, null); }
@Test public void testNameProvider() { try { assertNotNull(DateTimeZone.getNameProvider()); NameProvider provider = DateTimeZone.getNameProvider(); DateTimeZone.setNameProvider(null); assertEquals(provider.getClass(), DateTimeZone.getNameProvider().getClass()); provider = new MockOKButNullNameProvider(); DateTimeZone.setNameProvider(provider); assertSame(provider, DateTimeZone.getNameProvider()); assertEquals("+00:00", DateTimeZone.UTC.getShortName(TEST_TIME_SUMMER)); assertEquals("+00:00", DateTimeZone.UTC.getName(TEST_TIME_SUMMER)); } finally { DateTimeZone.setNameProvider(null); } try { System.setProperty("org.joda.time.DateTimeZone.NameProvider", "org.joda.time.tz.DefaultNameProvider"); DateTimeZone.setNameProvider(null); assertEquals(DefaultNameProvider.class, DateTimeZone.getNameProvider().getClass()); } finally { System.getProperties().remove("org.joda.time.DateTimeZone.NameProvider"); DateTimeZone.setNameProvider(null); assertEquals(DefaultNameProvider.class, DateTimeZone.getNameProvider().getClass()); } }
private String print(long instant, DateTimeZone displayZone, Locale locale) { if (displayZone == null) { return ""; // no zone } switch (iType) { case LONG_NAME: return displayZone.getName(instant, locale); case SHORT_NAME: return displayZone.getShortName(instant, locale); } return ""; }
/** * Gets the short name of this datetime zone suitable for display using * the default locale. * <p> * If the name is not available for the locale, then this method returns a * string in the format <code>[+-]hh:mm</code>. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the name for * @return the human-readable short name in the default locale */ public final String getShortName(long instant) { return getShortName(instant, null); }
/** * Gets the short name of this datetime zone suitable for display using * the default locale. * <p> * If the name is not available for the locale, then this method returns a * string in the format <code>[+-]hh:mm</code>. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the name for * @return the human-readable short name in the default locale */ public final String getShortName(long instant) { return getShortName(instant, null); }
/** * Gets the short name of this datetime zone suitable for display using * the default locale. * <p> * If the name is not available for the locale, then this method returns a * string in the format <code>[+-]hh:mm</code>. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the name for * @return the human-readable short name in the default locale */ public final String getShortName(long instant) { return getShortName(instant, null); }
public String getShortClockTimezone() { if (StringUtils.isEmpty(clockTimestampTimezone)) { return StringUtils.EMPTY; } return DateTimeZone.forID(clockTimestampTimezone).getShortName(getTimestamp().getTime()); }
private String print(long instant, DateTimeZone displayZone, Locale locale) { if (displayZone == null) { return ""; // no zone } switch (iType) { case LONG_NAME: return displayZone.getName(instant, locale); case SHORT_NAME: return displayZone.getShortName(instant, locale); } return ""; }
private String print(long instant, DateTimeZone displayZone, Locale locale) { if (displayZone == null) { return ""; // no zone } switch (iType) { case LONG_NAME: return displayZone.getName(instant, locale); case SHORT_NAME: return displayZone.getShortName(instant, locale); } return ""; }
private String print(long instant, DateTimeZone displayZone, Locale locale) { if (displayZone == null) { return ""; // no zone } switch (iType) { case LONG_NAME: return displayZone.getName(instant, locale); case SHORT_NAME: return displayZone.getShortName(instant, locale); } return ""; }
private String print(long instant, DateTimeZone displayZone, Locale locale) { if (displayZone == null) { return ""; // no zone } switch (iType) { case LONG_NAME: return displayZone.getName(instant, locale); case SHORT_NAME: return displayZone.getShortName(instant, locale); } return ""; }
private String print(long instant, DateTimeZone displayZone, Locale locale) { if (displayZone == null) { return ""; // no zone } switch (iType) { case LONG_NAME: return displayZone.getName(instant, locale); case SHORT_NAME: return displayZone.getShortName(instant, locale); } return ""; }
DateTimeZone dz = DateTimeZone.forID("America/New_York"); String tzid = dz.getShortName(DateTimeUtils.currentTimeMillis()); //tzid will be 'EST' String longerTimeZoneName = dz.getName(DateTimeUtils.currentTimeMillis()); //longerTimeZoneName will be 'Eastern Standard Time'
@JRubyMethod(name = "zone") public RubyString zone() { String zone = dt.getZone().getShortName(dt.getMillis()); if(zone.equals("+00:00")) { zone = "GMT"; } return getRuntime().newString(zone); }