/** * Returns the latest daylight savings in milliseconds for this time zone, relative * to this time zone's regular UTC offset (as returned by {@link #getRawOffset}). * * <p>This class returns {@code 3600000} (1 hour) for time zones * that use daylight savings time and {@code 0} for timezones that do not, * leaving it to subclasses to override this method for other daylight savings * offsets. (There are time zones, such as {@code Australia/Lord_Howe}, * that use other values.) * * <p>Note that this method doesn't tell you whether or not to <i>apply</i> the * offset: you need to call {@code inDaylightTime} for the specific time * you're interested in. If this method returns a non-zero offset, that only * tells you that this {@code TimeZone} sometimes observes daylight savings. * * <p>Note also that this method doesn't necessarily return the value you need * to apply to the time you're working with. This value can and does change over * time for a given time zone. * * <p>It's highly unlikely that you should ever call this method. You * probably want {@link #getOffset} instead, which tells you the offset * for a specific point in time, and takes daylight savings into account for you. */ public int getDSTSavings() { return useDaylightTime() ? 3600000 : 0; }
/** * {@inheritDoc} */ public void appendTo(StringBuffer buffer, Calendar calendar) { if (mTimeZoneForced) { if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(mDaylight); } else { buffer.append(mStandard); } } else { TimeZone timeZone = calendar.getTimeZone(); if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale)); } else { buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale)); } } } }
@Override public void appendTo(final StringBuffer buffer, final Calendar calendar) { final TimeZone zone = calendar.getTimeZone(); if (zone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale)); } else { buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale)); } } }
@Override public void appendTo(final StringBuffer buffer, final Calendar calendar) { final TimeZone zone = calendar.getTimeZone(); if (zone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale)); } else { buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale)); } } }
@Override public void appendTo(StringBuffer buffer, Calendar calendar) { TimeZone timeZone; if ((timeZone = mTimeZone) != null) { if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(mDaylight); } else { buffer.append(mStandard); } } else { timeZone = calendar.getTimeZone(); if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(getTimeZoneDisplay (timeZone, true, mStyle, mLocale)); } else { buffer.append(getTimeZoneDisplay (timeZone, false, mStyle, mLocale)); } } } }
TimeZoneStrategy(final Locale locale) { final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings(); for (String[] zone : zones) { if (zone[ID].startsWith("GMT")) { continue; } final TimeZone tz = TimeZone.getTimeZone(zone[ID]); if (!tzNames.containsKey(zone[LONG_STD])) { tzNames.put(zone[LONG_STD], tz); } if (!tzNames.containsKey(zone[SHORT_STD])) { tzNames.put(zone[SHORT_STD], tz); } if (tz.useDaylightTime()) { if (!tzNames.containsKey(zone[LONG_DST])) { tzNames.put(zone[LONG_DST], tz); } if (!tzNames.containsKey(zone[SHORT_DST])) { tzNames.put(zone[SHORT_DST], tz); } } } final StringBuilder sb = new StringBuilder(); sb.append("(GMT[+\\-]\\d{0,1}\\d{2}|[+\\-]\\d{2}:?\\d{2}|"); for (final String id : tzNames.keySet()) { escapeRegex(sb, id, false).append('|'); } sb.setCharAt(sb.length() - 1, ')'); validTimeZoneChars = sb.toString(); }
TimeZoneStrategy(final Locale locale) { final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings(); for (String[] zone : zones) { if (zone[ID].startsWith("GMT")) { continue; } final TimeZone tz = TimeZone.getTimeZone(zone[ID]); if (!tzNames.containsKey(zone[LONG_STD])) { tzNames.put(zone[LONG_STD], tz); } if (!tzNames.containsKey(zone[SHORT_STD])) { tzNames.put(zone[SHORT_STD], tz); } if (tz.useDaylightTime()) { if (!tzNames.containsKey(zone[LONG_DST])) { tzNames.put(zone[LONG_DST], tz); } if (!tzNames.containsKey(zone[SHORT_DST])) { tzNames.put(zone[SHORT_DST], tz); } } } final StringBuilder sb = new StringBuilder(); sb.append("(GMT[+\\-]\\d{0,1}\\d{2}|[+\\-]\\d{2}:?\\d{2}|"); for (final String id : tzNames.keySet()) { escapeRegex(sb, id, false).append('|'); } sb.setCharAt(sb.length() - 1, ')'); validTimeZoneChars = sb.toString(); }
/** formats time zone specifier. */ private static void formatTimeZone(Calendar cal,StringBuilder buf) { TimeZone tz = cal.getTimeZone(); if (tz == null) return; // otherwise print out normally. int offset; if (tz.inDaylightTime(cal.getTime())) { offset = tz.getRawOffset() + (tz.useDaylightTime()?3600000:0); } else { offset = tz.getRawOffset(); } if(offset==0) { buf.append('Z'); return; } if (offset >= 0) buf.append('+'); else { buf.append('-'); offset *= -1; } offset /= 60 * 1000; // offset is in milli-seconds formatTwoDigits(offset / 60, buf); buf.append(':'); formatTwoDigits(offset % 60, buf); }
if (zone.inDaylightTime(new Date()) && zone.useDaylightTime()) { offset += (int)JiveConstants.HOUR;
/** * Get the DST offset (if any) for the default locale and the given date. * * @param self a Date * @return the DST offset as a Duration. */ public static Duration getDaylightSavingsOffset(Date self) { TimeZone timeZone = getTimeZone(self); int millis = (timeZone.useDaylightTime() && timeZone.inDaylightTime(self)) ? timeZone.getDSTSavings() : 0; return new TimeDuration(0, 0, 0, millis); }
if (timeZone.useDaylightTime()) { for (int year = STARTING_YEAR; year <= endYear; year++) { ZonedDateTime i = LocalDateTime.of(year, 1, 1, 0, 0)
import java.util.TimeZone; public class DaylightSavings { public static void main(String[] args) { TimeZone tz = TimeZone.getTimeZone("Australia/Brisbane"); System.out.println(tz.useDaylightTime()); } }
/** * {@inheritDoc} */ public void appendTo(StringBuffer buffer, Calendar calendar) { if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(mDaylight); } else { buffer.append(mStandard); } } }
/** * Return true if the calendar supports and is in daylight time * (according to its timezone), false otherwise */ public static boolean shouldAppendDaylightTime(Calendar calendar) { if (calendar == null) { return false; } TimeZone zone = calendar.getTimeZone(); return zone.useDaylightTime() && zone.inDaylightTime(calendar.getTime()); }
/** * Return true if the calendar supports and is in daylight time * (according to its timezone), false otherwise */ public static boolean shouldAppendDaylightTime(Calendar calendar) { if (calendar == null) { return false; } TimeZone zone = calendar.getTimeZone(); return zone.useDaylightTime() && zone.inDaylightTime(calendar.getTime()); }
for (String tzId : TimeZone.getAvailableIDs()) { TimeZone tz = TimeZone.getTimeZone(tzId); if (tz.useDaylightTime()) { // do something } }
@Override public void appendTo(final StringBuffer buffer, final Calendar calendar) { final TimeZone zone = calendar.getTimeZone(); if (zone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale)); } else { buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale)); } } }
public static Duration getDaylightSavingsOffset(Date self) { TimeZone timeZone = getTimeZone(self); int millis = (timeZone.useDaylightTime() && timeZone.inDaylightTime(self)) ? timeZone.getDSTSavings() : 0; return new TimeDuration(0, 0, 0, millis); }
public static ArrayValue listAbbreviations() { ArrayValue array = new ArrayValueImpl(); String []ids = TimeZone.getAvailableIDs(); for (int i = 0; i < ids.length; i++) { TimeZone tz = TimeZone.getTimeZone(ids[i]); addAbbreviation(array, tz, false); if (tz.useDaylightTime()) addAbbreviation(array, tz, true); } return array; }
/** * Ensure useDaylightTime() method is working correctly. */ public void testUseDaylightTime() { assertEquals(expectedUseDaylightTime, timezone.useDaylightTime()); assertEquals(tz.useDaylightTime(), timezone.useDaylightTime()); }