Java Code Examples for java.util.SimpleTimeZone#getRawOffset()

The following examples show how to use java.util.SimpleTimeZone#getRawOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransitionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void Test4278609() {
    SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
                           /* DST start day: August, 1, 0:00 */
                           Calendar.AUGUST, 1, 0, 0,
                           /* DST end day: January, 1, 0:00 (wall-clock)*/
                           Calendar.JANUARY, 1, 0, 0,
                           60 * 60 * 1000);

    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    // setting a date using GMT zone just after the end rule of tz zone
    cal.clear();
    cal.set(Calendar.ERA, GregorianCalendar.AD);
    cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);

    Date date = cal.getTime();

    int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
                 + cal.get(Calendar.MINUTE) * 60000
                 + cal.get(Calendar.SECOND) * 1000
                 + cal.get(Calendar.MILLISECOND);
    /* we must use standard local time */
    millis += tz.getRawOffset();

    int offset = tz.getOffset(cal.get(Calendar.ERA),
                              cal.get(Calendar.YEAR),
                              cal.get(Calendar.MONTH),
                              cal.get(Calendar.DATE),
                              cal.get(Calendar.DAY_OF_WEEK),
                              millis);

    if (offset != 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
                                                       Locale.US);
        format.setTimeZone(tz);
        errln("Wrong DST transition: " + tz
              + "\na date just after DST = " + format.format(date)
              + "\ngetOffset = " + offset);
    }
}
 
Example 2
Source File: TransitionTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void Test4278609() {
    SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
                           /* DST start day: August, 1, 0:00 */
                           Calendar.AUGUST, 1, 0, 0,
                           /* DST end day: January, 1, 0:00 (wall-clock)*/
                           Calendar.JANUARY, 1, 0, 0,
                           60 * 60 * 1000);

    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    // setting a date using GMT zone just after the end rule of tz zone
    cal.clear();
    cal.set(Calendar.ERA, GregorianCalendar.AD);
    cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);

    Date date = cal.getTime();

    int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
                 + cal.get(Calendar.MINUTE) * 60000
                 + cal.get(Calendar.SECOND) * 1000
                 + cal.get(Calendar.MILLISECOND);
    /* we must use standard local time */
    millis += tz.getRawOffset();

    int offset = tz.getOffset(cal.get(Calendar.ERA),
                              cal.get(Calendar.YEAR),
                              cal.get(Calendar.MONTH),
                              cal.get(Calendar.DATE),
                              cal.get(Calendar.DAY_OF_WEEK),
                              millis);

    if (offset != 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
                                                       Locale.US);
        format.setTimeZone(tz);
        errln("Wrong DST transition: " + tz
              + "\na date just after DST = " + format.format(date)
              + "\ngetOffset = " + offset);
    }
}
 
Example 3
Source File: TransitionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void Test4278609() {
    SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
                           /* DST start day: August, 1, 0:00 */
                           Calendar.AUGUST, 1, 0, 0,
                           /* DST end day: January, 1, 0:00 (wall-clock)*/
                           Calendar.JANUARY, 1, 0, 0,
                           60 * 60 * 1000);

    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    // setting a date using GMT zone just after the end rule of tz zone
    cal.clear();
    cal.set(Calendar.ERA, GregorianCalendar.AD);
    cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);

    Date date = cal.getTime();

    int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
                 + cal.get(Calendar.MINUTE) * 60000
                 + cal.get(Calendar.SECOND) * 1000
                 + cal.get(Calendar.MILLISECOND);
    /* we must use standard local time */
    millis += tz.getRawOffset();

    int offset = tz.getOffset(cal.get(Calendar.ERA),
                              cal.get(Calendar.YEAR),
                              cal.get(Calendar.MONTH),
                              cal.get(Calendar.DATE),
                              cal.get(Calendar.DAY_OF_WEEK),
                              millis);

    if (offset != 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
                                                       Locale.US);
        format.setTimeZone(tz);
        errln("Wrong DST transition: " + tz
              + "\na date just after DST = " + format.format(date)
              + "\ngetOffset = " + offset);
    }
}
 
Example 4
Source File: TransitionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void Test4278609() {
    SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
                           /* DST start day: August, 1, 0:00 */
                           Calendar.AUGUST, 1, 0, 0,
                           /* DST end day: January, 1, 0:00 (wall-clock)*/
                           Calendar.JANUARY, 1, 0, 0,
                           60 * 60 * 1000);

    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    // setting a date using GMT zone just after the end rule of tz zone
    cal.clear();
    cal.set(Calendar.ERA, GregorianCalendar.AD);
    cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);

    Date date = cal.getTime();

    int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
                 + cal.get(Calendar.MINUTE) * 60000
                 + cal.get(Calendar.SECOND) * 1000
                 + cal.get(Calendar.MILLISECOND);
    /* we must use standard local time */
    millis += tz.getRawOffset();

    int offset = tz.getOffset(cal.get(Calendar.ERA),
                              cal.get(Calendar.YEAR),
                              cal.get(Calendar.MONTH),
                              cal.get(Calendar.DATE),
                              cal.get(Calendar.DAY_OF_WEEK),
                              millis);

    if (offset != 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
                                                       Locale.US);
        format.setTimeZone(tz);
        errln("Wrong DST transition: " + tz
              + "\na date just after DST = " + format.format(date)
              + "\ngetOffset = " + offset);
    }
}
 
Example 5
Source File: TransitionTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void Test4278609() {
    SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
                           /* DST start day: August, 1, 0:00 */
                           Calendar.AUGUST, 1, 0, 0,
                           /* DST end day: January, 1, 0:00 (wall-clock)*/
                           Calendar.JANUARY, 1, 0, 0,
                           60 * 60 * 1000);

    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    // setting a date using GMT zone just after the end rule of tz zone
    cal.clear();
    cal.set(Calendar.ERA, GregorianCalendar.AD);
    cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);

    Date date = cal.getTime();

    int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
                 + cal.get(Calendar.MINUTE) * 60000
                 + cal.get(Calendar.SECOND) * 1000
                 + cal.get(Calendar.MILLISECOND);
    /* we must use standard local time */
    millis += tz.getRawOffset();

    int offset = tz.getOffset(cal.get(Calendar.ERA),
                              cal.get(Calendar.YEAR),
                              cal.get(Calendar.MONTH),
                              cal.get(Calendar.DATE),
                              cal.get(Calendar.DAY_OF_WEEK),
                              millis);

    if (offset != 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
                                                       Locale.US);
        format.setTimeZone(tz);
        errln("Wrong DST transition: " + tz
              + "\na date just after DST = " + format.format(date)
              + "\ngetOffset = " + offset);
    }
}
 
Example 6
Source File: SimpleTimeZoneTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.SimpleTimeZone#setRawOffset(int)
 */
public void test_setRawOffsetI() {
    // Test for method void java.util.SimpleTimeZone.setRawOffset(int)

    st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
    int off = st1.getRawOffset();
    st1.setRawOffset(1000);
    boolean val = st1.getRawOffset() == 1000;
    st1.setRawOffset(off);
    assertTrue("Incorrect offset set", val);
}