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