List of usage examples for org.joda.time DateTimeZone isStandardOffset
public boolean isStandardOffset(long instant)
From source file:com.landenlabs.all_devtool.ClockFragment.java
License:Open Source License
/** * Update clock on screen//w ww . ja va 2 s. com */ private void updateClock() { m_date.setTime(System.currentTimeMillis()); m_timeZone = TimeZone.getDefault(); s_timeZoneFormat.setTimeZone(m_timeZone); String localTmStr = s_timeZoneFormat.format(m_date); m_clockLocalTv.setText(localTmStr); String gmtTmStr = s_timeGmtFormat.format(m_date); m_clockGmtTv.setText(gmtTmStr); long currDay = TimeUnit.DAYS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS); m_timePartsTv.setText(String.format("Days since Jan 1 1970: %d", currDay)); Locale ourLocale = Locale.getDefault(); StringBuilder tzStr1 = new StringBuilder(); StringBuilder tzStr2 = new StringBuilder(); tzStr1.append(String.format("Locale %s\n", ourLocale.getDisplayName())); tzStr1.append(getTzDetailStr(m_timeZone)); tzStr1.append("Daylight Savings:\n"); // tzStr.append((m_timeZone.useDaylightTime() ? "Has" : "No") + " daylight savings\n"); String ds_short = m_timeZone.getDisplayName(false, TimeZone.SHORT, ourLocale); tzStr1.append( String.format(" %s=%s\n", ds_short, m_timeZone.getDisplayName(false, TimeZone.LONG, ourLocale))); if (m_timeZone.useDaylightTime()) { String std_short = m_timeZone.getDisplayName(true, TimeZone.SHORT, ourLocale); tzStr1.append(String.format(" %s=%s\n", std_short, m_timeZone.getDisplayName(true, TimeZone.LONG, ourLocale))); // ---- // DateTimeZone zone1 = DateTimeZone.forID("Europe/London"); // DateTimeZone zone2 = DateTimeZone.forID("America/New_York"); DateTimeZone zone = DateTimeZone.forTimeZone(m_timeZone); DateTimeFormatter format = DateTimeFormat.mediumDateTime(); long current = System.currentTimeMillis(); for (int i = 0; i < 4; i++) { long next = zone.nextTransition(current); if (current == next) { break; } tzStr1.append(String.format(" %s %s\n", zone.isStandardOffset(next - 3600000) ? std_short : ds_short, format.print(next))); current = next; } m_localeTv.setText(tzStr1.toString()); String[] ids = TimeZone.getAvailableIDs(); if (ids != null && ids.length > 0) { switch (m_daylightFilter) { case NoDS: tzStr2.append("TimeZones (no Daylight savings):\n"); break; case HasDS: tzStr2.append("TimeZone (Has Daylight savings):\n"); break; case InDS: tzStr2.append("TimeZone (In Daylight savings):\n"); break; } SparseIntArray zones = new SparseIntArray(); for (int tzIdx = 0; tzIdx < ids.length; tzIdx++) { TimeZone tz = TimeZone.getTimeZone(ids[tzIdx]); boolean addTz = false; switch (m_daylightFilter) { case NoDS: addTz = !tz.useDaylightTime(); break; case HasDS: addTz = tz.useDaylightTime() && !tz.inDaylightTime(m_date); break; case InDS: addTz = tz.inDaylightTime(m_date); break; } if (addTz) { zones.put(tz.getRawOffset(), tzIdx); } } for (int idx = 0; idx != zones.size(); idx++) { TimeZone tz = TimeZone.getTimeZone(ids[zones.valueAt(idx)]); tzStr2.append(getTzOffsetStr(tz, s_timeFormat)); } } } m_dayLight.setText(tzStr2.toString()); m_clockSysClkUpTm.setText("uptimeMillis:" + formatInterval(SystemClock.uptimeMillis())); m_clockSysClkReal.setText("elapsedRealtime:" + formatInterval(SystemClock.elapsedRealtime())); }
From source file:com.microsoft.exchange.utils.TimeZoneHelper.java
License:Open Source License
private static long setTransitionTime(DateTimeZone zone, long now, SerializableTimeZone target) { long transition = zone.nextTransition(now); boolean isStandard = zone.isStandardOffset(transition); SerializableTimeZoneTime time = toSerializableTimeZoneTime(zone, transition); if (isStandard) { target.setStandardTime(time);// ww w. j a v a2 s . c om } else { target.setDaylightTime(time); } return transition; }
From source file:org.killbill.billing.util.account.AccountDateTimeUtils.java
License:Apache License
public static DateTimeZone getFixedOffsetTimeZone(final DateTimeZone referenceDateTimeZone, final Entity account) { final DateTime referenceDateTime = getReferenceDateTime(account); // Check if DST was in effect at the reference date time final boolean shouldUseDST = !referenceDateTimeZone.isStandardOffset(referenceDateTime.getMillis()); if (shouldUseDST) { return DateTimeZone.forOffsetMillis(referenceDateTimeZone.getOffset(referenceDateTime.getMillis())); } else {/*from w ww .j av a 2s . c o m*/ return DateTimeZone .forOffsetMillis(referenceDateTimeZone.getStandardOffset(referenceDateTime.getMillis())); } }
From source file:org.nodatime.tzvalidate.JodaDump.java
License:Open Source License
@Override public ZoneTransitions getTransitions(String id, int fromYear, int toYear) { DateTimeZone zone = zones.get(id); // Note that the ID we fetched isn't always the same as DateTimeZone.getID() DateTimeFormatter nameFormatter = DateTimeFormat.forPattern("zz").withZone(zone); Instant start = new DateTime(fromYear, 1, 1, 0, 0, DateTimeZone.UTC).toInstant(); Instant end = new DateTime(toYear, 1, 1, 0, 0, DateTimeZone.UTC).toInstant(); ZoneTransitions transitions = new ZoneTransitions(id); long now = start.getMillis(); transitions.addTransition(null, zone.getOffset(now), !zone.isStandardOffset(now), nameFormatter.print(now)); now = zone.nextTransition(now);// w w w . j a v a 2 s . co m if (now == start.getMillis()) { return transitions; } while (now < end.getMillis()) { transitions.addTransition(new Date(now), zone.getOffset(now), !zone.isStandardOffset(now), nameFormatter.print(now)); long next = zone.nextTransition(now); if (next <= now) { break; } now = next; } return transitions; }
From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java
License:Open Source License
private ASSystemTime standardDate(TimeZone timeZone) { DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone); DateMidnight dateMidnight = new DateMidnight(DateTimeUtils.getInstantMillis(null), dateTimeZone); long firstDSTTransitionInstant = dateTimeZone.nextTransition(dateMidnight.getMillis()); long secondDSTTransitionInstant = dateTimeZone.nextTransition(firstDSTTransitionInstant); if (firstDSTTransitionInstant == secondDSTTransitionInstant) { return systemTimeFromInstant(0, DateTimeZone.UTC); }//from w w w . ja va2s . c o m if (dateTimeZone.isStandardOffset(firstDSTTransitionInstant)) { return systemTimeFromInstant(firstDSTTransitionInstant, dateTimeZone); } return systemTimeFromInstant(secondDSTTransitionInstant, dateTimeZone); }
From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java
License:Open Source License
private ASSystemTime dayLightDate(TimeZone timeZone) { DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone); DateMidnight dateMidnight = new DateMidnight(DateTimeUtils.getInstantMillis(null), dateTimeZone); long firstDSTTransitionInstant = dateTimeZone.nextTransition(dateMidnight.getMillis()); long secondDSTTransitionInstant = dateTimeZone.nextTransition(firstDSTTransitionInstant); if (firstDSTTransitionInstant == secondDSTTransitionInstant) { return systemTimeFromInstant(0, DateTimeZone.UTC); }//from w w w.j a va 2 s . com if (dateTimeZone.isStandardOffset(firstDSTTransitionInstant)) { return systemTimeFromInstant(secondDSTTransitionInstant, dateTimeZone); } return systemTimeFromInstant(firstDSTTransitionInstant, dateTimeZone); }