Search in sources :

Example 36 with TimeZone

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

the class TimeZoneTest method test_getOffset_long.

/**
     * java.util.TimeZone#getOffset(long)
     */
public void test_getOffset_long() {
    // Test for method int java.util.TimeZone.getOffset(long time)
    // test on subclass SimpleTimeZone
    TimeZone st1 = TimeZone.getTimeZone("EST");
    long time1 = new GregorianCalendar(1998, Calendar.NOVEMBER, 11).getTimeInMillis();
    assertEquals("T1. Incorrect offset returned", -(5 * ONE_HOUR), st1.getOffset(time1));
    long time2 = new GregorianCalendar(1998, Calendar.JUNE, 11).getTimeInMillis();
    st1 = TimeZone.getTimeZone("EST");
    assertEquals("T2. Incorrect offset returned", -(5 * ONE_HOUR), st1.getOffset(time2));
    // test on subclass Support_TimeZone, an instance with daylight savings
    TimeZone tz1 = new Support_TimeZone(-5 * ONE_HOUR, true);
    assertEquals("T3. Incorrect offset returned, ", -(5 * ONE_HOUR), tz1.getOffset(time1));
    assertEquals("T4. Incorrect offset returned, ", -(4 * ONE_HOUR), tz1.getOffset(time2));
    // an instance without daylight savings
    tz1 = new Support_TimeZone(3 * ONE_HOUR, false);
    assertEquals("T5. Incorrect offset returned, ", (3 * ONE_HOUR), tz1.getOffset(time1));
    assertEquals("T6. Incorrect offset returned, ", (3 * ONE_HOUR), tz1.getOffset(time2));
}
Also used : TimeZone(java.util.TimeZone) Support_TimeZone(tests.support.Support_TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar) Support_TimeZone(tests.support.Support_TimeZone)

Example 37 with TimeZone

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

the class TimeZoneTest method test_setDefaultLjava_util_TimeZone.

/**
     * java.util.TimeZone#setDefault(java.util.TimeZone)
     */
public void test_setDefaultLjava_util_TimeZone() {
    // NOTE: Required to get tests passing under vogar. Vogar sets
    // a hardcoded timezone before running every test, so we have to
    // set it back to the "real" default before we run the test.
    TimeZone.setDefault(null);
    TimeZone oldDefault = TimeZone.getDefault();
    TimeZone zone = new SimpleTimeZone(45, "TEST");
    TimeZone.setDefault(zone);
    assertEquals("timezone not set", zone, TimeZone.getDefault());
    TimeZone.setDefault(null);
    assertEquals("default not restored", oldDefault, TimeZone.getDefault());
}
Also used : TimeZone(java.util.TimeZone) Support_TimeZone(tests.support.Support_TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone)

Example 38 with TimeZone

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

the class TimeZoneTest method test_getDSTSavings.

/**
     * java.util.TimeZone#getDSTSavings()
     */
public void test_getDSTSavings() {
    // Test for method int java.util.TimeZone.getDSTSavings()
    // test on subclass SimpleTimeZone
    TimeZone st1 = TimeZone.getTimeZone("America/New_York");
    assertEquals("T1A. Incorrect daylight savings returned", ONE_HOUR, st1.getDSTSavings());
    // a SimpleTimeZone with daylight savings different then 1 hour
    st1 = TimeZone.getTimeZone("Australia/Lord_Howe");
    assertEquals("T1B. Incorrect daylight savings returned", 1800000, st1.getDSTSavings());
    // test on subclass Support_TimeZone, an instance with daylight savings
    TimeZone tz1 = new Support_TimeZone(-5 * ONE_HOUR, true);
    assertEquals("T2. Incorrect daylight savings returned", ONE_HOUR, tz1.getDSTSavings());
    // an instance without daylight savings
    tz1 = new Support_TimeZone(3 * ONE_HOUR, false);
    assertEquals("T3. Incorrect daylight savings returned, ", 0, tz1.getDSTSavings());
}
Also used : TimeZone(java.util.TimeZone) Support_TimeZone(tests.support.Support_TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Support_TimeZone(tests.support.Support_TimeZone)

Example 39 with TimeZone

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

the class TimeZoneTest method test_getDisplayName_ZI.

/**
     * @add test {@link java.util.TimeZone#getDisplayName(boolean, int)}
     */
public void test_getDisplayName_ZI() {
    TimeZone defaultZone = TimeZone.getDefault();
    Locale defaultLocale = Locale.getDefault();
    String actualName = defaultZone.getDisplayName(false, TimeZone.LONG);
    String expectedName = defaultZone.getDisplayName(false, TimeZone.LONG, defaultLocale);
    assertEquals("getDisplayName(daylight,style) did not return the default locale suitable name", expectedName, actualName);
}
Also used : Locale(java.util.Locale) TimeZone(java.util.TimeZone) Support_TimeZone(tests.support.Support_TimeZone) SimpleTimeZone(java.util.SimpleTimeZone)

Example 40 with TimeZone

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

the class TimeZoneTest method test_getAvailableIDs_I.

public void test_getAvailableIDs_I() {
    TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
    int rawoffset = tz.getRawOffset();
    String[] ids = TimeZone.getAvailableIDs(rawoffset);
    List<String> idList = Arrays.asList(ids);
    assertTrue(idList.toString(), idList.contains("Asia/Hong_Kong"));
}
Also used : TimeZone(java.util.TimeZone) Support_TimeZone(tests.support.Support_TimeZone) SimpleTimeZone(java.util.SimpleTimeZone)

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