Example usage for com.google.gwt.core.client JsDate getTimezoneOffset

List of usage examples for com.google.gwt.core.client JsDate getTimezoneOffset

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsDate getTimezoneOffset.

Prototype

public final native int getTimezoneOffset() ;

Source Link

Document

Returns the difference, in minutes, between the local and UTC representations of this date.

Usage

From source file:java.util.Date.java

License:Apache License

/**
 * Detects if the requested time falls into a non-existent time range due to
 * local time advancing into daylight savings time. If so, push the requested
 * time forward out of the non-existent range.
 *//*  w  ww.  j a v a  2 s .c om*/
private void fixDaylightSavings(int hours) {
    if ((jsdate.getHours() % 24) != (hours % 24)) {
        JsDate copy = JsDate.create(jsdate.getTime());
        copy.setDate(copy.getDate() + 1);
        int timeDiff = jsdate.getTimezoneOffset() - copy.getTimezoneOffset();

        // If the time zone offset is changing, advance the hours and
        // minutes from the initially requested time by the change amount
        if (timeDiff > 0) {
            int timeDiffHours = timeDiff / 60;
            int timeDiffMinutes = timeDiff % 60;
            int day = jsdate.getDate();
            int badHours = jsdate.getHours();
            if (badHours + timeDiffHours >= 24) {
                day++;
            }
            JsDate newTime = JsDate.create(jsdate.getFullYear(), jsdate.getMonth(), day, hours + timeDiffHours,
                    jsdate.getMinutes() + timeDiffMinutes, jsdate.getSeconds(), jsdate.getMilliseconds());
            jsdate.setTime(newTime.getTime());
        }
    }
}