Home | History | Annotate | Download | only in format
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.text.format;
     18 
     19 import android.test.suitebuilder.annotation.SmallTest;
     20 import android.test.suitebuilder.annotation.Suppress;
     21 import android.text.format.Time;
     22 import android.util.Log;
     23 import android.util.TimeFormatException;
     24 
     25 import junit.framework.TestCase;
     26 
     27 public class TimeTest extends TestCase {
     28 
     29     @SmallTest
     30     public void testNormalize0() throws Exception {
     31         Time t = new Time(Time.TIMEZONE_UTC);
     32         t.parse("20060432T010203");
     33         t.normalize(false /* use isDst */);
     34 //        System.out.println("got: " + t.year + '-'
     35 //                + t.month + '-' + t.monthDay
     36 //                + ' ' + t.hour + ':' + t.minute
     37 //                + ':' + t.second
     38 //                + "( " + t.isDst + ',' + t.gmtoff
     39 //                + ',' + t.weekDay
     40 //                + ',' + t.yearDay + ')');
     41     }
     42 
     43     private static class DateTest {
     44         public int year1;
     45         public int month1;
     46         public int day1;
     47         public int hour1;
     48         public int minute1;
     49         public int dst1;
     50 
     51         public int offset;
     52 
     53         public int year2;
     54         public int month2;
     55         public int day2;
     56         public int hour2;
     57         public int minute2;
     58         public int dst2;
     59 
     60         public DateTest(int year1, int month1, int day1, int hour1, int minute1, int dst1,
     61                 int offset, int year2, int month2, int day2, int hour2, int minute2,
     62                 int dst2) {
     63             this.year1 = year1;
     64             this.month1 = month1;
     65             this.day1 = day1;
     66             this.hour1 = hour1;
     67             this.minute1 = minute1;
     68             this.dst1 = dst1;
     69             this.offset = offset;
     70             this.year2 = year2;
     71             this.month2 = month2;
     72             this.day2 = day2;
     73             this.hour2 = hour2;
     74             this.minute2 = minute2;
     75             this.dst2 = dst2;
     76         }
     77 
     78         public DateTest(int year1, int month1, int day1, int hour1, int minute1,
     79                 int offset, int year2, int month2, int day2, int hour2, int minute2) {
     80             this.year1 = year1;
     81             this.month1 = month1;
     82             this.day1 = day1;
     83             this.hour1 = hour1;
     84             this.minute1 = minute1;
     85             this.dst1 = -1;
     86             this.offset = offset;
     87             this.year2 = year2;
     88             this.month2 = month2;
     89             this.day2 = day2;
     90             this.hour2 = hour2;
     91             this.minute2 = minute2;
     92             this.dst2 = -1;
     93         }
     94     }
     95 
     96     // These tests assume that DST changes on Nov 4, 2007 at 2am (to 1am).
     97 
     98     // The "offset" field in "dayTests" represents days.
     99     // Use normalize(true) with these tests to change the date by 1 day.
    100     private DateTest[] dayTests = {
    101             // The month numbers are 0-relative, so Jan=0, Feb=1,...Dec=11
    102 
    103             // Nov 4, 12am + 0 day = Nov 4, 12am
    104             // Nov 5, 12am + 0 day = Nov 5, 12am
    105             new DateTest(2007, 10, 4, 0, 0, 0, 2007, 10, 4, 0, 0),
    106             new DateTest(2007, 10, 5, 0, 0, 0, 2007, 10, 5, 0, 0),
    107 
    108             // Nov 3, 12am + 1 day = Nov 4, 12am
    109             // Nov 4, 12am + 1 day = Nov 5, 12am
    110             // Nov 5, 12am + 1 day = Nov 6, 12am
    111             new DateTest(2007, 10, 3, 0, 0, 1, 2007, 10, 4, 0, 0),
    112             new DateTest(2007, 10, 4, 0, 0, 1, 2007, 10, 5, 0, 0),
    113             new DateTest(2007, 10, 5, 0, 0, 1, 2007, 10, 6, 0, 0),
    114 
    115             // Nov 3, 1am + 1 day = Nov 4, 1am
    116             // Nov 4, 1am + 1 day = Nov 5, 1am
    117             // Nov 5, 1am + 1 day = Nov 6, 1am
    118             new DateTest(2007, 10, 3, 1, 0, 1, 2007, 10, 4, 1, 0),
    119             new DateTest(2007, 10, 4, 1, 0, 1, 2007, 10, 5, 1, 0),
    120             new DateTest(2007, 10, 5, 1, 0, 1, 2007, 10, 6, 1, 0),
    121 
    122             // Nov 3, 2am + 1 day = Nov 4, 2am
    123             // Nov 4, 2am + 1 day = Nov 5, 2am
    124             // Nov 5, 2am + 1 day = Nov 6, 2am
    125             new DateTest(2007, 10, 3, 2, 0, 1, 2007, 10, 4, 2, 0),
    126             new DateTest(2007, 10, 4, 2, 0, 1, 2007, 10, 5, 2, 0),
    127             new DateTest(2007, 10, 5, 2, 0, 1, 2007, 10, 6, 2, 0),
    128     };
    129 
    130     // The "offset" field in "minuteTests" represents minutes.
    131     // Use normalize(false) with these tests.
    132     private DateTest[] minuteTests = {
    133             // The month numbers are 0-relative, so Jan=0, Feb=1,...Dec=11
    134 
    135             // Nov 4, 12am + 0 minutes = Nov 4, 12am
    136             // Nov 5, 12am + 0 minutes = Nov 5, 12am
    137             new DateTest(2007, 10, 4, 0, 0, 0, 2007, 10, 4, 0, 0),
    138             new DateTest(2007, 10, 5, 0, 0, 0, 2007, 10, 5, 0, 0),
    139 
    140             // Nov 3, 12am + 60 minutes = Nov 3, 1am
    141             // Nov 4, 12am + 60 minutes = Nov 4, 1am
    142             // Nov 5, 12am + 60 minutes = Nov 5, 1am
    143             new DateTest(2007, 10, 3, 0, 0, 60, 2007, 10, 3, 1, 0),
    144             new DateTest(2007, 10, 4, 0, 0, 60, 2007, 10, 4, 1, 0),
    145             new DateTest(2007, 10, 5, 0, 0, 60, 2007, 10, 5, 1, 0),
    146 
    147             // Nov 3, 1am + 60 minutes = Nov 3, 2am
    148             // Nov 4, 1am (PDT) + 30 minutes = Nov 4, 1:30am (PDT)
    149             // Nov 4, 1am (PDT) + 60 minutes = Nov 4, 1am (PST)
    150             new DateTest(2007, 10, 3, 1, 0, 60, 2007, 10, 3, 2, 0),
    151             new DateTest(2007, 10, 4, 1, 0, 1, 30, 2007, 10, 4, 1, 30, 1),
    152             new DateTest(2007, 10, 4, 1, 0, 1, 60, 2007, 10, 4, 1, 0, 0),
    153 
    154             // Nov 4, 1:30am (PDT) + 15 minutes = Nov 4, 1:45am (PDT)
    155             // Nov 4, 1:30am (PDT) + 30 minutes = Nov 4, 1:00am (PST)
    156             // Nov 4, 1:30am (PDT) + 60 minutes = Nov 4, 1:30am (PST)
    157             new DateTest(2007, 10, 4, 1, 30, 1, 15, 2007, 10, 4, 1, 45, 1),
    158             new DateTest(2007, 10, 4, 1, 30, 1, 30, 2007, 10, 4, 1, 0, 0),
    159             new DateTest(2007, 10, 4, 1, 30, 1, 60, 2007, 10, 4, 1, 30, 0),
    160 
    161             // Nov 4, 1:30am (PST) + 15 minutes = Nov 4, 1:45am (PST)
    162             // Nov 4, 1:30am (PST) + 30 minutes = Nov 4, 2:00am (PST)
    163             // Nov 5, 1am + 60 minutes = Nov 5, 2am
    164             new DateTest(2007, 10, 4, 1, 30, 0, 15, 2007, 10, 4, 1, 45, 0),
    165             new DateTest(2007, 10, 4, 1, 30, 0, 30, 2007, 10, 4, 2, 0, 0),
    166             new DateTest(2007, 10, 5, 1, 0, 60, 2007, 10, 5, 2, 0),
    167 
    168             // Nov 3, 2am + 60 minutes = Nov 3, 3am
    169             // Nov 4, 2am + 30 minutes = Nov 4, 2:30am
    170             // Nov 4, 2am + 60 minutes = Nov 4, 3am
    171             // Nov 5, 2am + 60 minutes = Nov 5, 3am
    172             new DateTest(2007, 10, 3, 2, 0, 60, 2007, 10, 3, 3, 0),
    173             new DateTest(2007, 10, 4, 2, 0, 30, 2007, 10, 4, 2, 30),
    174             new DateTest(2007, 10, 4, 2, 0, 60, 2007, 10, 4, 3, 0),
    175             new DateTest(2007, 10, 5, 2, 0, 60, 2007, 10, 5, 3, 0),
    176     };
    177 
    178     @SmallTest
    179     public void testNormalize1() throws Exception {
    180         Time local = new Time("America/Los_Angeles");
    181 
    182         int len = dayTests.length;
    183         for (int index = 0; index < len; index++) {
    184             DateTest test = dayTests[index];
    185             local.set(0, test.minute1, test.hour1, test.day1, test.month1, test.year1);
    186             // call normalize() to make sure that isDst is set
    187             local.normalize(false /* use isDst */);
    188             local.monthDay += test.offset;
    189             local.normalize(true /* ignore isDst */);
    190             if (local.year != test.year2 || local.month != test.month2
    191                     || local.monthDay != test.day2 || local.hour != test.hour2
    192                     || local.minute != test.minute2) {
    193                 String expectedTime = String.format("%d-%02d-%02d %02d:%02d",
    194                         test.year2, test.month2, test.day2, test.hour2, test.minute2);
    195                 String actualTime = String.format("%d-%02d-%02d %02d:%02d",
    196                         local.year, local.month, local.monthDay, local.hour, local.minute);
    197                 throw new RuntimeException(
    198                         "day test index " + index + ", normalize(): expected local " + expectedTime
    199                                 + " got: " + actualTime);
    200             }
    201 
    202             local.set(0, test.minute1, test.hour1, test.day1, test.month1, test.year1);
    203             // call normalize() to make sure that isDst is set
    204             local.normalize(false /* use isDst */);
    205             local.monthDay += test.offset;
    206             long millis = local.toMillis(true /* ignore isDst */);
    207             local.set(millis);
    208             if (local.year != test.year2 || local.month != test.month2
    209                     || local.monthDay != test.day2 || local.hour != test.hour2
    210                     || local.minute != test.minute2) {
    211                 String expectedTime = String.format("%d-%02d-%02d %02d:%02d",
    212                         test.year2, test.month2, test.day2, test.hour2, test.minute2);
    213                 String actualTime = String.format("%d-%02d-%02d %02d:%02d",
    214                         local.year, local.month, local.monthDay, local.hour, local.minute);
    215                 throw new RuntimeException(
    216                         "day test index " + index + ", toMillis(): expected local " + expectedTime
    217                                 + " got: " + actualTime);
    218             }
    219         }
    220 
    221         len = minuteTests.length;
    222         for (int index = 0; index < len; index++) {
    223             DateTest test = minuteTests[index];
    224             local.set(0, test.minute1, test.hour1, test.day1, test.month1, test.year1);
    225             local.isDst = test.dst1;
    226             // call normalize() to make sure that isDst is set
    227             local.normalize(false /* use isDst */);
    228             if (test.dst2 == -1) test.dst2 = local.isDst;
    229             local.minute += test.offset;
    230             local.normalize(false /* use isDst */);
    231             if (local.year != test.year2 || local.month != test.month2
    232                     || local.monthDay != test.day2 || local.hour != test.hour2
    233                     || local.minute != test.minute2 || local.isDst != test.dst2) {
    234                 String expectedTime = String.format("%d-%02d-%02d %02d:%02d isDst: %d",
    235                         test.year2, test.month2, test.day2, test.hour2, test.minute2,
    236                         test.dst2);
    237                 String actualTime = String.format("%d-%02d-%02d %02d:%02d isDst: %d",
    238                         local.year, local.month, local.monthDay, local.hour, local.minute,
    239                         local.isDst);
    240                 throw new RuntimeException(
    241                         "minute test index " + index + ", normalize(): expected local " + expectedTime
    242                                 + " got: " + actualTime);
    243             }
    244 
    245             local.set(0, test.minute1, test.hour1, test.day1, test.month1, test.year1);
    246             local.isDst = test.dst1;
    247             // call normalize() to make sure that isDst is set
    248             local.normalize(false /* use isDst */);
    249             if (test.dst2 == -1) test.dst2 = local.isDst;
    250             local.minute += test.offset;
    251             long millis = local.toMillis(false /* use isDst */);
    252             local.set(millis);
    253             if (local.year != test.year2 || local.month != test.month2
    254                     || local.monthDay != test.day2 || local.hour != test.hour2
    255                     || local.minute != test.minute2 || local.isDst != test.dst2) {
    256                 String expectedTime = String.format("%d-%02d-%02d %02d:%02d isDst: %d",
    257                         test.year2, test.month2, test.day2, test.hour2, test.minute2,
    258                         test.dst2);
    259                 String actualTime = String.format("%d-%02d-%02d %02d:%02d isDst: %d",
    260                         local.year, local.month, local.monthDay, local.hour, local.minute,
    261                         local.isDst);
    262                 throw new RuntimeException(
    263                         "minute test index " + index + ", toMillis(): expected local " + expectedTime
    264                                 + " got: " + actualTime);
    265             }
    266         }
    267     }
    268 
    269     @SmallTest
    270     public void testSwitchTimezone0() throws Exception {
    271         Time t = new Time(Time.TIMEZONE_UTC);
    272         t.parse("20061005T120000");
    273         t.switchTimezone("America/Los_Angeles");
    274         // System.out.println("got: " + t);
    275     }
    276 
    277     @SmallTest
    278     public void testCtor0() throws Exception {
    279         Time t = new Time(Time.TIMEZONE_UTC);
    280         assertEquals(Time.TIMEZONE_UTC, t.timezone);
    281     }
    282 
    283     @SmallTest
    284     public void testGetActualMaximum0() throws Exception {
    285         Time t = new Time(Time.TIMEZONE_UTC);
    286         int r = t.getActualMaximum(Time.SECOND);
    287         // System.out.println("r=" + r);
    288     }
    289 
    290     @SmallTest
    291     public void testClear0() throws Exception {
    292         Time t = new Time(Time.TIMEZONE_UTC);
    293         t.clear(Time.TIMEZONE_UTC);
    294     }
    295 
    296     @SmallTest
    297     public void testCompare0() throws Exception {
    298         Time a = new Time(Time.TIMEZONE_UTC);
    299         Time b = new Time("America/Los_Angeles");
    300         int r = Time.compare(a, b);
    301         // System.out.println("r=" + r);
    302     }
    303 
    304     @SmallTest
    305     public void testFormat0() throws Exception {
    306         Time t = new Time(Time.TIMEZONE_UTC);
    307         String r = t.format("%Y%m%dT%H%M%S");
    308         // System.out.println("r='" + r + "'");
    309     }
    310 
    311     @SmallTest
    312     public void testToString0() throws Exception {
    313         Time t = new Time(Time.TIMEZONE_UTC);
    314         String r = t.toString();
    315         // System.out.println("r='" + r + "'");
    316     }
    317 
    318     @SmallTest
    319     public void testGetCurrentTimezone0() throws Exception {
    320         String r = Time.getCurrentTimezone();
    321         // System.out.println("r='" + r + "'");
    322     }
    323 
    324     @SmallTest
    325     public void testSetToNow0() throws Exception {
    326         Time t = new Time(Time.TIMEZONE_UTC);
    327         t.setToNow();
    328         // System.out.println("t=" + t);
    329     }
    330 
    331     @SmallTest
    332     public void testMillis0() throws Exception {
    333         Time t = new Time(Time.TIMEZONE_UTC);
    334         t.set(0, 0, 0, 1, 1, 2006);
    335         long r = t.toMillis(true /* ignore isDst */);
    336         // System.out.println("r=" + r);
    337         t.set(1, 0, 0, 1, 1, 2006);
    338         r = t.toMillis(true /* ignore isDst */);
    339         // System.out.println("r=" + r);
    340     }
    341 
    342     @SmallTest
    343     public void testMillis1() throws Exception {
    344         Time t = new Time(Time.TIMEZONE_UTC);
    345         t.set(1, 0, 0, 1, 0, 1970);
    346         long r = t.toMillis(true /* ignore isDst */);
    347         // System.out.println("r=" + r);
    348     }
    349 
    350     @SmallTest
    351     public void testParse0() throws Exception {
    352         Time t = new Time(Time.TIMEZONE_UTC);
    353         t.parse("12345678T901234");
    354         // System.out.println("t=" + t);
    355     }
    356 
    357     @SmallTest
    358     public void testParse33390() throws Exception {
    359         Time t = new Time(Time.TIMEZONE_UTC);
    360 
    361         t.parse3339("1980-05-23");
    362         if (!t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23) {
    363             fail("Did not parse all-day date correctly");
    364         }
    365 
    366         t.parse3339("1980-05-23T09:50:50");
    367         if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 ||
    368                 t.hour != 9 || t.minute != 50 || t.second != 50 ||
    369                 t.gmtoff != 0) {
    370             fail("Did not parse timezone-offset-less date correctly");
    371         }
    372 
    373         t.parse3339("1980-05-23T09:50:50Z");
    374         if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 ||
    375                 t.hour != 9 || t.minute != 50 || t.second != 50 ||
    376                 t.gmtoff != 0) {
    377             fail("Did not parse UTC date correctly");
    378         }
    379 
    380         t.parse3339("1980-05-23T09:50:50.0Z");
    381         if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 ||
    382                 t.hour != 9 || t.minute != 50 || t.second != 50 ||
    383                 t.gmtoff != 0) {
    384             fail("Did not parse UTC date correctly");
    385         }
    386 
    387         t.parse3339("1980-05-23T09:50:50.12Z");
    388         if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 ||
    389                 t.hour != 9 || t.minute != 50 || t.second != 50 ||
    390                 t.gmtoff != 0) {
    391             fail("Did not parse UTC date correctly");
    392         }
    393 
    394         t.parse3339("1980-05-23T09:50:50.123Z");
    395         if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 ||
    396                 t.hour != 9 || t.minute != 50 || t.second != 50 ||
    397                 t.gmtoff != 0) {
    398             fail("Did not parse UTC date correctly");
    399         }
    400 
    401         // The time should be normalized to UTC
    402         t.parse3339("1980-05-23T09:50:50-01:05");
    403         if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 ||
    404                 t.hour != 10 || t.minute != 55 || t.second != 50 ||
    405                 t.gmtoff != 0) {
    406             fail("Did not parse timezone-offset date correctly");
    407         }
    408 
    409         // The time should be normalized to UTC
    410         t.parse3339("1980-05-23T09:50:50.123-01:05");
    411         if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 ||
    412                 t.hour != 10 || t.minute != 55 || t.second != 50 ||
    413                 t.gmtoff != 0) {
    414             fail("Did not parse timezone-offset date correctly");
    415         }
    416 
    417         try {
    418             t.parse3339("1980");
    419             fail("Did not throw error on truncated input length");
    420         } catch (TimeFormatException e) {
    421             // Successful
    422         }
    423 
    424         try {
    425             t.parse3339("1980-05-23T09:50:50.123+");
    426             fail("Did not throw error on truncated timezone offset");
    427         } catch (TimeFormatException e1) {
    428             // Successful
    429         }
    430 
    431         try {
    432             t.parse3339("1980-05-23T09:50:50.123+05:0");
    433             fail("Did not throw error on truncated timezone offset");
    434         } catch (TimeFormatException e1) {
    435             // Successful
    436         }
    437     }
    438 
    439     @SmallTest
    440     public void testSet0() throws Exception {
    441         Time t = new Time(Time.TIMEZONE_UTC);
    442         t.set(1000L);
    443         // System.out.println("t.year=" + t.year);
    444         // System.out.println("t=" + t);
    445         t.set(2000L);
    446         // System.out.println("t=" + t);
    447         t.set(1000L * 60);
    448         // System.out.println("t=" + t);
    449         t.set((1000L * 60 * 60 * 24) + 1000L);
    450         // System.out.println("t=" + t);
    451     }
    452 
    453     @SmallTest
    454     public void testSet1() throws Exception {
    455         Time t = new Time(Time.TIMEZONE_UTC);
    456         t.set(1, 2, 3, 4, 5, 6);
    457         // System.out.println("t=" + t);
    458     }
    459 
    460     // Timezones that cover the world.  Some GMT offsets occur more than
    461     // once in case some cities decide to change their GMT offset.
    462     private static final String[] mTimeZones = {
    463         "Pacific/Kiritimati",
    464         "Pacific/Enderbury",
    465         "Pacific/Fiji",
    466         "Antarctica/South_Pole",
    467         "Pacific/Norfolk",
    468         "Pacific/Ponape",
    469         "Asia/Magadan",
    470         "Australia/Lord_Howe",
    471         "Australia/Sydney",
    472         "Australia/Adelaide",
    473         "Asia/Tokyo",
    474         "Asia/Seoul",
    475         "Asia/Taipei",
    476         "Asia/Singapore",
    477         "Asia/Hong_Kong",
    478         "Asia/Saigon",
    479         "Asia/Bangkok",
    480         "Indian/Cocos",
    481         "Asia/Rangoon",
    482         "Asia/Omsk",
    483         "Antarctica/Mawson",
    484         "Asia/Colombo",
    485         "Asia/Calcutta",
    486         "Asia/Oral",
    487         "Asia/Kabul",
    488         "Asia/Dubai",
    489         "Asia/Tehran",
    490         "Europe/Moscow",
    491         "Asia/Baghdad",
    492         "Africa/Mogadishu",
    493         "Europe/Athens",
    494         "Africa/Cairo",
    495         "Europe/Rome",
    496         "Europe/Berlin",
    497         "Europe/Amsterdam",
    498         "Africa/Tunis",
    499         "Europe/London",
    500         "Europe/Dublin",
    501         "Atlantic/St_Helena",
    502         "Africa/Monrovia",
    503         "Africa/Accra",
    504         "Atlantic/Azores",
    505         "Atlantic/South_Georgia",
    506         "America/Noronha",
    507         "America/Sao_Paulo",
    508         "America/Cayenne",
    509         "America/St_Johns",
    510         "America/Puerto_Rico",
    511         "America/Aruba",
    512         "America/New_York",
    513         "America/Chicago",
    514         "America/Denver",
    515         "America/Los_Angeles",
    516         "America/Anchorage",
    517         "Pacific/Marquesas",
    518         "America/Adak",
    519         "Pacific/Honolulu",
    520         "Pacific/Midway",
    521     };
    522 
    523     @Suppress
    524     public void disableTestGetJulianDay() throws Exception {
    525         Time time = new Time();
    526 
    527         // For each day of the year, and for each timezone, get the Julian
    528         // day for 12am and then check that if we change the time we get the
    529         // same Julian day.
    530         for (int monthDay = 1; monthDay <= 366; monthDay++) {
    531             for (int zoneIndex = 0; zoneIndex < mTimeZones.length; zoneIndex++) {
    532                 // We leave the "month" as zero because we are changing the
    533                 // "monthDay" from 1 to 366.  The call to normalize() will
    534                 // then change the "month" (but we don't really care).
    535                 time.set(0, 0, 0, monthDay, 0, 2008);
    536                 time.timezone = mTimeZones[zoneIndex];
    537                 long millis = time.normalize(true);
    538                 if (zoneIndex == 0) {
    539                     Log.i("TimeTest", time.format("%B %d, %Y"));
    540                 }
    541 
    542                 // This is the Julian day for 12am for this day of the year
    543                 int julianDay = Time.getJulianDay(millis, time.gmtoff);
    544 
    545                 // Change the time during the day and check that we get the same
    546                 // Julian day.
    547                 for (int hour = 0; hour < 24; hour++) {
    548                     for (int minute = 0; minute < 60; minute += 15) {
    549                         time.set(0, minute, hour, monthDay, 0, 2008);
    550                         millis = time.normalize(true);
    551                         int day = Time.getJulianDay(millis, time.gmtoff);
    552                         if (day != julianDay) {
    553                             Log.e("TimeTest", "Julian day: " + day + " at time "
    554                                     + time.hour + ":" + time.minute
    555                                     + " != today's Julian day: " + julianDay
    556                                     + " timezone: " + time.timezone);
    557                         }
    558                         assertEquals(day, julianDay);
    559                     }
    560                 }
    561             }
    562         }
    563     }
    564 
    565     @Suppress
    566     public void disableTestSetJulianDay() throws Exception {
    567         Time time = new Time();
    568 
    569         // For each day of the year in 2008, and for each timezone,
    570         // test that we can set the Julian day correctly.
    571         for (int monthDay = 1; monthDay <= 366; monthDay++) {
    572             for (int zoneIndex = 0; zoneIndex < mTimeZones.length; zoneIndex++) {
    573                 // We leave the "month" as zero because we are changing the
    574                 // "monthDay" from 1 to 366.  The call to normalize() will
    575                 // then change the "month" (but we don't really care).
    576                 time.set(0, 0, 0, monthDay, 0, 2008);
    577                 time.timezone = mTimeZones[zoneIndex];
    578                 long millis = time.normalize(true);
    579                 if (zoneIndex == 0) {
    580                     Log.i("TimeTest", time.format("%B %d, %Y"));
    581                 }
    582                 int julianDay = Time.getJulianDay(millis, time.gmtoff);
    583 
    584                 time.setJulianDay(julianDay);
    585 
    586                 // Some places change daylight saving time at 12am and so there
    587                 // is no 12am on some days in some timezones.  In those cases,
    588                 // the time is set to 1am.
    589                 // Examples: Africa/Cairo on April 25, 2008
    590                 //  America/Sao_Paulo on October 12, 2008
    591                 //  Atlantic/Azores on March 30, 2008
    592                 assertTrue(time.hour == 0 || time.hour == 1);
    593                 assertEquals(0, time.minute);
    594                 assertEquals(0, time.second);
    595 
    596                 millis = time.toMillis(false);
    597                 int day = Time.getJulianDay(millis, time.gmtoff);
    598                 if (day != julianDay) {
    599                     Log.i("TimeTest", "Error: gmtoff " + (time.gmtoff / 3600.0)
    600                             + " day " + julianDay
    601                             + " millis " + millis
    602                             + " " + time.format("%B %d, %Y") + " " + time.timezone);
    603                 }
    604                 assertEquals(day, julianDay);
    605             }
    606         }
    607     }
    608 }
    609