Search in sources :

Example 21 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class CalendarRegressionTest method dowTest.

void dowTest(boolean lenient) {
    GregorianCalendar cal = new GregorianCalendar();
    // Wednesday
    cal.set(1997, Calendar.AUGUST, 12);
    // cal.getTime(); // Force update
    cal.setLenient(lenient);
    // Set the date to be December 1,
    cal.set(1996, Calendar.DECEMBER, 1);
    // 1996
    int dow = cal.get(Calendar.DAY_OF_WEEK);
    int min = cal.getMinimum(Calendar.DAY_OF_WEEK);
    int max = cal.getMaximum(Calendar.DAY_OF_WEEK);
    logln(cal.getTime().toString());
    if (min != Calendar.SUNDAY || max != Calendar.SATURDAY)
        errln("FAIL: Min/max bad");
    if (dow < min || dow > max)
        errln("FAIL: Day of week " + dow + " out of range");
    if (dow != Calendar.SUNDAY)
        errln("FAIL: Day of week should be SUNDAY Got " + dow);
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar)

Example 22 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class CalendarRegressionTest method Test4059654.

/*
     * User error - no bug here public void Test4059524() { // Create calendar
     * for April 10, 1997 GregorianCalendar calendar = new GregorianCalendar(); //
     * print out a bunch of interesting things logln("ERA: " +
     * calendar.get(calendar.ERA)); logln("YEAR: " +
     * calendar.get(calendar.YEAR)); logln("MONTH: " +
     * calendar.get(calendar.MONTH)); logln("WEEK_OF_YEAR: " +
     * calendar.get(calendar.WEEK_OF_YEAR)); logln("WEEK_OF_MONTH: " +
     * calendar.get(calendar.WEEK_OF_MONTH)); logln("DATE: " +
     * calendar.get(calendar.DATE)); logln("DAY_OF_MONTH: " +
     * calendar.get(calendar.DAY_OF_MONTH)); logln("DAY_OF_YEAR: " +
     * calendar.get(calendar.DAY_OF_YEAR)); logln("DAY_OF_WEEK: " +
     * calendar.get(calendar.DAY_OF_WEEK)); logln("DAY_OF_WEEK_IN_MONTH: " +
     * calendar.get(calendar.DAY_OF_WEEK_IN_MONTH)); logln("AM_PM: " +
     * calendar.get(calendar.AM_PM)); logln("HOUR: " +
     * calendar.get(calendar.HOUR)); logln("HOUR_OF_DAY: " +
     * calendar.get(calendar.HOUR_OF_DAY)); logln("MINUTE: " +
     * calendar.get(calendar.MINUTE)); logln("SECOND: " +
     * calendar.get(calendar.SECOND)); logln("MILLISECOND: " +
     * calendar.get(calendar.MILLISECOND)); logln("ZONE_OFFSET: " +
     * (calendar.get(calendar.ZONE_OFFSET)/(60*60*1000))); logln("DST_OFFSET: " +
     * (calendar.get(calendar.DST_OFFSET)/(60*60*1000))); calendar = new
     * GregorianCalendar(1997,3,10); calendar.getTime(); logln("April 10,
     * 1997"); logln("ERA: " + calendar.get(calendar.ERA)); logln("YEAR: " +
     * calendar.get(calendar.YEAR)); logln("MONTH: " +
     * calendar.get(calendar.MONTH)); logln("WEEK_OF_YEAR: " +
     * calendar.get(calendar.WEEK_OF_YEAR)); logln("WEEK_OF_MONTH: " +
     * calendar.get(calendar.WEEK_OF_MONTH)); logln("DATE: " +
     * calendar.get(calendar.DATE)); logln("DAY_OF_MONTH: " +
     * calendar.get(calendar.DAY_OF_MONTH)); logln("DAY_OF_YEAR: " +
     * calendar.get(calendar.DAY_OF_YEAR)); logln("DAY_OF_WEEK: " +
     * calendar.get(calendar.DAY_OF_WEEK)); logln("DAY_OF_WEEK_IN_MONTH: " +
     * calendar.get(calendar.DAY_OF_WEEK_IN_MONTH)); logln("AM_PM: " +
     * calendar.get(calendar.AM_PM)); logln("HOUR: " +
     * calendar.get(calendar.HOUR)); logln("HOUR_OF_DAY: " +
     * calendar.get(calendar.HOUR_OF_DAY)); logln("MINUTE: " +
     * calendar.get(calendar.MINUTE)); logln("SECOND: " +
     * calendar.get(calendar.SECOND)); logln("MILLISECOND: " +
     * calendar.get(calendar.MILLISECOND)); logln("ZONE_OFFSET: " +
     * (calendar.get(calendar.ZONE_OFFSET)/(60*60*1000))); // in hours
     * logln("DST_OFFSET: " + (calendar.get(calendar.DST_OFFSET)/(60*60*1000))); //
     * in hours }
     */
@Test
public void Test4059654() {
    // try {
    // work around bug for jdk1.4 on solaris 2.6, which uses funky
    // timezone names
    // jdk1.4.1 will drop support for 2.6 so we should be ok when it
    // comes out
    java.util.TimeZone javazone = java.util.TimeZone.getTimeZone("GMT");
    TimeZone icuzone = TimeZone.getTimeZone("GMT");
    GregorianCalendar gc = new GregorianCalendar(icuzone);
    // April 1, 1997
    gc.set(1997, 3, 1, 15, 16, 17);
    gc.set(Calendar.HOUR, 0);
    gc.set(Calendar.AM_PM, Calendar.AM);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    Date cd = gc.getTime();
    java.util.Calendar cal = java.util.Calendar.getInstance(javazone);
    cal.clear();
    cal.set(1997, 3, 1, 0, 0, 0);
    Date exp = cal.getTime();
    if (!cd.equals(exp))
        errln("Fail: Calendar.set broken. Got " + cd + " Want " + exp);
// } catch (RuntimeException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
// }
}
Also used : SimpleTimeZone(android.icu.util.SimpleTimeZone) TimeZone(android.icu.util.TimeZone) GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 23 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class CalendarRegressionTest method Test4031502.

/*
      Synopsis: java.sql.Timestamp constructor works wrong on Windows 95

      ==== Here is the test ==== 
      public static void main (String args[]) { 
        java.sql.Timestamp t= new java.sql.Timestamp(0,15,5,5,8,13,123456700); 
        logln("expected=1901-04-05 05:08:13.1234567"); 
        logln(" result="+t); 
      } 
      
      ==== Here is the output of the test on Solaris or NT ==== 
      expected=1901-04-05 05:08:13.1234567 
      result=1901-04-05 05:08:13.1234567 
      
      ==== Here is the output of the test on Windows95 ==== 
      expected=1901-04-05 05:08:13.1234567 
      result=1901-04-05 06:08:13.1234567 
      */
@Test
public void Test4031502() {
    try {
        // This bug actually occurs on Windows NT as well, and doesn't
        // require the host zone to be set; it can be set in Java.
        String[] ids = TimeZone.getAvailableIDs();
        boolean bad = false;
        for (int i = 0; i < ids.length; ++i) {
            TimeZone zone = TimeZone.getTimeZone(ids[i]);
            GregorianCalendar cal = new GregorianCalendar(zone);
            cal.clear();
            cal.set(1900, 15, 5, 5, 8, 13);
            if (cal.get(Calendar.HOUR) != 5) {
                logln("Fail: " + zone.getID() + " " + zone.useDaylightTime() + "; DST_OFFSET = " + cal.get(Calendar.DST_OFFSET) / (60 * 60 * 1000.0) + "; ZONE_OFFSET = " + cal.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000.0) + "; getRawOffset() = " + zone.getRawOffset() / (60 * 60 * 1000.0) + "; HOUR = " + cal.get(Calendar.HOUR));
                cal.clear();
                cal.set(1900, 15, 5, 5, 8, 13);
                if (cal.get(Calendar.HOUR) != 5) {
                    logln("Fail: " + zone.getID() + " " + zone.useDaylightTime() + "; DST_OFFSET = " + cal.get(Calendar.DST_OFFSET) / (60 * 60 * 1000.0) + "; ZONE_OFFSET = " + cal.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000.0) + "; getRawOffset() = " + zone.getRawOffset() / (60 * 60 * 1000.0) + "; HOUR = " + cal.get(Calendar.HOUR));
                    cal.clear();
                    cal.set(1900, 15, 5, 5, 8, 13);
                    logln("ms = " + cal.getTime() + " (" + cal.getTime().getTime() + ")");
                    cal.get(Calendar.HOUR);
                    java.util.GregorianCalendar cal2 = new java.util.GregorianCalendar(java.util.TimeZone.getTimeZone(ids[i]));
                    cal2.clear();
                    cal2.set(1900, 15, 5, 5, 8, 13);
                    cal2.get(Calendar.HOUR);
                    logln("java.util.GC: " + zone.getID() + " " + zone.useDaylightTime() + "; DST_OFFSET = " + cal2.get(Calendar.DST_OFFSET) / (60 * 60 * 1000.0) + "; ZONE_OFFSET = " + cal2.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000.0) + "; getRawOffset() = " + zone.getRawOffset() / (60 * 60 * 1000.0) + "; HOUR = " + cal.get(Calendar.HOUR));
                    logln("ms = " + cal2.getTime() + " (" + cal2.getTime().getTime() + ")");
                    bad = true;
                } else if (false) {
                    // Change to true to debug
                    logln("OK: " + zone.getID() + " " + zone.useDaylightTime() + " " + cal.get(Calendar.DST_OFFSET) / (60 * 60 * 1000) + " " + zone.getRawOffset() / (60 * 60 * 1000) + ": HOUR = " + cal.get(Calendar.HOUR));
                }
            }
            if (bad)
                errln("TimeZone problems with GC");
        }
    } catch (MissingResourceException e) {
        warnln("Could not load data. " + e.getMessage());
    }
}
Also used : SimpleTimeZone(android.icu.util.SimpleTimeZone) TimeZone(android.icu.util.TimeZone) MissingResourceException(java.util.MissingResourceException) GregorianCalendar(android.icu.util.GregorianCalendar) Test(org.junit.Test)

Example 24 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class CalendarRegressionTest method Test4070502.

@Test
public void Test4070502() {
    java.util.Calendar tempcal = java.util.Calendar.getInstance();
    tempcal.clear();
    tempcal.set(1998, 0, 30);
    Date d = getAssociatedDate(tempcal.getTime());
    Calendar cal = new GregorianCalendar();
    cal.setTime(d);
    if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
        errln("Fail: Want weekday Got " + d);
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) Calendar(android.icu.util.Calendar) GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 25 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class CalendarRegressionTest method Test4095407.

@Test
public void Test4095407() {
    GregorianCalendar a = new GregorianCalendar(1997, Calendar.NOVEMBER, 13);
    int dow = a.get(Calendar.DAY_OF_WEEK);
    if (dow != Calendar.THURSDAY)
        errln("Fail: Want THURSDAY Got " + dow);
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) Test(org.junit.Test)

Aggregations

GregorianCalendar (android.icu.util.GregorianCalendar)111 Test (org.junit.Test)102 Date (java.util.Date)63 Calendar (android.icu.util.Calendar)40 SimpleDateFormat (android.icu.text.SimpleDateFormat)34 SimpleTimeZone (android.icu.util.SimpleTimeZone)28 TimeZone (android.icu.util.TimeZone)28 DateFormat (android.icu.text.DateFormat)24 JapaneseCalendar (android.icu.util.JapaneseCalendar)17 ULocale (android.icu.util.ULocale)16 ChineseCalendar (android.icu.util.ChineseCalendar)15 IslamicCalendar (android.icu.util.IslamicCalendar)14 BuddhistCalendar (android.icu.util.BuddhistCalendar)12 ChineseDateFormat (android.icu.text.ChineseDateFormat)8 IOException (java.io.IOException)8 ParsePosition (java.text.ParsePosition)8 CalendarAstronomer (android.icu.impl.CalendarAstronomer)7 HebrewCalendar (android.icu.util.HebrewCalendar)7 FieldPosition (java.text.FieldPosition)7 ParseException (java.text.ParseException)6