Search in sources :

Example 96 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 97 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)

Example 98 with TimeZone

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

the class NativeTimeZoneTest method testResetDefaultTimeZone.

public void testResetDefaultTimeZone() {
    TimeZone defaultTz = TimeZone.getDefault();
    if (defaultTz.getID().equals("Etc/UTC")) {
        // We assume that the test is never run with the environment TZ=Etc/UTC, but just to be safe.
        return;
    }
    TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));
    assertEquals("Etc/UTC", TimeZone.getDefault().getID());
    // Manually post NSSystemTimeZoneDidChangeNotification, which is dispatched immediately to all
    // observers.
    postNSSystemTimeZoneDidChangeNotification();
    // The default time zone should be updated.
    assertNotNull(TimeZone.getDefault());
    assertFalse(TimeZone.getDefault().getID().equals("Etc/UTC"));
}
Also used : TimeZone(java.util.TimeZone)

Example 99 with TimeZone

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

the class NativeTimeZoneTest method testUSPacificTimeZoneTransitionsSince1970.

/**
   * Test that the TimeZone instance returns accurate offsets for instants in America/Los_Angeles
   * (commonly known as PT, which includes PST and PDT). This also accounts for the daylight
   * saving time (DST) change due to Energy Policy Act of 2005.
   */
public void testUSPacificTimeZoneTransitionsSince1970() {
    TimeZone la = TimeZone.getTimeZone("America/Los_Angeles");
    // 2016-03-13T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1457863200000L));
    // 2015-11-01T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1446368400000L));
    // 2015-03-08T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1425808800000L));
    // 2014-11-02T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1414918800000L));
    // 2014-03-09T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1394359200000L));
    // 2013-11-03T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1383469200000L));
    // 2013-03-10T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1362909600000L));
    // 2012-11-04T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1352019600000L));
    // 2012-03-11T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1331460000000L));
    // 2011-11-06T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1320570000000L));
    // 2011-03-13T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1300010400000L));
    // 2010-11-07T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1289120400000L));
    // 2010-03-14T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1268560800000L));
    // 2009-11-01T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1257066000000L));
    // 2009-03-08T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1236506400000L));
    // 2008-11-02T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1225616400000L));
    // 2008-03-09T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1205056800000L));
    // 2007-11-04T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1194166800000L));
    // 2007-03-11T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1173607200000L));
    // 2006-10-29T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1162112400000L));
    // 2006-04-02T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1143972000000L));
    // 2005-10-30T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1130662800000L));
    // 2005-04-03T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1112522400000L));
    // 2004-10-31T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1099213200000L));
    // 2004-04-04T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1081072800000L));
    // 2003-10-26T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1067158800000L));
    // 2003-04-06T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1049623200000L));
    // 2002-10-27T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1035709200000L));
    // 2002-04-07T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(1018173600000L));
    // 2001-10-28T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(1004259600000L));
    // 2001-04-01T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(986119200000L));
    // 2000-10-29T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(972810000000L));
    // 2000-04-02T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(954669600000L));
    // 1999-10-31T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(941360400000L));
    // 1999-04-04T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(923220000000L));
    // 1998-10-25T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(909306000000L));
    // 1998-04-05T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(891770400000L));
    // 1997-10-26T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(877856400000L));
    // 1997-04-06T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(860320800000L));
    // 1996-10-27T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(846406800000L));
    // 1996-04-07T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(828871200000L));
    // 1995-10-29T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(814957200000L));
    // 1995-04-02T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(796816800000L));
    // 1994-10-30T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(783507600000L));
    // 1994-04-03T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(765367200000L));
    // 1993-10-31T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(752058000000L));
    // 1993-04-04T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(733917600000L));
    // 1992-10-25T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(720003600000L));
    // 1992-04-05T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(702468000000L));
    // 1991-10-27T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(688554000000L));
    // 1991-04-07T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(671018400000L));
    // 1990-10-28T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(657104400000L));
    // 1990-04-01T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(638964000000L));
    // 1989-10-29T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(625654800000L));
    // 1989-04-02T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(607514400000L));
    // 1988-10-30T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(594205200000L));
    // 1988-04-03T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(576064800000L));
    // 1987-10-25T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(562150800000L));
    // 1987-04-05T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(544615200000L));
    // 1986-10-26T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(530701200000L));
    // 1986-04-27T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(514980000000L));
    // 1985-10-27T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(499251600000L));
    // 1985-04-28T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(483530400000L));
    // 1984-10-28T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(467802000000L));
    // 1984-04-29T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(452080800000L));
    // 1983-10-30T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(436352400000L));
    // 1983-04-24T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(420026400000L));
    // 1982-10-31T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(404902800000L));
    // 1982-04-25T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(388576800000L));
    // 1981-10-25T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(372848400000L));
    // 1981-04-26T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(357127200000L));
    // 1980-10-26T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(341398800000L));
    // 1980-04-27T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(325677600000L));
    // 1979-10-28T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(309949200000L));
    // 1979-04-29T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(294228000000L));
    // 1978-10-29T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(278499600000L));
    // 1978-04-30T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(262778400000L));
    // 1977-10-30T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(247050000000L));
    // 1977-04-24T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(230724000000L));
    // 1976-10-31T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(215600400000L));
    // 1976-04-25T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(199274400000L));
    // 1975-10-26T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(183546000000L));
    // 1975-02-23T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(162381600000L));
    // 1974-10-27T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(152096400000L));
    // 1974-01-06T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(126698400000L));
    // 1973-10-28T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(120646800000L));
    // 1973-04-29T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(104925600000L));
    // 1972-10-29T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(89197200000L));
    // 1972-04-30T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(73476000000L));
    // 1971-10-31T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(57747600000L));
    // 1971-04-25T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(41421600000L));
    // 1970-10-25T01:00:00.000-08:00
    assertEquals(-28800000, la.getOffset(25693200000L));
    // 1970-04-26T03:00:00.000-07:00
    assertEquals(-25200000, la.getOffset(9972000000L));
}
Also used : TimeZone(java.util.TimeZone)

Example 100 with TimeZone

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

the class NativeTimeZoneTest method testGetDisplayName.

/**
   * Test the locale-dependent display name of a time zone.
   *
   * JVM and iOS/OS X don't agree on the localized names, nor do they have the same localization
   * coverage, and so we are just testing a few shared traits here.
   */
public void testGetDisplayName() {
    TimeZone tz = TimeZone.getTimeZone("Europe/Paris");
    // JVM says Central European (Summer) Time, OS X/iOS uses Central European Standard/Summer Time.
    // Short names also differ and are not tested here.
    assertTrue(tz.getDisplayName(true, TimeZone.LONG, Locale.ENGLISH).startsWith("Central European"));
    assertTrue(tz.getDisplayName(true, TimeZone.LONG, Locale.ENGLISH).contains("Summer"));
    assertTrue(tz.getDisplayName(false, TimeZone.LONG, Locale.ENGLISH).startsWith("Central European"));
    assertFalse(tz.getDisplayName(false, TimeZone.LONG, Locale.ENGLISH).startsWith("Summer"));
    // French time zone names change across environment and OS versions, and so we only test common
    // substrings here.
    // French for "summer"
    final String ete = "été";
    // French for "forward"
    final String avancee = "avancée";
    String frStdName = tz.getDisplayName(false, TimeZone.LONG, Locale.FRANCE);
    String frDstName = tz.getDisplayName(true, TimeZone.LONG, Locale.FRANCE);
    assertTrue(frStdName.contains("Europe central"));
    assertFalse(frStdName.contains(ete) || frStdName.contains(avancee));
    assertTrue(frDstName.contains("Europe central"));
    assertTrue(frDstName.contains(ete) || frDstName.contains(avancee));
    // Similarly for German, though they finally agree on the DST name.
    assertTrue(tz.getDisplayName(true, TimeZone.LONG, Locale.GERMAN).equals("Mitteleuropäische Sommerzeit"));
    assertTrue(tz.getDisplayName(false, TimeZone.LONG, Locale.GERMAN).startsWith("Mitteleuropäische"));
    assertFalse(tz.getDisplayName(false, TimeZone.LONG, Locale.GERMAN).contains("Sommer"));
}
Also used : TimeZone(java.util.TimeZone)

Aggregations

TimeZone (java.util.TimeZone)533 Date (java.util.Date)135 Calendar (java.util.Calendar)125 SimpleTimeZone (java.util.SimpleTimeZone)89 Test (org.junit.Test)81 Locale (java.util.Locale)62 SimpleDateFormat (java.text.SimpleDateFormat)61 GregorianCalendar (java.util.GregorianCalendar)55 ArrayList (java.util.ArrayList)29 DateFormat (java.text.DateFormat)22 ParseException (java.text.ParseException)21 IOException (java.io.IOException)19 HashSet (java.util.HashSet)13 Map (java.util.Map)11 DateTimeZone (org.joda.time.DateTimeZone)11 Support_TimeZone (tests.support.Support_TimeZone)10 Resources (android.content.res.Resources)9 HashMap (java.util.HashMap)9 XmlResourceParser (android.content.res.XmlResourceParser)8 Timestamp (java.sql.Timestamp)7