Package java.util

Examples of java.util.SimpleTimeZone


  // Tests converted from the SimpleTimeZoneTest.java attachment
  // of http://gcc.gnu.org/ml/java-patches/2007-q1/msg00587.html.
  private void test2(TestHarness harness)
  {
    TimeZone utc = (TimeZone) new SimpleTimeZone(0, "GMT");
    TimeZone.setDefault(utc);
    Calendar cal = Calendar.getInstance(utc);

    TimeZone tz2 = new SimpleTimeZone(
      -12600000, "Test1",
      Calendar.MARCH, 8, -Calendar.SUNDAY, 60000,
      SimpleTimeZone.WALL_TIME,
      Calendar.NOVEMBER, 1, -Calendar.SUNDAY, 60000,
      SimpleTimeZone.STANDARD_TIME,
      3600000);

    TimeZone tz3 = new SimpleTimeZone(
      -12600000, "Test2",
      Calendar.MARCH, 8, -Calendar.SUNDAY, 60000,
      Calendar.NOVEMBER, 1, -Calendar.SUNDAY, 3660000,
      3600000);

    harness.check(!tz2.equals(tz3));

    ((SimpleTimeZone) tz2).setEndRule(
      Calendar.NOVEMBER, 1, -Calendar.SUNDAY, 3660000);
    tz3.setID("Test1");

    harness.check(tz2.equals(tz3));
  }
View Full Code Here


   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)
  {
    SimpleTimeZone z1 = new SimpleTimeZone(0, "Zone 1");
    harness.check(z1.getRawOffset(), 0);
    z1.setRawOffset(12345);
    harness.check(z1.getRawOffset(), 12345);
  }
View Full Code Here

  }

  private void testConstructor1(TestHarness harness)
  {
    harness.checkPoint("(int, String)");
    SimpleTimeZone z = new SimpleTimeZone(1234, "Z1");
    harness.check(z.getRawOffset(), 1234);
    harness.check(z.getID(), "Z1");
   
    // null id should throw exception
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
View Full Code Here

  }
 
  private void testConstructor2(TestHarness harness)
  {
    harness.checkPoint("(int, String, int, int, int, int, int, int, int, int)");
    SimpleTimeZone z = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 15, 0, 2*60*60*1000,
      Calendar.NOVEMBER, 22, 0, 2*60*60*1000);
    harness.check(z.getRawOffset(), 1234);
    harness.check(z.getID(), "Z1");
    harness.check(z.useDaylightTime());
    harness.check(z.getDSTSavings(), 60*60*1000);

    // null id should throw exception
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, null, Calendar.APRIL, 15, 0, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
    }
   
    // check for invalid start month
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z", 12, 15, 0, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid end month
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z", Calendar.APRIL, 15, 0, 2*60*60*1000,
        12, 22, 0, 2*60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid start day-of-month
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z", Calendar.APRIL, 33, 0, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid end day-of-month
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z", Calendar.APRIL, 15, 0, 2*60*60*1000,
        Calendar.NOVEMBER, 33, 0, 2*60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid start n (for nth day-of-week)
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z",
        Calendar.APRIL, 6, Calendar.MONDAY, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z",
        Calendar.APRIL, -6, Calendar.MONDAY, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid end n (for nth day-of-week)
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z",
        Calendar.APRIL, 1, Calendar.MONDAY, 2*60*60*1000,
        Calendar.NOVEMBER, 6, Calendar.MONDAY, 2*60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z",
        Calendar.APRIL, 1, Calendar.MONDAY, 2*60*60*1000,
        Calendar.NOVEMBER, -6, Calendar.MONDAY, 2*60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
View Full Code Here

    harness.checkPoint("set/restore default TimeZone ID");
   
    String id = "MyTZ";
    String id2 = "AnotherTZ";
   
    SimpleTimeZone stz = new SimpleTimeZone(60 * 60 * 1000, id);
   
    harness.check(stz.getID(), id);
   
    stz.setID(id2);
    harness.check(stz.getID(), id2);
   
    try
      {
  stz.setID(null);
  harness.check(false);
      }
    catch (NullPointerException e)
      {
  harness.check(true);
View Full Code Here

  }
 
  private void testConstructor3(TestHarness harness)
  {
    harness.checkPoint("(int, String, int, int, int, int, int, int, int, int, int)");
    SimpleTimeZone z = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 15, 0, 2*60*60*1000,
      Calendar.NOVEMBER, 22, 0, 2*60*60*1000, 123456);
    harness.check(z.getRawOffset(), 1234);
    harness.check(z.getID(), "Z1");
    harness.check(z.useDaylightTime());
    harness.check(z.getDSTSavings(), 123456);
   
    // null id should throw exception
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, null, Calendar.APRIL, 15, 0, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
    }
   
    // check for invalid start month
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z", 12, 15, 0, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid end month
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z", Calendar.APRIL, 15, 0, 2*60*60*1000,
        15, 22, 0, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // check for invalid start day-of-month
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z", Calendar.APRIL, 33, 0, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // check for invalid end day-of-month
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z", Calendar.APRIL, 15, 0, 2*60*60*1000,
        Calendar.NOVEMBER, 33, 0, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
 
    // check for invalid start n (for nth day of week)
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z",
        Calendar.APRIL, 6, Calendar.MONDAY, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z",
        Calendar.APRIL, -6, Calendar.MONDAY, 2*60*60*1000,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid end n (for nth day of week)
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z",
        Calendar.APRIL, 1, Calendar.MONDAY, 2*60*60*1000,
        Calendar.NOVEMBER, 6, Calendar.MONDAY, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, "Z",
        Calendar.APRIL, -1, Calendar.MONDAY, 2*60*60*1000,
        Calendar.NOVEMBER, -6, Calendar.MONDAY, 2*60*60*1000, 60*60*1000);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
View Full Code Here

  }
 
  private void testConstructor4(TestHarness harness)
  {
    harness.checkPoint("(int, String, int, int, int, int, int, int, int, int, int, int, int)");
    SimpleTimeZone z = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 15, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      Calendar.NOVEMBER, 22, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
    harness.check(z.getRawOffset(), 1234);
    harness.check(z.getID(), "Z1");
    harness.check(z.useDaylightTime());
    harness.check(z.getDSTSavings(), 123456);

    // null id should throw exception
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(0, null,
        Calendar.APRIL, 15, 0, 2*60*60*1000, SimpleTimeZone.WALL_TIME,
        Calendar.NOVEMBER, 22, 0, 2*60*60*1000, SimpleTimeZone.WALL_TIME,
        60*60*1000);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
    }
   
    // check for invalid start month
    try
    {
    SimpleTimeZone z2 = new SimpleTimeZone(1234, "Z1",
      12, 15, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      Calendar.NOVEMBER, 22, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid end month
    try
    {
    SimpleTimeZone z2 = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 15, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      12, 22, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // check for invalid start day-of-month
    try
    {
    SimpleTimeZone z2 = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 33, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      Calendar.NOVEMBER, 22, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // check for invalid end day-of-month
    try
    {
    SimpleTimeZone z2 = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 15, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      Calendar.NOVEMBER, 33, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // check for invalid n (for nth day-of-week)
    try
    {
    SimpleTimeZone z2 = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 6, Calendar.MONDAY, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      Calendar.NOVEMBER, 22, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, -6, Calendar.MONDAY, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      Calendar.NOVEMBER, 22, 0, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // check for invalid n (for nth day-of-week)
    try
    {
    SimpleTimeZone z2 = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 1, Calendar.MONDAY, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      Calendar.NOVEMBER, 6, Calendar.MONDAY, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    try
    {
      SimpleTimeZone z2 = new SimpleTimeZone(1234, "Z1",
      Calendar.APRIL, 1, Calendar.MONDAY, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      Calendar.NOVEMBER, -6, Calendar.MONDAY, 2*60*60*1000, SimpleTimeZone.UTC_TIME,
      123456);
      harness.check(false);
    }
View Full Code Here

   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)
  {
    int t = 2 * 60 * 60 * 1000;
    SimpleTimeZone z1 = new SimpleTimeZone(5 * 60 * 60 * 1000, "Zone 1",
      Calendar.JANUARY, 15, 0, t,
      Calendar.NOVEMBER, 11, 0, t,
      60 * 60 * 1000);
    SimpleTimeZone z2 = (SimpleTimeZone) z1.clone();
    harness.check(z1.equals(z2));
  }
View Full Code Here

      return;

    if (!new File(zdump).exists() || !new File(zoneinfodir).isDirectory())
      return;

    TimeZone utc = (TimeZone) new SimpleTimeZone(0, "GMT");
    TimeZone.setDefault(utc);

    String[] zones = TimeZone.getAvailableIDs();
    for (int i = 0; i < zones.length; i++)
      {
View Full Code Here

    // the second Monday, April 10 at 12 noon, ending the second
    // Sunday, September 10, 12 noon in daylight savings, 1 hour
    // shift.

    // All three should represent the same period
    SimpleTimeZone tz =
      new SimpleTimeZone(rawOff, "Z1",
       Calendar.APRIL, 10, 0, 43200000,
       Calendar.SEPTEMBER, 10, 0, 43200000,
       dstOff);

    int off;

    // Test 1/2 hour before dst
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 41400000);
    harness.check(off, rawOff);            // check 1
   
    // Test 1/2 hour into dst
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 2

    // Test end rule
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 3
   
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 4

    // Test that Nth dayofweek works with day of month rules
    tz.setStartRule(Calendar.APRIL, 2, Calendar.SATURDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 41400000);
    harness.check(off, rawOff);            // check 5
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 6

    tz.setEndRule(Calendar.SEPTEMBER, 2, Calendar.FRIDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 7
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 8

    // Test that -Nth dayofweek works with day of month rules
    tz.setStartRule(Calendar.APRIL, -3, Calendar.SATURDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 41400000);
    harness.check(off, rawOff);            // check 9
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 10, Calendar.SATURDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 10

    tz.setEndRule(Calendar.SEPTEMBER, -3, Calendar.FRIDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 11
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 12

    // Friday on or before April 5, 2004 is April 2
    // Test arguments get overidden and perform correctly
    tz.setStartRule(Calendar.APRIL, 5, Calendar.FRIDAY, 43200000, false);
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 2, Calendar.FRIDAY, 41400000);
    harness.check(off, rawOff);            // check 13
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 2, Calendar.FRIDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 14
   
    tz.setEndRule(Calendar.SEPTEMBER, -15, -Calendar.FRIDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 15
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 16

    // Sunday on or after April 5, 2004 is April 11
    // Test arguments get overidden and perform correctly
    tz.setStartRule(Calendar.APRIL, 5, Calendar.SUNDAY, 43200000, true);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 11, Calendar.SUNDAY, 41400000);
    harness.check(off, rawOff);            // check 17
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.APRIL, 11, Calendar.SUNDAY, 45000000);
    harness.check(off, rawOff + dstOff);   // check 18

    tz.setEndRule(Calendar.SEPTEMBER, 6, -Calendar.FRIDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 19
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.SEPTEMBER, 10, Calendar.FRIDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 20

    // Currently broken in GCJ
    tz.setEndRule(Calendar.SEPTEMBER, -6, -Calendar.TUESDAY, 43200000);

    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.AUGUST, 31, Calendar.TUESDAY, 41400000 - dstOff);
    harness.check(off, rawOff + dstOff);   // check 21
    off = tz.getOffset(GregorianCalendar.AD, 2004, Calendar.AUGUST, 31, Calendar.TUESDAY, 45000000 - dstOff);
    harness.check(off, rawOff);            // check 22

    // This looks like a Date or DateFormat test, but is here because there was a bug in SimpleTimeZone
    // PR libgcj/8321
    Date date = new Date(1034705556525l);
View Full Code Here

TOP

Related Classes of java.util.SimpleTimeZone

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.