Example usage for java.util TimeZone getDSTSavings

List of usage examples for java.util TimeZone getDSTSavings

Introduction

In this page you can find the example usage for java.util TimeZone getDSTSavings.

Prototype

public int getDSTSavings() 

Source Link

Document

Returns the amount of time to be added to local standard time to get local wall clock time.

Usage

From source file:com.synelixis.xifi.AuthWebClient.AToken.java

private Date getGMTime() {
    Calendar c = Calendar.getInstance();
    System.out.println("current: " + c.getTime());

    TimeZone z = c.getTimeZone();
    int offset = z.getRawOffset();
    if (z.inDaylightTime(new Date())) {
        offset = offset + z.getDSTSavings();
    }/*  w ww .  ja  va 2s .c  om*/
    int offsetHrs = offset / 1000 / 60 / 60;
    int offsetMins = offset / 1000 / 60 % 60;
    c.add(Calendar.HOUR_OF_DAY, (-offsetHrs));
    c.add(Calendar.MINUTE, (-offsetMins));
    return c.getTime();

}

From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java

@Override
public Date sunrise(final Coordinate coordinate, final Date date) {
    final Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(date);//from  ww  w.  j  a v  a 2 s  .c  o  m

    final int day = calendar.get(Calendar.DAY_OF_YEAR);

    final double total = length(coordinate.getLatitude(), day);

    final int hours = (int) total;
    final int minutes = (int) ((((double) total) - ((double) hours)) * 60d);

    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    calendar.add(Calendar.HOUR_OF_DAY, -hours / 2);
    calendar.add(Calendar.MINUTE, -minutes / 2);
    calendar.add(Calendar.MINUTE, (int) localSolarTime(day));

    final TimeZone timeZone = TimeZone.getDefault();

    if (timeZone.inDaylightTime(date)) {
        calendar.add(Calendar.MILLISECOND, timeZone.getDSTSavings());
    }

    return calendar.getTime();
}

From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java

@Override
public Date sunset(final Coordinate coordinate, final Date date) {
    final Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(date);/*from w ww .  j a v a 2s.  c o m*/

    final int day = calendar.get(Calendar.DAY_OF_YEAR);

    final double total = length(coordinate.getLatitude(), day);

    final int hours = (int) total;
    final int minutes = (int) ((((double) total) - ((double) hours)) * 60d);

    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    calendar.add(Calendar.HOUR_OF_DAY, hours / 2);
    calendar.add(Calendar.MINUTE, minutes / 2);
    calendar.add(Calendar.MINUTE, (int) localSolarTime(day));

    final TimeZone timeZone = TimeZone.getDefault();

    if (timeZone.inDaylightTime(date)) {
        calendar.add(Calendar.MILLISECOND, timeZone.getDSTSavings());
    }

    return calendar.getTime();
}

From source file:com.microsoft.exchange.DateHelpTest.java

@Test
public void systemTimeZone() {
    List<String> availableIDs = Arrays.asList(TimeZone.getAvailableIDs());
    assertFalse(CollectionUtils.isEmpty(availableIDs));
    assertTrue(availableIDs.contains(TimeZones.UTC_ID));
    assertTrue(availableIDs.contains("UTC"));

    TimeZone ical4jUTC = TimeZone.getTimeZone(TimeZones.UTC_ID);
    TimeZone sysUTC = TimeZone.getTimeZone("UTC");

    assertEquals(ical4jUTC.getDSTSavings(), sysUTC.getDSTSavings());
    assertEquals(ical4jUTC.getRawOffset(), sysUTC.getRawOffset());
    assertTrue(ical4jUTC.hasSameRules(sysUTC));

    TimeZone origDefaultTimeZone = TimeZone.getDefault();
    assertNotNull(origDefaultTimeZone);/*from   w w  w  . j  a v  a  2  s  .  com*/
    assertEquals(TimeZone.getDefault().getRawOffset(), origDefaultTimeZone.getRawOffset());

    log.info("TimeZone.DisplayName=" + origDefaultTimeZone.getDisplayName());
    log.info("TimeZone.ID=" + origDefaultTimeZone.getID());
    log.info("TimeZone.DSTSavings=" + origDefaultTimeZone.getDSTSavings());
    log.info("TimeZone.RawOffset=" + origDefaultTimeZone.getRawOffset());
    log.info("TimeZone.useDaylightTime=" + origDefaultTimeZone.useDaylightTime());

    TimeZone.setDefault(ical4jUTC);
    assertEquals(ical4jUTC, TimeZone.getDefault());
    log.info(" -- Defualt Time Zone has been changed successfully! -- ");

    TimeZone newDefaultTimeZone = TimeZone.getDefault();
    log.info("TimeZone.DisplayName=" + newDefaultTimeZone.getDisplayName());
    log.info("TimeZone.ID=" + newDefaultTimeZone.getID());
    log.info("TimeZone.DSTSavings=" + newDefaultTimeZone.getDSTSavings());
    log.info("TimeZone.RawOffset=" + newDefaultTimeZone.getRawOffset());
    log.info("TimeZone.useDaylightTime=" + newDefaultTimeZone.useDaylightTime());
}

From source file:org.sipfoundry.sipxconfig.device.DeviceTimeZone.java

public void setTimeZone(TimeZone tz) {
    String tzn = tz.getID();/*from  w  w w . j ava  2s .co  m*/
    m_useDaylight = tz.useDaylightTime();
    m_offset = tz.getRawOffset() / (int) DateUtils.MILLIS_PER_MINUTE;

    m_dstSavings = tz.getDSTSavings() / (int) DateUtils.MILLIS_PER_MINUTE;

    // Until there is a setting for DST rule, it must be guessed here based on the timezone
    // name
    //
    // XCF-977 - Doing string compares on ID is not predicable! On my gentoo system, I get
    // US/Eastern but on a FC4 machine I get America/New_York. Both running java1.5.0.06
    // We'll wait for XCF-874 to address this properly. Until then, do not break whatever
    // seems to work for some systems in Europe, but default everyone else to US. Otherwise
    // the default of zero is not very helpful
    // See also: http://en.wikipedia.org/wiki/List_of_zoneinfo_time_zones
    if (tzn.matches("^Europe/.*")) {
        setDstParameters(DST_EU);
    } else {
        setDstParameters(DST_US);
    }
}

From source file:com.onesignal.OneSignal.java

private static int getTimeZoneOffset() {
    TimeZone timezone = Calendar.getInstance().getTimeZone();
    int offset = timezone.getRawOffset();

    if (timezone.inDaylightTime(new Date()))
        offset = offset + timezone.getDSTSavings();

    return offset / 1000;
}

From source file:com.microsoft.exchange.DateHelpTest.java

/**
 * Computes the time zone offset for a given {@link XMLGregorianCalendar} and compares to the specified {@link TimeZone}
 * //from w  ww . j  a  v  a2  s. com
 * 
 * 
 * @param xmlGregorianCalendar
 * @param timeZone
 */
public boolean xmlGregorianCalendareMatchesTimeZone(XMLGregorianCalendar xmlGregorianCalendar,
        TimeZone timeZone) {
    int xmlTimeZoneOffsetMinutes = xmlGregorianCalendar.getTimezone();
    TimeZone xmlTimeZone = xmlGregorianCalendar.getTimeZone(xmlTimeZoneOffsetMinutes);
    int jvmRawOffsetMinutes = (timeZone.getRawOffset() / 1000 / 60);
    int jvmDstOffsetMinutes = (timeZone.getDSTSavings() / 1000 / 60);

    int xmlRawOffsetMinutes = (xmlTimeZone.getRawOffset() / 1000 / 60);
    int xmlDstOffsetMinutes = (xmlTimeZone.getDSTSavings() / 1000 / 60);

    //XMLGregorianCalendar only stores an Int for offset, no DST information.  
    //as a result the xmlTimeZone and jvmTimeZone almost never follow the same rules
    if (timeZone.hasSameRules(xmlTimeZone)) {
        log.debug("xmlTimeZoneId=" + xmlTimeZone.getID() + " hasSameRules as jvmTimeZone=" + timeZone.getID());
        return true;
    }

    if (timeZone.useDaylightTime()) {
        //they definately do not when the jvmTimeZone uses DST.
        assertFalse(xmlTimeZone.hasSameRules(timeZone));
        jvmRawOffsetMinutes += jvmDstOffsetMinutes;
    }

    if (xmlTimeZone.useDaylightTime()) {
        xmlRawOffsetMinutes += xmlDstOffsetMinutes;
    }
    if (xmlTimeZoneOffsetMinutes != xmlRawOffsetMinutes) {
        log.info("xmlTimeZoneId=" + xmlTimeZone.getID() + " has weird rules");
    }

    return (jvmRawOffsetMinutes == xmlRawOffsetMinutes);

}

From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java

/**
 * Returns the amount of days between two given dates
 *///  ww w  . j  a  va  2  s  .  c  o  m
public static Long getDaysBetween(Date beginDate, Date endDate) {
    final TimeZone tz = TimeZone.getDefault();
    final long nowDstOffset = (tz.inDaylightTime(beginDate)) ? tz.getDSTSavings() : 0L;
    final long dateDstOffset = (tz.inDaylightTime(endDate)) ? tz.getDSTSavings() : 0L;
    return (endDate.getTime() + dateDstOffset - beginDate.getTime() - nowDstOffset) / DateUtils.MILLIS_PER_DAY;
}

From source file:com.mirth.connect.client.ui.StatusBar.java

private String convertLocalToServerTime() {
    TimeZone localTimeZone = TimeZone.getTimeZone(this.localTimeZone);
    TimeZone serverTimeZone = TimeZone.getTimeZone(this.serverTimeZone);

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MILLISECOND, (int) timeOffset);

    calendar.add(Calendar.MILLISECOND, localTimeZone.getRawOffset() * -1);
    if (localTimeZone.inDaylightTime(calendar.getTime())) {
        calendar.add(Calendar.MILLISECOND, localTimeZone.getDSTSavings() * -1);
    }/*from w  ww  .  j a va2s. co  m*/

    calendar.add(Calendar.MILLISECOND, serverTimeZone.getRawOffset());
    if (serverTimeZone.inDaylightTime(calendar.getTime())) {
        calendar.add(Calendar.MILLISECOND, serverTimeZone.getDSTSavings());
    }

    return new SimpleDateFormat("h:mm a").format(calendar.getTime());
}

From source file:com.linemetrics.monk.api.ApiClient.java

public DataItem getLastValue(Number dataStreamId, final TDB tdb, final TimeZone tz) throws ApiException {

    try {/*  ww  w.j a v  a2  s .c  om*/
        URI uri = restclient.buildURI(getBaseUri() + "/lastvalue/" + dataStreamId,
                new HashMap<String, String>() {
                    {
                        put("tdb", "" + tdb.getMilliseconds());
                        put("time_offset", "" + (tz.getRawOffset() + tz.getDSTSavings()));
                    }
                });

        JSONObject result = restclient.get(uri);
        if (result.containsKey("data")) {
            return new DataItem(result.get("data"));
        }
    } catch (Exception ex) {
        throw new ApiException(
                "Unable to retrieve last value of dataStream (" + dataStreamId + "): " + ex.getMessage(), ex);
    }

    return null;
}