Search in sources :

Example 41 with TimeZone

use of java.util.TimeZone in project j2objc by google.

the class TimeZoneTest method test_getDisplayName.

/**
     * @add test {@link java.util.TimeZone#getDisplayName()}
     */
public void test_getDisplayName() {
    TimeZone defaultZone = TimeZone.getDefault();
    Locale defaulLocal = Locale.getDefault();
    String defaultName = defaultZone.getDisplayName();
    String expectedName = defaultZone.getDisplayName(defaulLocal);
    assertEquals("getDispalyName() did not return the default Locale suitable name", expectedName, defaultName);
}
Also used : Locale(java.util.Locale) TimeZone(java.util.TimeZone) Support_TimeZone(tests.support.Support_TimeZone) SimpleTimeZone(java.util.SimpleTimeZone)

Example 42 with TimeZone

use of java.util.TimeZone in project j2objc by google.

the class NativeTimeZoneTest method testUTCAndGMT.

public void testUTCAndGMT() {
    TimeZone utc = TimeZone.getTimeZone("UTC");
    TimeZone gmt = TimeZone.getTimeZone("GMT");
    assertEquals("UTC", utc.getID());
    assertEquals("GMT", gmt.getID());
    // Same rules, but not equal.
    assertTrue(utc.hasSameRules(gmt));
    assertFalse(utc.equals(gmt));
    assertEquals(utc.getDSTSavings(), gmt.getDSTSavings());
    assertEquals(utc.getRawOffset(), gmt.getRawOffset());
    assertEquals(utc.useDaylightTime(), gmt.useDaylightTime());
    assertEquals(0, utc.getRawOffset());
    assertEquals(0, utc.getDSTSavings());
    assertFalse(utc.useDaylightTime());
    List<String> ids = Arrays.asList(TimeZone.getAvailableIDs());
    assertTrue(ids.contains(gmt.getID()));
    assertTrue(ids.contains(utc.getID()));
}
Also used : TimeZone(java.util.TimeZone)

Example 43 with TimeZone

use of java.util.TimeZone in project j2objc by google.

the class NativeTimeZoneTest method testEtcUTCAndEtcGMT.

/**
   * Different time zone libraries treat these two UTC alias differently. On OS X and iOS,
   * Etc/UTC and Etc/GMT are treated as two different time zones, even if their offset and other
   * fields are exactly the same as those in UTC. Therefore we don't even attempt to compare their
   * rules.
   */
public void testEtcUTCAndEtcGMT() {
    TimeZone utc = TimeZone.getTimeZone("UTC");
    TimeZone etcUtc = TimeZone.getTimeZone("Etc/UTC");
    TimeZone etcGmt = TimeZone.getTimeZone("Etc/GMT");
    assertEquals("Etc/UTC", etcUtc.getID());
    assertEquals("Etc/GMT", etcGmt.getID());
    assertEquals(utc.getDSTSavings(), etcGmt.getDSTSavings());
    assertEquals(utc.getRawOffset(), etcGmt.getRawOffset());
    assertEquals(utc.useDaylightTime(), etcGmt.useDaylightTime());
    assertEquals(utc.getDSTSavings(), etcUtc.getDSTSavings());
    assertEquals(utc.getRawOffset(), etcUtc.getRawOffset());
    assertEquals(utc.useDaylightTime(), etcUtc.useDaylightTime());
    assertEquals(0, utc.getRawOffset());
    assertEquals(0, utc.getDSTSavings());
    assertFalse(utc.useDaylightTime());
    List<String> ids = Arrays.asList(TimeZone.getAvailableIDs());
    String vmName = System.getProperty("java.vendor");
    if (vmName != null && vmName.startsWith("J2ObjC")) {
    // It's ok for Etc/UTC and Etc/GMT not to be part of TimeZone.getAvailableIDs().
    } else {
        assertTrue(ids.contains(etcGmt.getID()));
        assertTrue(ids.contains(etcUtc.getID()));
    }
}
Also used : TimeZone(java.util.TimeZone)

Example 44 with TimeZone

use of java.util.TimeZone in project j2objc by google.

the class NativeTimeZoneTest method testEST.

/**
   * Although Android SDK documentation says three-letter time zone IDs other than UTC and GMT are
   * not supported, actual implementations may still support them. The time zone "EST" is in
   * practice UTC-5 with the following properties.
   */
public void testEST() {
    TimeZone tz = TimeZone.getTimeZone("EST");
    assertEquals("EST", tz.getID());
    assertFalse(tz.useDaylightTime());
    assertEquals(-5 * 3600000, tz.getRawOffset());
    assertEquals(0, tz.getDSTSavings());
}
Also used : TimeZone(java.util.TimeZone)

Example 45 with TimeZone

use of java.util.TimeZone in project j2objc by google.

the class NativeTimeZoneTest method testGetOffsetWithLocalDates.

/**
   * Test the local date-based offset getter.
   */
public void testGetOffsetWithLocalDates() {
    TimeZone la = TimeZone.getTimeZone("America/Los_Angeles");
    // Recall Java calendar month is 0-based, and the dayOfWeek, parameter is actually ignored by
    // some implementations.
    // 2016-03-12T03:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(GregorianCalendar.AD, 2016, 2, 12, Calendar.SATURDAY, 10800000));
    // 2016-03-13T01:59:59.999-08:00
    assertEquals(-28800000, la.getOffset(GregorianCalendar.AD, 2016, 2, 13, Calendar.SUNDAY, 7200000 - 1));
    // 2016-03-13T02:00:00.000-08:00 (but 2 AM that day local time in America/Los_Angeles does not
    // exist, even though TimeZone returns something that is after the DST transition)
    assertEquals(-25200000, la.getOffset(GregorianCalendar.AD, 2016, 2, 13, Calendar.SUNDAY, 7200000));
    // 2016-03-13T02:30:00.000-08:00 (but 2:30 AM is a non-existent local time)
    assertEquals(-25200000, la.getOffset(GregorianCalendar.AD, 2016, 2, 13, Calendar.SUNDAY, 9000000));
    // 2016-03-13T02:59:59.999-08:00 (but 2:59:59.999 AM is a non-existent local time)
    assertEquals(-25200000, la.getOffset(GregorianCalendar.AD, 2016, 2, 13, Calendar.SUNDAY, 10800000 - 1));
    // 2016-03-13T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(GregorianCalendar.AD, 2016, 2, 13, Calendar.SUNDAY, 10800000));
    // 2016-03-13T03:00:00.001-07:00
    assertEquals(-25200000, la.getOffset(GregorianCalendar.AD, 2016, 2, 13, Calendar.SUNDAY, 10800000 + 1));
    // 2015-10-31T01:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(GregorianCalendar.AD, 2015, 9, 31, Calendar.SATURDAY, 3600000));
    // 2015-11-01T00:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(GregorianCalendar.AD, 2015, 10, 1, Calendar.SUNDAY, 0));
    // 2015-11-01T00:59:59.000-07:00
    assertEquals(-25200000, la.getOffset(GregorianCalendar.AD, 2015, 10, 1, Calendar.SUNDAY, 3600000 - 1));
    // 2015-11-01T01:00:00.000-08:00 (this is the evidence that TimeZone implementations always
    // prefer the local datetime in terms of the raw offset).
    assertEquals(-28800000, la.getOffset(GregorianCalendar.AD, 2015, 10, 1, Calendar.SUNDAY, 3600000));
    // 2015-11-01T01:59:59.999-08:00
    assertEquals(-28800000, la.getOffset(GregorianCalendar.AD, 2015, 10, 1, Calendar.SUNDAY, 7200000 - 1));
    // 2015-11-01T02:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(GregorianCalendar.AD, 2015, 10, 1, Calendar.SUNDAY, 7200000));
// Don't test any BC dates as it's meaningless.
}
Also used : TimeZone(java.util.TimeZone)

Aggregations

TimeZone (java.util.TimeZone)577 Date (java.util.Date)140 Calendar (java.util.Calendar)137 SimpleTimeZone (java.util.SimpleTimeZone)89 Test (org.junit.Test)85 SimpleDateFormat (java.text.SimpleDateFormat)69 Locale (java.util.Locale)69 GregorianCalendar (java.util.GregorianCalendar)56 ArrayList (java.util.ArrayList)32 DateFormat (java.text.DateFormat)24 ParseException (java.text.ParseException)23 IOException (java.io.IOException)20 Map (java.util.Map)15 HashSet (java.util.HashSet)13 PreparedStatement (java.sql.PreparedStatement)11 HashMap (java.util.HashMap)11 DateTimeZone (org.joda.time.DateTimeZone)11 Support_TimeZone (tests.support.Support_TimeZone)10 Resources (android.content.res.Resources)9 SQLException (java.sql.SQLException)9