summaryrefslogtreecommitdiff
path: root/android_icu4j/src/main/tests/android/icu/dev/test/calendar/IBMCalendarTest.java
blob: 1ff38f56fdca3c3282b67ff74cb5e8c2fe091bb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
/* GENERATED SOURCE. DO NOT MODIFY. */
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html#License
/*
 *******************************************************************************
 * Copyright (C) 2000-2016, International Business Machines Corporation and
 * others. All Rights Reserved.
 *******************************************************************************
 */
package android.icu.dev.test.calendar;

import java.text.FieldPosition;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;
import java.util.Set;

import org.junit.Test;

import android.icu.impl.CalendarAstronomer;
import android.icu.impl.LocaleUtility;
import android.icu.impl.ZoneMeta;
import android.icu.text.DateFormat;
import android.icu.text.DateFormatSymbols;
import android.icu.text.SimpleDateFormat;
import android.icu.util.BuddhistCalendar;
import android.icu.util.Calendar;
import android.icu.util.ChineseCalendar;
import android.icu.util.GregorianCalendar;
import android.icu.util.JapaneseCalendar;
import android.icu.util.TaiwanCalendar;
import android.icu.util.TimeZone;
import android.icu.util.TimeZone.SystemTimeZoneType;
import android.icu.util.ULocale;
import android.icu.testsharding.MainTestShard;

/**
 * @summary Tests of new functionality in IBMCalendar
 */
@MainTestShard
public class IBMCalendarTest extends CalendarTestFmwk {
    /**
     * Test weekend support in IBMCalendar.
     *
     * NOTE: This test will have to be updated when the isWeekend() etc.
     *       API is finalized later.
     *
     *       In particular, the test will have to be rewritten to instantiate
     *       a Calendar in the given locale (using getInstance()) and call
     *       that Calendar's isWeekend() etc. methods.
     */
    @Test
    public void TestWeekend() {
        SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd yyyy G HH:mm:ss.SSS");

        // NOTE
        // This test tests for specific locale data.  This is probably okay
        // as far as US data is concerned, but if the Arabic/Yemen data
        // changes, this test will have to be updated.

        // Test specific days
        Object[] DATA1 = {
            Locale.US, new int[] { // Saturday:Sunday
                2000, Calendar.MARCH, 17, 23,  0, 0, // Fri 23:00
                2000, Calendar.MARCH, 18,  0, -1, 0, // Fri 23:59:59.999
                2000, Calendar.MARCH, 18,  0,  0, 1, // Sat 00:00
                2000, Calendar.MARCH, 18, 15,  0, 1, // Sat 15:00
                2000, Calendar.MARCH, 19, 23,  0, 1, // Sun 23:00
                2000, Calendar.MARCH, 20,  0, -1, 1, // Sun 23:59:59.999
                2000, Calendar.MARCH, 20,  0,  0, 0, // Mon 00:00
                2000, Calendar.MARCH, 20,  8,  0, 0, // Mon 08:00
            },
            new Locale("ar", "OM"), new int[] { // Friday:Saturday
                2000, Calendar.MARCH, 15, 23,  0, 0, // Wed 23:00
                2000, Calendar.MARCH, 16,  0, -1, 0, // Wed 23:59:59.999
                2000, Calendar.MARCH, 16,  0,  0, 0, // Thu 00:00
                2000, Calendar.MARCH, 16, 15,  0, 0, // Thu 15:00
                2000, Calendar.MARCH, 17, 23,  0, 1, // Fri 23:00
                2000, Calendar.MARCH, 18,  0, -1, 1, // Fri 23:59:59.999
                2000, Calendar.MARCH, 18,  0,  0, 1, // Sat 00:00
                2000, Calendar.MARCH, 18,  8,  0, 1, // Sat 08:00
            },
        };

        // Test days of the week
        Object[] DATA2 = {
            Locale.US, new int[] {
                Calendar.MONDAY,   Calendar.WEEKDAY,
                Calendar.FRIDAY,   Calendar.WEEKDAY,
                Calendar.SATURDAY, Calendar.WEEKEND,
                Calendar.SUNDAY,   Calendar.WEEKEND,
            },
            new Locale("ar", "OM"), new int[] { // Friday:Saturday
                Calendar.WEDNESDAY,Calendar.WEEKDAY,
                Calendar.THURSDAY, Calendar.WEEKDAY,
                Calendar.FRIDAY,   Calendar.WEEKEND,
                Calendar.SATURDAY, Calendar.WEEKEND,
            },
            new Locale("hi", "IN"), new int[] { // Sunday only
                Calendar.MONDAY,   Calendar.WEEKDAY,
                Calendar.FRIDAY,   Calendar.WEEKDAY,
                Calendar.SATURDAY, Calendar.WEEKDAY,
                Calendar.SUNDAY,   Calendar.WEEKEND,
            },
        };

        // We only test the getDayOfWeekType() and isWeekend() APIs.
        // The getWeekendTransition() API is tested indirectly via the
        // isWeekend() API, which calls it.

        for (int i1=0; i1<DATA1.length; i1+=2) {
            Locale loc = (Locale)DATA1[i1];
            int[] data = (int[]) DATA1[i1+1];
            Calendar cal = Calendar.getInstance(loc);
            logln("Locale: " + loc);
            for (int i=0; i<data.length; i+=6) {
                cal.clear();
                cal.set(data[i], data[i+1], data[i+2], data[i+3], 0, 0);
                if (data[i+4] != 0) {
                    cal.setTime(new Date(cal.getTime().getTime() + data[i+4]));
                }
                boolean isWeekend = cal.isWeekend();
                boolean ok = isWeekend == (data[i+5] != 0);
                if (ok) {
                    logln("Ok:   " + fmt.format(cal.getTime()) + " isWeekend=" + isWeekend);
                } else {
                    errln("FAIL: " + fmt.format(cal.getTime()) + " isWeekend=" + isWeekend +
                          ", expected=" + (!isWeekend));
                }
            }
        }

        for (int i2=0; i2<DATA2.length; i2+=2) {
            Locale loc = (Locale)DATA2[i2];
            int[] data = (int[]) DATA2[i2+1];
            logln("Locale: " + loc);
            Calendar cal = Calendar.getInstance(loc);
            for (int i=0; i<data.length; i+=2) {
                int type = cal.getDayOfWeekType(data[i]);
                int exp  = data[i+1];
                if (type == exp) {
                    logln("Ok:   DOW " + data[i] + " type=" + type);
                } else {
                    errln("FAIL: DOW " + data[i] + " type=" + type +
                          ", expected=" + exp);
                }
            }
        }
    }

    /**
     * Run a test of a quasi-Gregorian calendar.  This is a calendar
     * that behaves like a Gregorian but has different year/era mappings.
     * The int[] data array should have the format:
     *
     * { era, year, gregorianYear, month, dayOfMonth, ... }
     */
    void quasiGregorianTest(Calendar cal, int[] data) {
        // As of JDK 1.4.1_01, using the Sun JDK GregorianCalendar as
        // a reference throws us off by one hour.  This is most likely
        // due to the JDK 1.4 incorporation of historical time zones.
        //java.util.Calendar grego = java.util.Calendar.getInstance();
        Calendar grego = Calendar.getInstance();
        for (int i=0; i<data.length; ) {
            int era = data[i++];
            int year = data[i++];
            int gregorianYear = data[i++];
            int month = data[i++];
            int dayOfMonth = data[i++];

            grego.clear();
            grego.set(gregorianYear, month, dayOfMonth);
            Date D = grego.getTime();

            cal.clear();
            cal.set(Calendar.ERA, era);
            cal.set(year, month, dayOfMonth);
            Date d = cal.getTime();
            if (d.equals(D)) {
                logln("OK: " + era + ":" + year + "/" + (month+1) + "/" + dayOfMonth +
                      " => " + d);
            } else {
                errln("Fail: " + era + ":" + year + "/" + (month+1) + "/" + dayOfMonth +
                      " => " + d + ", expected " + D);
            }

            cal.clear();
            cal.setTime(D);
            int e = cal.get(Calendar.ERA);
            int y = cal.get(Calendar.YEAR);
            if (y == year && e == era) {
                logln("OK: " + D + " => " + cal.get(Calendar.ERA) + ":" +
                      cal.get(Calendar.YEAR) + "/" +
                      (cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.DATE));
            } else {
                logln("Fail: " + D + " => " + cal.get(Calendar.ERA) + ":" +
                      cal.get(Calendar.YEAR) + "/" +
                      (cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.DATE) +
                      ", expected " + era + ":" + year + "/" + (month+1) + "/" +
                      dayOfMonth);
            }
        }
    }

    /**
     * Verify that BuddhistCalendar shifts years to Buddhist Era but otherwise
     * behaves like GregorianCalendar.
     */
    @Test
    public void TestBuddhist() {
        quasiGregorianTest(new BuddhistCalendar(),
                           new int[] {
                               // BE 2542 == 1999 CE
                               0, 2542, 1999, Calendar.JUNE, 4
                           });
    }

    @Test
    public void TestBuddhistCoverage() {
    {
        // new BuddhistCalendar(ULocale)
        BuddhistCalendar cal = new BuddhistCalendar(ULocale.getDefault());
        if(cal == null){
            errln("could not create BuddhistCalendar with ULocale");
        }
    }

    {
        // new BuddhistCalendar(TimeZone,ULocale)
        BuddhistCalendar cal = new BuddhistCalendar(TimeZone.getDefault(),ULocale.getDefault());
        if(cal == null){
            errln("could not create BuddhistCalendar with TimeZone ULocale");
        }
    }

    {
        // new BuddhistCalendar(TimeZone)
        BuddhistCalendar cal = new BuddhistCalendar(TimeZone.getDefault());
        if(cal == null){
            errln("could not create BuddhistCalendar with TimeZone");
        }
    }

    {
        // new BuddhistCalendar(Locale)
        BuddhistCalendar cal = new BuddhistCalendar(Locale.getDefault());
        if(cal == null){
            errln("could not create BuddhistCalendar with Locale");
        }
    }

    {
        // new BuddhistCalendar(TimeZone, Locale)
        BuddhistCalendar cal = new BuddhistCalendar(TimeZone.getDefault(), Locale.getDefault());
        if(cal == null){
            errln("could not create BuddhistCalendar with TimeZone and Locale");
        }
    }

    {
        // new BuddhistCalendar(Date)
        BuddhistCalendar cal = new BuddhistCalendar(new Date());
        if(cal == null){
            errln("could not create BuddhistCalendar with Date");
        }
    }

    {
        // new BuddhistCalendar(int year, int month, int date)
        BuddhistCalendar cal = new BuddhistCalendar(2543, Calendar.MAY, 22);
        if(cal == null){
            errln("could not create BuddhistCalendar with year,month,data");
        }
    }

    {
        // new BuddhistCalendar(int year, int month, int date, int hour, int minute, int second)
        BuddhistCalendar cal = new BuddhistCalendar(2543, Calendar.MAY, 22, 1, 1, 1);
        if(cal == null){
            errln("could not create BuddhistCalendar with year,month,date,hour,minute,second");
        }
    }

    {
        // data
        BuddhistCalendar cal = new BuddhistCalendar(2543, Calendar.MAY, 22);
        Date time = cal.getTime();

        String[] calendarLocales = {
        "th_TH"
        };

        String[] formatLocales = {
        "en", "ar", "hu", "th"
        };

        for (int i = 0; i < calendarLocales.length; ++i) {
        String calLocName = calendarLocales[i];
        Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
        cal = new BuddhistCalendar(calLocale);

        for (int j = 0; j < formatLocales.length; ++j) {
            String locName = formatLocales[j];
            Locale formatLocale = LocaleUtility.getLocaleFromName(locName);
            DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale);
            logln(calLocName + "/" + locName + " --> " + format.format(time));
        }
        }
    }
    }

    /**
     * Test limits of the Buddhist calendar.
     */
    @Test
    public void TestBuddhistLimits() {
        // Final parameter is either number of days, if > 0, or test
        // duration in seconds, if < 0.
        Calendar cal = Calendar.getInstance();
        cal.set(2007, Calendar.JANUARY, 1);
        BuddhistCalendar buddhist = new BuddhistCalendar();
        doLimitsTest(buddhist, null, cal.getTime());
        doTheoreticalLimitsTest(buddhist, false);
    }

    /**
     * Default calendar for Thai (Ticket#6302)
     */
    @Test
    public void TestThaiDefault() {
        // Buddhist calendar is used as the default calendar for
        // Thai locale
        Calendar cal = Calendar.getInstance(new ULocale("th_TH"));
        String type = cal.getType();
        // Android patch: Force default Gregorian calendar.
        if (!type.equals("gregorian")) {
            errln("FAIL: Gregorian calendar is not returned for locale " + cal.toString());
        }
        // Android patch end.
    }

    /**
     * Verify that TaiwanCalendar shifts years to Minguo Era but otherwise
     * behaves like GregorianCalendar.
     */
    @Test
    public void TestTaiwan() {
        quasiGregorianTest(new TaiwanCalendar(),
                           new int[] {
                               TaiwanCalendar.BEFORE_MINGUO, 8, 1904, Calendar.FEBRUARY, 29,
                               TaiwanCalendar.MINGUO, 1, 1912, Calendar.JUNE, 4,
                               TaiwanCalendar.MINGUO, 3, 1914, Calendar.FEBRUARY, 12,
                               TaiwanCalendar.MINGUO, 96,2007, Calendar.FEBRUARY, 12,
                           });
    }

    /**
     * Test limits of the Taiwan calendar.
     */
    @Test
    public void TestTaiwanLimits() {
        // Final parameter is either number of days, if > 0, or test
        // duration in seconds, if < 0.
        Calendar cal = Calendar.getInstance();
        cal.set(2007, Calendar.JANUARY, 1);
        TaiwanCalendar taiwan = new TaiwanCalendar();
        doLimitsTest(taiwan, null, cal.getTime());
        doTheoreticalLimitsTest(taiwan, false);
    }

    @Test
    public void TestTaiwanCoverage() {
    {
        // new TaiwanCalendar(ULocale)
        TaiwanCalendar cal = new TaiwanCalendar(ULocale.getDefault());
        if(cal == null){
            errln("could not create TaiwanCalendar with ULocale");
        }
    }

    {
        // new TaiwanCalendar(TimeZone,ULocale)
        TaiwanCalendar cal = new TaiwanCalendar(TimeZone.getDefault(),ULocale.getDefault());
        if(cal == null){
            errln("could not create TaiwanCalendar with TimeZone ULocale");
        }
    }

    {
        // new TaiwanCalendar(TimeZone)
        TaiwanCalendar cal = new TaiwanCalendar(TimeZone.getDefault());
        if(cal == null){
            errln("could not create TaiwanCalendar with TimeZone");
        }
    }

    {
        // new TaiwanCalendar(Locale)
        TaiwanCalendar cal = new TaiwanCalendar(Locale.getDefault());
        if(cal == null){
            errln("could not create TaiwanCalendar with Locale");
        }
    }

    {
        // new TaiwanCalendar(TimeZone, Locale)
        TaiwanCalendar cal = new TaiwanCalendar(TimeZone.getDefault(), Locale.getDefault());
        if(cal == null){
            errln("could not create TaiwanCalendar with TimeZone and Locale");
        }
    }

    {
        // new TaiwanCalendar(Date)
        TaiwanCalendar cal = new TaiwanCalendar(new Date());
        if(cal == null){
            errln("could not create TaiwanCalendar with Date");
        }
    }

    {
        // new TaiwanCalendar(int year, int month, int date)
        TaiwanCalendar cal = new TaiwanCalendar(34, Calendar.MAY, 22);
        if(cal == null){
            errln("could not create TaiwanCalendar with year,month,data");
        }
    }

    {
        // new TaiwanCalendar(int year, int month, int date, int hour, int minute, int second)
        TaiwanCalendar cal = new TaiwanCalendar(34, Calendar.MAY, 22, 1, 1, 1);
        if(cal == null){
            errln("could not create TaiwanCalendar with year,month,date,hour,minute,second");
        }
    }

    {
        // data
        TaiwanCalendar cal = new TaiwanCalendar(34, Calendar.MAY, 22);
        Date time = cal.getTime();

        String[] calendarLocales = {
        "en","zh"
        };

        String[] formatLocales = {
        "en", "ar", "hu", "th"
        };

        for (int i = 0; i < calendarLocales.length; ++i) {
        String calLocName = calendarLocales[i];
        Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
        cal = new TaiwanCalendar(calLocale);

        for (int j = 0; j < formatLocales.length; ++j) {
            String locName = formatLocales[j];
            Locale formatLocale = LocaleUtility.getLocaleFromName(locName);
            DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale);
            logln(calLocName + "/" + locName + " --> " + format.format(time));
        }
        }
    }
    }

    /**
     * Verify that JapaneseCalendar shifts years to Japanese Eras but otherwise
     * behaves like GregorianCalendar.
     */
    @Test
    public void TestJapanese() {
        // First make sure this test works for GregorianCalendar
        int[] control = {
            GregorianCalendar.AD, 1868, 1868, Calendar.SEPTEMBER, 8,
            GregorianCalendar.AD, 1868, 1868, Calendar.SEPTEMBER, 9,
            GregorianCalendar.AD, 1869, 1869, Calendar.JUNE, 4,
            GregorianCalendar.AD, 1912, 1912, Calendar.JULY, 29,
            GregorianCalendar.AD, 1912, 1912, Calendar.JULY, 30,
            GregorianCalendar.AD, 1912, 1912, Calendar.AUGUST, 1,
        };
        quasiGregorianTest(new GregorianCalendar(), control);

        int[] data = {
            JapaneseCalendar.MEIJI, 1, 1868, Calendar.SEPTEMBER, 8,
            JapaneseCalendar.MEIJI, 1, 1868, Calendar.SEPTEMBER, 9,
            JapaneseCalendar.MEIJI, 2, 1869, Calendar.JUNE, 4,
            JapaneseCalendar.MEIJI, 45, 1912, Calendar.JULY, 29,
            JapaneseCalendar.TAISHO, 1, 1912, Calendar.JULY, 30,
            JapaneseCalendar.TAISHO, 1, 1912, Calendar.AUGUST, 1,
        };
        quasiGregorianTest(new JapaneseCalendar(), data);
    }

    /**
     * Test limits of the Gregorian calendar.
     */
    @Test
    public void TestGregorianLimits() {
        // Final parameter is either number of days, if > 0, or test
        // duration in seconds, if < 0.
        Calendar cal = Calendar.getInstance();
        cal.set(2004, Calendar.JANUARY, 1);
        GregorianCalendar gregorian = new GregorianCalendar();
        doLimitsTest(gregorian, null, cal.getTime());
        doTheoreticalLimitsTest(gregorian, false);
    }

    /**
     * Test behavior of fieldDifference around leap years.  Also test a large
     * field difference to check binary search.
     */
    @Test
    public void TestLeapFieldDifference() {
        Calendar cal = Calendar.getInstance();
        cal.set(2004, Calendar.FEBRUARY, 29);
        Date date2004 = cal.getTime();
        cal.set(2000, Calendar.FEBRUARY, 29);
        Date date2000 = cal.getTime();
        int y = cal.fieldDifference(date2004, Calendar.YEAR);
        int d = cal.fieldDifference(date2004, Calendar.DAY_OF_YEAR);
        if (d == 0) {
            logln("Ok: 2004/Feb/29 - 2000/Feb/29 = " + y + " years, " + d + " days");
        } else {
            errln("FAIL: 2004/Feb/29 - 2000/Feb/29 = " + y + " years, " + d + " days");
        }
        cal.setTime(date2004);
        y = cal.fieldDifference(date2000, Calendar.YEAR);
        d = cal.fieldDifference(date2000, Calendar.DAY_OF_YEAR);
        if (d == 0) {
            logln("Ok: 2000/Feb/29 - 2004/Feb/29 = " + y + " years, " + d + " days");
        } else {
            errln("FAIL: 2000/Feb/29 - 2004/Feb/29 = " + y + " years, " + d + " days");
        }
        // Test large difference
        cal.set(2001, Calendar.APRIL, 5); // 2452005
        Date ayl = cal.getTime();
        cal.set(1964, Calendar.SEPTEMBER, 7); // 2438646
        Date asl = cal.getTime();
        d = cal.fieldDifference(ayl, Calendar.DAY_OF_MONTH);
        cal.setTime(ayl);
        int d2 = cal.fieldDifference(asl, Calendar.DAY_OF_MONTH);
        if (d == -d2 && d == 13359) {
            logln("Ok: large field difference symmetrical " + d);
        } else {
            logln("FAIL: large field difference incorrect " + d + ", " + d2 +
                  ", expect +/- 13359");
        }
    }

    /**
     * Test ms_MY "Malay (Malaysia)" locale.  Bug 1543.
     */
    @Test
    public void TestMalaysianInstance() {
        Locale loc = new Locale("ms", "MY");  // Malay (Malaysia)
        Calendar cal = Calendar.getInstance(loc);
        if(cal == null){
            errln("could not create Malaysian instance");
        }
    }

    /**
     * setFirstDayOfWeek and setMinimalDaysInFirstWeek may change the
     * field <=> time mapping, since they affect the interpretation of
     * the WEEK_OF_MONTH or WEEK_OF_YEAR fields.
     */
    @Test
    public void TestWeekShift() {
        Calendar cal = new GregorianCalendar(
                             TimeZone.getTimeZone("America/Los_Angeles"),
                             new Locale("en", "US"));
        cal.setTime(new Date(997257600000L)); // Wed Aug 08 01:00:00 PDT 2001
        // In pass one, change the first day of week so that the weeks
        // shift in August 2001.  In pass two, change the minimal days
        // in the first week so that the weeks shift in August 2001.
        //     August 2001
        // Su Mo Tu We Th Fr Sa
        //           1  2  3  4
        //  5  6  7  8  9 10 11
        // 12 13 14 15 16 17 18
        // 19 20 21 22 23 24 25
        // 26 27 28 29 30 31
        for (int pass=0; pass<2; ++pass) {
            if (pass==0) {
                cal.setFirstDayOfWeek(Calendar.WEDNESDAY);
                cal.setMinimalDaysInFirstWeek(4);
            } else {
                cal.setFirstDayOfWeek(Calendar.SUNDAY);
                cal.setMinimalDaysInFirstWeek(4);
            }
            cal.add(Calendar.DATE, 1); // Force recalc
            cal.add(Calendar.DATE, -1);

            Date time1 = cal.getTime(); // Get time -- should not change

            // Now change a week parameter and then force a recalc.
            // The bug is that the recalc should not be necessary --
            // calendar should do so automatically.
            if (pass==0) {
                cal.setFirstDayOfWeek(Calendar.THURSDAY);
            } else {
                cal.setMinimalDaysInFirstWeek(5);
            }

            int woy1 = cal.get(Calendar.WEEK_OF_YEAR);
            int wom1 = cal.get(Calendar.WEEK_OF_MONTH);

            cal.add(Calendar.DATE, 1); // Force recalc
            cal.add(Calendar.DATE, -1);

            int woy2 = cal.get(Calendar.WEEK_OF_YEAR);
            int wom2 = cal.get(Calendar.WEEK_OF_MONTH);

            Date time2 = cal.getTime();

            if (!time1.equals(time2)) {
                errln("FAIL: shifting week should not alter time");
            } else {
                logln(time1.toString());
            }
            if (woy1 == woy2 && wom1 == wom2) {
                logln("Ok: WEEK_OF_YEAR: " + woy1 +
                      ", WEEK_OF_MONTH: " + wom1);
            } else {
                errln("FAIL: WEEK_OF_YEAR: " + woy1 + " => " + woy2 +
                      ", WEEK_OF_MONTH: " + wom1 + " => " + wom2 +
                      " after week shift");
            }
        }
    }

    /**
     * Make sure that when adding a day, we actually wind up in a
     * different day.  The DST adjustments we use to keep the hour
     * constant across DST changes can backfire and change the day.
     */
    @Test
    public void TestTimeZoneTransitionAdd() {
        Locale locale = Locale.US; // could also be CHINA
        SimpleDateFormat dateFormat =
            new SimpleDateFormat("MM/dd/yyyy HH:mm z", locale);

        String tz[] = TimeZone.getAvailableIDs();

        for (int z=0; z<tz.length; ++z) {
            TimeZone t = TimeZone.getTimeZone(tz[z]);
            dateFormat.setTimeZone(t);

            Calendar cal = Calendar.getInstance(t, locale);
            cal.clear();
            // Scan the year 2003, overlapping the edges of the year
            cal.set(Calendar.YEAR, 2002);
            cal.set(Calendar.MONTH, Calendar.DECEMBER);
            cal.set(Calendar.DAY_OF_MONTH, 25);

            for (int i=0; i<365+10; ++i) {
                Date yesterday = cal.getTime();
                int yesterday_day = cal.get(Calendar.DAY_OF_MONTH);
                cal.add(Calendar.DAY_OF_MONTH, 1);
                if (yesterday_day == cal.get(Calendar.DAY_OF_MONTH)) {
                    errln(tz[z] + " " +
                          dateFormat.format(yesterday) + " +1d= " +
                          dateFormat.format(cal.getTime()));
                }
            }
        }
    }

    @Test
    public void TestJB1684() {
        class TestData {
            int year;
            int month;
            int date;
            int womyear;
            int wommon;
            int wom;
            int dow;
            String data;
            String normalized;

            public TestData(int year, int month, int date,
                            int womyear, int wommon, int wom, int dow,
                            String data, String normalized) {
                this.year = year;
                this.month = month-1;
                this.date = date;
                this.womyear = womyear;
                this.wommon = wommon-1;
                this.wom = wom;
                this.dow = dow;
                this.data = data; // year, month, week of month, day
                this.normalized = data;
                if (normalized != null) this.normalized = normalized;
            }
        }

        //      July 2001            August 2001           January 2002
        // Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
        //  1  2  3  4  5  6  7            1  2  3  4         1  2  3  4  5
        //  8  9 10 11 12 13 14   5  6  7  8  9 10 11   6  7  8  9 10 11 12
        // 15 16 17 18 19 20 21  12 13 14 15 16 17 18  13 14 15 16 17 18 19
        // 22 23 24 25 26 27 28  19 20 21 22 23 24 25  20 21 22 23 24 25 26
        // 29 30 31              26 27 28 29 30 31     27 28 29 30 31
        TestData[] tests = {
            new TestData(2001, 8,  6,  2001,8,2,Calendar.MONDAY,    "2001 08 02 Mon", null),
            new TestData(2001, 8,  7,  2001,8,2,Calendar.TUESDAY,   "2001 08 02 Tue", null),
            new TestData(2001, 8,  5,/*12,*/ 2001,8,2,Calendar.SUNDAY,    "2001 08 02 Sun", null),
            new TestData(2001, 8,6, /*7,  30,*/ 2001,7,6,Calendar.MONDAY,    "2001 07 06 Mon", "2001 08 02 Mon"),
            new TestData(2001, 8,7, /*7,  31,*/ 2001,7,6,Calendar.TUESDAY,   "2001 07 06 Tue", "2001 08 02 Tue"),
            new TestData(2001, 8,  5,  2001,7,6,Calendar.SUNDAY,    "2001 07 06 Sun", "2001 08 02 Sun"),
            new TestData(2001, 7,  30, 2001,8,1,Calendar.MONDAY,    "2001 08 01 Mon", "2001 07 05 Mon"),
            new TestData(2001, 7,  31, 2001,8,1,Calendar.TUESDAY,   "2001 08 01 Tue", "2001 07 05 Tue"),
            new TestData(2001, 7,29, /*8,  5,*/  2001,8,1,Calendar.SUNDAY,    "2001 08 01 Sun", "2001 07 05 Sun"),
            new TestData(2001, 12, 31, 2001,12,6,Calendar.MONDAY,   "2001 12 06 Mon", null),
            new TestData(2002, 1,  1,  2002,1,1,Calendar.TUESDAY,   "2002 01 01 Tue", null),
            new TestData(2002, 1,  2,  2002,1,1,Calendar.WEDNESDAY, "2002 01 01 Wed", null),
            new TestData(2002, 1,  3,  2002,1,1,Calendar.THURSDAY,  "2002 01 01 Thu", null),
            new TestData(2002, 1,  4,  2002,1,1,Calendar.FRIDAY,    "2002 01 01 Fri", null),
            new TestData(2002, 1,  5,  2002,1,1,Calendar.SATURDAY,  "2002 01 01 Sat", null),
            new TestData(2001,12,30, /*2002, 1,  6,*/  2002,1,1,Calendar.SUNDAY,    "2002 01 01 Sun", "2001 12 06 Sun"),
        };

        int pass = 0, error = 0, warning = 0;

        final String pattern = "yyyy MM WW EEE";
        GregorianCalendar cal = new GregorianCalendar();
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        sdf.setCalendar(cal);

        cal.setFirstDayOfWeek(Calendar.SUNDAY);
        cal.setMinimalDaysInFirstWeek(1);

        for (int i = 0; i < tests.length; ++i) {
            TestData test = tests[i];
            log("\n-----\nTesting round trip of " + test.year +
                  " " + (test.month + 1) +
                  " " + test.date +
                  " (written as) " + test.data);

            cal.clear();
            cal.set(test.year, test.month, test.date);
            Date ms = cal.getTime();

            cal.clear();
            cal.set(Calendar.YEAR, test.womyear);
            cal.set(Calendar.MONTH, test.wommon);
            cal.set(Calendar.WEEK_OF_MONTH, test.wom);
            cal.set(Calendar.DAY_OF_WEEK, test.dow);
            Date ms2 = cal.getTime();

            if (!ms2.equals(ms)) {
                log("\nError: GregorianCalendar.DOM gave " + ms +
                    "\n       GregorianCalendar.WOM gave " + ms2);
                error++;
            } else {
                pass++;
            }

            ms2 = null;
            try {
                ms2 = sdf.parse(test.data);
            }
            catch (ParseException e) {
                errln("parse exception: " + e);
            }

            if (!ms2.equals(ms)) {
                log("\nError: GregorianCalendar gave      " + ms +
                    "\n       SimpleDateFormat.parse gave " + ms2);
                error++;
            } else {
                pass++;
            }

            String result = sdf.format(ms);
            if (!result.equals(test.normalized)) {
                log("\nWarning: format of '" + test.data + "' gave" +
                    "\n                   '" + result + "'" +
                    "\n          expected '" + test.normalized + "'");
                warning++;
            } else {
                pass++;
            }

            Date ms3 = null;
            try {
                ms3 = sdf.parse(result);
            }
            catch (ParseException e) {
                errln("parse exception 2: " + e);
            }

            if (!ms3.equals(ms)) {
                error++;
                log("\nError: Re-parse of '" + result + "' gave time of " +
                    "\n        " + ms3 +
                    "\n    not " + ms);
            } else {
                pass++;
            }
        }
        String info = "\nPassed: " + pass + ", Warnings: " + warning + ", Errors: " + error;
        if (error > 0) {
            errln(info);
        } else {
            logln(info);
        }
    }

    /**
     * Test the ZoneMeta API.
     */
    @Test
    public void TestZoneMeta() {
        // Test index by country API

        // Format: {country, zone1, zone2, ..., zoneN}
        String COUNTRY[][] = { {""},
                               {"US", "America/Los_Angeles", "PST"} };
        StringBuffer buf = new StringBuffer();
        for (int i=0; i<COUNTRY.length; ++i) {
            Set<String> a = ZoneMeta.getAvailableIDs(SystemTimeZoneType.ANY, COUNTRY[i][0], null);
            buf.setLength(0);
            buf.append("Country \"" + COUNTRY[i][0] + "\": [");
            // Use bitmask to track which of the expected zones we see
            int mask = 0;
            boolean first = true;
            for (String z : a) {
                if (first) {
                    first = false;
                } else {
                    buf.append(", ");
                }
                buf.append(z);
                for (int k = 1; k < COUNTRY[i].length; ++k) {
                    if ((mask & (1 << k)) == 0 && z.equals(COUNTRY[i][k])) {
                        mask |= (1 << k);
                    }
                }
            }
            buf.append("]");
            mask >>= 1;
            // Check bitmask to see if we saw all expected zones
            if (mask == (1 << (COUNTRY[i].length-1))-1) {
                logln(buf.toString());
            } else {
                errln(buf.toString());
            }
        }

        // Test equivalent IDs API

        int n = ZoneMeta.countEquivalentIDs("PST");
        boolean ok = false;
        buf.setLength(0);
        buf.append("Equivalent to PST: ");
        for (int i=0; i<n; ++i) {
            String id = ZoneMeta.getEquivalentID("PST", i);
            if (id.equals("America/Los_Angeles")) {
                ok = true;
            }
            if (i!=0) buf.append(", ");
            buf.append(id);
        }
        if (ok) {
            logln(buf.toString());
        } else {
            errln(buf.toString());
        }
    }

    @Test
    public void TestComparable() {
    GregorianCalendar c0 = new GregorianCalendar();
    GregorianCalendar c1 = new GregorianCalendar();
    c1.add(Calendar.DAY_OF_MONTH, 1);
    if (c0.compareTo(c1) >= 0) {
        errln("calendar " + c0 + " not < " + c1);
    }
    c0.add(Calendar.MONTH, 1);
    if (c0.compareTo(c1) <= 0) {
        errln("calendar " + c0 + " not > " + c1);
    }

    c0.setTimeInMillis(c1.getTimeInMillis());
    if (c0.compareTo(c1) != 0) {
        errln("calendar " + c0 + " not == " + c1);
    }

    }

    /**
     * Miscellaneous tests to increase coverage.
     */
    @Test
    public void TestCoverage() {
        // BuddhistCalendar
        BuddhistCalendar bcal = new BuddhistCalendar();
        /*int i =*/ bcal.getMinimum(Calendar.ERA);
        bcal.add(Calendar.YEAR, 1);
        bcal.add(Calendar.MONTH, 1);
        /*Date d = */bcal.getTime();

        // CalendarAstronomer
        // (This class should probably be made package-private.)
        CalendarAstronomer astro = new CalendarAstronomer();
        /*String s = */astro.local(0);

        // ChineseCalendar
        ChineseCalendar ccal = new ChineseCalendar(TimeZone.getDefault(),
                                                   Locale.getDefault());
        ccal.add(Calendar.MONTH, 1);
        ccal.add(Calendar.YEAR, 1);
        ccal.roll(Calendar.MONTH, 1);
        ccal.roll(Calendar.YEAR, 1);
        ccal.getTime();

        // ICU 2.6
        Calendar cal = Calendar.getInstance(Locale.US);
        logln(cal.toString());
        logln(cal.getDisplayName(Locale.US));
        int weekendOnset=-1;
        int weekendCease=-1;
        for (int i=Calendar.SUNDAY; i<=Calendar.SATURDAY; ++i) {
            if (cal.getDayOfWeekType(i) == Calendar.WEEKEND_ONSET) {
                weekendOnset = i;
            }
            if (cal.getDayOfWeekType(i) == Calendar.WEEKEND_CEASE) {
                weekendCease = i;
            }
        }
        // can't call this unless we get a transition day (unusual),
        // but make the call anyway for coverage reasons
        try {
            /*int x=*/ cal.getWeekendTransition(weekendOnset);
            /*int x=*/ cal.getWeekendTransition(weekendCease);
        } catch (IllegalArgumentException e) {}
        /*int x=*/ cal.isWeekend(new Date());

        // new GregorianCalendar(ULocale)
        GregorianCalendar gcal = new GregorianCalendar(ULocale.getDefault());
        if(gcal==null){
            errln("could not create GregorianCalendar with ULocale");
        } else {
            logln("Calendar display name: " + gcal.getDisplayName(ULocale.getDefault()));
        }

        //cover getAvailableULocales
        final ULocale[] locales = Calendar.getAvailableULocales();
        long count = locales.length;
        if (count == 0)
            errln("getAvailableULocales return empty list");
        logln("" + count + " available ulocales in Calendar.");

        // Jitterbug 4451, for coverage
        class StubCalendar extends Calendar{
            /**
             * For serialization
             */
            private static final long serialVersionUID = -4558903444622684759L;

            @Override
            protected int handleGetLimit(int field, int limitType) {
                if (limitType == Calendar.LEAST_MAXIMUM) {
                    return 1;
                } else if (limitType == Calendar.GREATEST_MINIMUM) {
                    return 7;
                }
               return -1;
            }
            @Override
            protected int handleComputeMonthStart(int eyear, int month, boolean useMonth) {
                if (useMonth) {
                    return eyear * 365 + month * 31;
                } else {
                    return eyear * 365;
                }
            }
            @Override
            protected int handleGetExtendedYear() {return 2017;}

            public void run(){
                if (Calendar.gregorianPreviousMonthLength(2000,2) != 29){
                    errln("Year 2000 Feb should have 29 days.");
                }
                long millis = Calendar.julianDayToMillis(Calendar.MAX_JULIAN);
                if(millis != Calendar.MAX_MILLIS){
                    errln("Did not get the expected value from julianDayToMillis. Got:" + millis);
                }
                DateFormat df = handleGetDateFormat("",Locale.getDefault());
                if (!df.equals(handleGetDateFormat("",ULocale.getDefault()))){
                    errln ("Calendar.handleGetDateFormat(String, Locale) should delegate to ( ,ULocale)");
                }
                if (!getType().equals("unknown")){
                    errln ("Calendar.getType() should be 'unknown'");
                }

                // Tests for complete coverage of Calendar functions.
                int julianDay = Calendar.millisToJulianDay(millis - 1);
                assertEquals("Julian max day -1", julianDay, Calendar.MAX_JULIAN - 1);

                DateFormat df1 = handleGetDateFormat("GG yyyy-d:MM", "option=xyz", Locale.getDefault());
                if (!df1.equals(handleGetDateFormat("GG yyyy-d:MM", "option=xyz", ULocale.getDefault()))){
                    errln ("Calendar.handleGetDateFormat(String, Locale) should delegate to ( ,ULocale)");
                }

                // Prove that the local overrides are used.
                int leastMsInDay = handleGetLimit(Calendar.MILLISECONDS_IN_DAY, Calendar.LEAST_MAXIMUM);
                assertEquals("getLimit test 1", leastMsInDay, 1);
                int maxMsInDay = handleGetLimit(Calendar.WEEK_OF_MONTH, Calendar.GREATEST_MINIMUM);
                assertEquals("getLimit test 2", 7, maxMsInDay);

                int febLeapLength = handleGetMonthLength(2020, Calendar.FEBRUARY);
                assertEquals("handleMonthLength", 31, febLeapLength);
                int exYear = handleGetExtendedYear();
                assertEquals("handleGetExtendeYear", exYear, 2017);
                int monthStart = handleComputeMonthStart(2016, 4, false);
                assertEquals("handleComputeMonthStart false", 735840, monthStart);
                monthStart = handleComputeMonthStart(2016, 4, true);
                assertEquals("handleComputeMonthStart true", 735964, monthStart);

                Calendar cal = Calendar.getInstance();
                cal.set(1980, 5, 2);
                this.setTime(cal.getTime());
                assertEquals("handleComputeFields: year set", 1980, get(YEAR));
                assertEquals("handleComputeFields: month set", 5, get(MONTH));
                assertEquals("handleComputeFields: day set", 2, get(DAY_OF_MONTH));
            }
        }
        StubCalendar stub = new StubCalendar();
        stub.run();
    }

    // Tests for jb 4541
    @Test
    public void TestJB4541() {
        ULocale loc = new ULocale("en_US");

        // !!! Shouldn't we have an api like this?
        // !!! Question: should this reflect those actually available in this copy of ICU, or
        // the list of types we assume is available?
        // String[] calTypes = Calendar.getAvailableTypes();
        final String[] calTypes = {
            "buddhist", "chinese", "coptic", "ethiopic", "gregorian", "hebrew",
            "islamic", "islamic-civil", "japanese", "roc"
        };

        // constructing a DateFormat with a locale indicating a calendar type should construct a
        // date format appropriate to that calendar
        final Date time = new Date();
        for (int i = 0; i < calTypes.length; ++i) {
            ULocale aLoc = loc.setKeywordValue("calendar", calTypes[i]);
            logln("locale: " + aLoc);

            DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,
                                                           DateFormat.FULL,
                                                           aLoc);

            logln("df type: " + df.getClass().getName() + " loc: " + df.getLocale(ULocale.VALID_LOCALE));

            Calendar cal = df.getCalendar();
            assertEquals("calendar types", cal.getType(), calTypes[i]);
            DateFormat df2 = cal.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, ULocale.US);
            logln("df2 type: " + df2.getClass().getName() + " loc: " + df2.getLocale(ULocale.VALID_LOCALE));
            assertEquals("format results", df.format(time), df2.format(time));
        }

        // dateFormat.setCalendar should throw exception if wrong format for calendar
        if (false) {
            DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,
                                                           DateFormat.FULL,
                                                           new ULocale("en_US@calendar=chinese"));

            logln("dateformat type: " + df.getClass().getName());

            Calendar cal = Calendar.getInstance(new ULocale("en_US@calendar=chinese"));

            logln("calendar type: " + cal.getClass().getName());
        }
    }

    @Test
    public void TestTypes() {
        String[] locs = {
                "en_US_VALLEYGIRL",
                "en_US_VALLEYGIRL@collation=phonebook;calendar=japanese",
                "en_US_VALLEYGIRL@collation=phonebook;calendar=gregorian",
                "ja_JP@calendar=japanese",
                "th_TH@calendar=buddhist",
                "th-TH-u-ca-gregory",
                "ja_JP_TRADITIONAL",
                "th_TH_TRADITIONAL",
                "th_TH_TRADITIONAL@calendar=gregorian",
                "en_US",
                "th_TH",    // Default calendar for th_TH is buddhist
                "th",       // th's default region is TH and buddhist is used as default for TH
                "en_TH",    // Default calendar for any locales with region TH is buddhist
                "th_TH@calendar=iso8601",   // iso8601 calendar type
                "fr_CH",
                "fr_SA",
                "fr_CH@rg=sazzzz",
                "fr_CH@calendar=japanese;rg=sazzzz",
                "fr_TH@rg=SA",  // ignore malformed rg tag, use buddhist
                "th@rg=SA",		// ignore malformed rg tag, use buddhist
        };

        // Android patch: Force default Gregorian calendar.
        String[] types = {
                "gregorian",
                "japanese",
                "gregorian",
                "japanese",
                "buddhist",
                "gregorian",
                "japanese",
                "buddhist",
                "gregorian",
                "gregorian",
                "gregorian",
                "gregorian",
                "gregorian",
                "gregorian",    // iso8601 is a gregorian sub type
                "gregorian",
                "gregorian",
                "gregorian",
                "japanese",
                "gregorian",
                "gregorian",
        };
        // Android patch end.

        for (int i = 0; i < locs.length; i++) {
            Calendar cal = Calendar.getInstance(new ULocale(locs[i]));
            if (!cal.getType().equals(types[i])) {
                errln(locs[i] + " Calendar type " + cal.getType() + " instead of " + types[i]);
            }
        }
    }

    @Test
    public void TestISO8601() {
        final ULocale[] TEST_LOCALES = {
            new ULocale("en_US@calendar=iso8601"),
            new ULocale("en_US@calendar=Iso8601"),
            new ULocale("th_TH@calendar=iso8601"),
            new ULocale("ar_EG@calendar=iso8601")
        };

        final int[][] TEST_DATA = {
            // {<year>, <week# of Jan 1>, <week# year of Jan 1>}
            {2008, 1, 2008},
            {2009, 1, 2009},
            {2010, 53, 2009},
            {2011, 52, 2010},
            {2012, 52, 2011},
            {2013, 1, 2013},
            {2014, 1, 2014},
        };

        for (ULocale locale : TEST_LOCALES) {
            Calendar cal = Calendar.getInstance(locale);
            // No matter what locale is used, if calendar type is "iso8601",
            // calendar type must be Gregorian
            if (!cal.getType().equals("gregorian")) {
                errln("Error: Gregorian calendar is not used for locale: " + locale);
            }

            for (int[] data : TEST_DATA) {
                cal.set(data[0], Calendar.JANUARY, 1);
                int weekNum = cal.get(Calendar.WEEK_OF_YEAR);
                int weekYear = cal.get(Calendar.YEAR_WOY);

                if (weekNum != data[1] || weekYear != data[2]) {
                    errln("Error: Incorrect week of year on January 1st, " + data[0]
                            + " for locale " + locale
                            + ": Returned [weekNum=" + weekNum + ", weekYear=" + weekYear
                            + "], Expected [weekNum=" + data[1] + ", weekYear=" + data[2] + "]");
                }
            }
        }
    }

    private static class CalFields {
        private int year;
        private int month;
        private int day;
        private int hour;
        private int min;
        private int sec;
        private int ms;

        CalFields(int year, int month, int day, int hour, int min, int sec) {
            this(year, month, day, hour, min, sec, 0);
        }

        CalFields(int year, int month, int day, int hour, int min, int sec, int ms) {
            this.year = year;
            this.month = month;
            this.day = day;
            this.hour = hour;
            this.min = min;
            this.sec = sec;
            this.ms = ms;
        }

        void setTo(Calendar cal) {
            cal.clear();
            cal.set(year,  month - 1, day, hour, min, sec);
            cal.set(Calendar.MILLISECOND, ms);
        }

        @Override
        public String toString() {
            return String.format("%04d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour, min, sec, ms);
        }

        @Override
        public boolean equals(Object other) {
            if (other instanceof CalFields) {
                CalFields otr = (CalFields)other;
                return (year == otr.year
                        && month == otr.month
                        && day == otr.day
                        && hour == otr.hour
                        && min == otr.min
                        && sec == otr.sec
                        && ms == otr.ms);
            }
            return false;
        }

        boolean isEquivalentTo(Calendar cal) {
            return year == cal.get(Calendar.YEAR)
                    && month == cal.get(Calendar.MONTH) + 1
                    && day == cal.get(Calendar.DAY_OF_MONTH)
                    && hour == cal.get(Calendar.HOUR_OF_DAY)
                    && min == cal.get(Calendar.MINUTE)
                    && sec == cal.get(Calendar.SECOND)
                    && ms == cal.get(Calendar.MILLISECOND);
        }

        static CalFields createFrom(Calendar cal) {
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH) + 1;
            int day = cal.get(Calendar.DAY_OF_MONTH);
            int hour = cal.get(Calendar.HOUR_OF_DAY);
            int min = cal.get(Calendar.MINUTE);
            int sec = cal.get(Calendar.SECOND);

            return new CalFields(year, month, day, hour, min, sec);
        }
    }

    @Test
    public void TestAmbiguousWallTimeAPIs() {
        Calendar cal = Calendar.getInstance();

        assertEquals("Default repeated wall time option", cal.getRepeatedWallTimeOption(), Calendar.WALLTIME_LAST);
        assertEquals("Default skipped wall time option", cal.getSkippedWallTimeOption(), Calendar.WALLTIME_LAST);

        Calendar cal2 = (Calendar)cal.clone();

        assertTrue("Equality", cal2.equals(cal));
        assertTrue("Hash code", cal.hashCode() == cal2.hashCode());

        cal2.setRepeatedWallTimeOption(Calendar.WALLTIME_FIRST);
        cal2.setSkippedWallTimeOption(Calendar.WALLTIME_FIRST);

        assertFalse("Equality after mod", cal2.equals(cal));
        assertFalse("Hash code after mod", cal.hashCode() == cal2.hashCode());

        assertEquals("getRepeatedWallTimeOption after mod", cal2.getRepeatedWallTimeOption(), Calendar.WALLTIME_FIRST);
        assertEquals("getSkippedWallTimeOption after mod", cal2.getSkippedWallTimeOption(), Calendar.WALLTIME_FIRST);

        try {
            cal.setRepeatedWallTimeOption(Calendar.WALLTIME_NEXT_VALID);
            errln("IAE expected on setRepeatedWallTimeOption(WALLTIME_NEXT_VALID");
        } catch (IllegalArgumentException e) {
            // expected
        }
    }

    @Test
    public void TestRepeatedWallTime() {
        final Object[][] TESTDATA = {
            // Time zone            Input wall time                     WALLTIME_LAST in GMT                WALLTIME_FIRST in GMT
            {"America/New_York",    new CalFields(2011,11,6,0,59,59),   new CalFields(2011,11,6,4,59,59),   new CalFields(2011,11,6,4,59,59)},
            {"America/New_York",    new CalFields(2011,11,6,1,0,0),     new CalFields(2011,11,6,6,0,0),     new CalFields(2011,11,6,5,0,0)},
            {"America/New_York",    new CalFields(2011,11,6,1,0,1),     new CalFields(2011,11,6,6,0,1),     new CalFields(2011,11,6,5,0,1)},
            {"America/New_York",    new CalFields(2011,11,6,1,30,0),    new CalFields(2011,11,6,6,30,0),    new CalFields(2011,11,6,5,30,0)},
            {"America/New_York",    new CalFields(2011,11,6,1,59,59),   new CalFields(2011,11,6,6,59,59),   new CalFields(2011,11,6,5,59,59)},
            {"America/New_York",    new CalFields(2011,11,6,2,0,0),     new CalFields(2011,11,6,7,0,0),     new CalFields(2011,11,6,7,0,0)},
            {"America/New_York",    new CalFields(2011,11,6,2,0,1),     new CalFields(2011,11,6,7,0,1),     new CalFields(2011,11,6,7,0,1)},

            {"Australia/Lord_Howe", new CalFields(2011,4,3,1,29,59),    new CalFields(2011,4,2,14,29,59),   new CalFields(2011,4,2,14,29,59)},
            {"Australia/Lord_Howe", new CalFields(2011,4,3,1,30,0),     new CalFields(2011,4,2,15,0,0),     new CalFields(2011,4,2,14,30,0)},
            {"Australia/Lord_Howe", new CalFields(2011,4,3,1,45,0),     new CalFields(2011,4,2,15,15,0),    new CalFields(2011,4,2,14,45,0)},
            {"Australia/Lord_Howe", new CalFields(2011,4,3,1,59,59),    new CalFields(2011,4,2,15,29,59),   new CalFields(2011,4,2,14,59,59)},
            {"Australia/Lord_Howe", new CalFields(2011,4,3,2,0,0),      new CalFields(2011,4,2,15,30,0),    new CalFields(2011,4,2,15,30,0)},
            {"Australia/Lord_Howe", new CalFields(2011,4,3,2,0,1),      new CalFields(2011,4,2,15,30,1),    new CalFields(2011,4,2,15,30,1)},
        };

        Calendar calGMT = Calendar.getInstance(TimeZone.GMT_ZONE);

        Calendar calDefault = Calendar.getInstance();
        Calendar calLast = Calendar.getInstance();
        Calendar calFirst = Calendar.getInstance();

        calFirst.setRepeatedWallTimeOption(Calendar.WALLTIME_FIRST);
        calLast.setRepeatedWallTimeOption(Calendar.WALLTIME_LAST);

        for (Object[] test : TESTDATA) {
            String tzid = (String)test[0];
            TimeZone tz = TimeZone.getTimeZone(tzid);
            CalFields in = (CalFields)test[1];
            CalFields expLastGMT = (CalFields)test[2];
            CalFields expFirstGMT = (CalFields)test[3];

            // WALLTIME_LAST
            calLast.setTimeZone(tz);
            in.setTo(calLast);
            calGMT.setTimeInMillis(calLast.getTimeInMillis());
            CalFields outLastGMT = CalFields.createFrom(calGMT);
            if (!outLastGMT.equals(expLastGMT)) {
                errln("Fail: WALLTIME_LAST " + in + "[" + tzid + "] is parsed as " + outLastGMT + "[GMT]. Expected: " + expLastGMT + "[GMT]");
            }

            // default
            calDefault.setTimeZone(tz);
            in.setTo(calDefault);
            calGMT.setTimeInMillis(calDefault.getTimeInMillis());
            CalFields outDefGMT = CalFields.createFrom(calGMT);
            if (!outDefGMT.equals(expLastGMT)) {
                errln("Fail: (default) " + in + "[" + tzid + "] is parsed as " + outDefGMT + "[GMT]. Expected: " + expLastGMT + "[GMT]");
            }

            // WALLTIME_FIRST
            calFirst.setTimeZone(tz);
            in.setTo(calFirst);
            calGMT.setTimeInMillis(calFirst.getTimeInMillis());
            CalFields outFirstGMT = CalFields.createFrom(calGMT);
            if (!outFirstGMT.equals(expFirstGMT)) {
                errln("Fail: WALLTIME_FIRST " + in + "[" + tzid + "] is parsed as " + outFirstGMT + "[GMT]. Expected: " + expFirstGMT + "[GMT]");
            }
        }
    }

    @Test
    public void TestSkippedWallTime() {
        final Object[][] TESTDATA = {
            // Time zone            Input wall time                     Valid wall time?
            {"America/New_York",    new CalFields(2011,3,13,1,59,59),   true,
                //  WALLTIME_LAST in GMT                WALLTIME_FIRST in GMT           WALLTIME_NEXT_VALID in GMT
                new CalFields(2011,3,13,6,59,59),   new CalFields(2011,3,13,6,59,59),   new CalFields(2011,3,13,6,59,59)},

            {"America/New_York",    new CalFields(2011,3,13,2,0,0),     false,
                new CalFields(2011,3,13,7,0,0),     new CalFields(2011,3,13,6,0,0),     new CalFields(2011,3,13,7,0,0)},

            {"America/New_York",    new CalFields(2011,3,13,2,1,0),     false,
                new CalFields(2011,3,13,7,1,0),     new CalFields(2011,3,13,6,1,0),     new CalFields(2011,3,13,7,0,0)},

            {"America/New_York",    new CalFields(2011,3,13,2,30,0),    false,
                new CalFields(2011,3,13,7,30,0),    new CalFields(2011,3,13,6,30,0),    new CalFields(2011,3,13,7,0,0)},

            {"America/New_York",    new CalFields(2011,3,13,2,59,59),   false,
                new CalFields(2011,3,13,7,59,59),   new CalFields(2011,3,13,6,59,59),   new CalFields(2011,3,13,7,0,0)},

            {"America/New_York",    new CalFields(2011,3,13,3,0,0),     true,
                new CalFields(2011,3,13,7,0,0),     new CalFields(2011,3,13,7,0,0),     new CalFields(2011,3,13,7,0,0)},

            {"Pacific/Apia",        new CalFields(2011,12,29,23,59,59), true,
                new CalFields(2011,12,30,9,59,59),  new CalFields(2011,12,30,9,59,59),  new CalFields(2011,12,30,9,59,59)},

            {"Pacific/Apia",        new CalFields(2011,12,30,0,0,0),    false,
                new CalFields(2011,12,30,10,0,0),  new CalFields(2011,12,29,10,0,0),  new CalFields(2011,12,30,10,0,0)},

            {"Pacific/Apia",        new CalFields(2011,12,30,12,0,0),   false,
                new CalFields(2011,12,30,22,0,0),  new CalFields(2011,12,29,22,0,0),  new CalFields(2011,12,30,10,0,0)},

            {"Pacific/Apia",        new CalFields(2011,12,30,23,59,59), false,
                new CalFields(2011,12,31,9,59,59), new CalFields(2011,12,30,9,59,59), new CalFields(2011,12,30,10,0,0)},

            {"Pacific/Apia",        new CalFields(2011,12,31,0,0,0),    true,
                new CalFields(2011,12,30,10,0,0),  new CalFields(2011,12,30,10,0,0),  new CalFields(2011,12,30,10,0,0)},
        };

        Calendar calGMT = Calendar.getInstance(TimeZone.GMT_ZONE);

        Calendar calDefault = Calendar.getInstance();
        Calendar calLast = Calendar.getInstance();
        Calendar calFirst = Calendar.getInstance();
        Calendar calNextAvail = Calendar.getInstance();

        calLast.setSkippedWallTimeOption(Calendar.WALLTIME_LAST);
        calFirst.setSkippedWallTimeOption(Calendar.WALLTIME_FIRST);
        calNextAvail.setSkippedWallTimeOption(Calendar.WALLTIME_NEXT_VALID);

        for (Object[] test : TESTDATA) {
            String tzid = (String)test[0];
            TimeZone tz = TimeZone.getTimeZone(tzid);
            CalFields in = (CalFields)test[1];
            boolean isValid = (Boolean)test[2];
            CalFields expLastGMT = (CalFields)test[3];
            CalFields expFirstGMT = (CalFields)test[4];
            CalFields expNextAvailGMT = (CalFields)test[5];

            for (int i = 0; i < 2; i++) {
                boolean bLenient = (i == 0);

                // WALLTIME_LAST
                calLast.setLenient(bLenient);
                calLast.setTimeZone(tz);
                try {
                    in.setTo(calLast);
                    calGMT.setTimeInMillis(calLast.getTimeInMillis());
                    CalFields outLastGMT = CalFields.createFrom(calGMT);
                    if (!bLenient && !isValid) {
                        errln("Fail: IllegalArgumentException expected - " + in + "[" + tzid + "] (WALLTIME_LAST)");
                    } else if (!outLastGMT.equals(expLastGMT)) {
                        errln("Fail: WALLTIME_LAST " + in + "[" + tzid + "] is parsed as " + outLastGMT + "[GMT]. Expected: " + expLastGMT + "[GMT]");
                    }
                } catch (IllegalArgumentException e) {
                    if (bLenient || isValid) {
                        errln("Fail: Unexpected IllegalArgumentException - " + in + "[" + tzid + "] (WALLTIME_LAST)");
                    }
                }

                // default
                calDefault.setLenient(bLenient);
                calDefault.setTimeZone(tz);
                try {
                    in.setTo(calDefault);
                    calGMT.setTimeInMillis(calDefault.getTimeInMillis());
                    CalFields outDefGMT = CalFields.createFrom(calGMT);
                    if (!bLenient && !isValid) {
                        errln("Fail: IllegalArgumentException expected - " + in + "[" + tzid + "] (default)");
                    } else if (!outDefGMT.equals(expLastGMT)) {
                        errln("Fail: (default) " + in + "[" + tzid + "] is parsed as " + outDefGMT + "[GMT]. Expected: " + expLastGMT + "[GMT]");
                    }
                } catch (IllegalArgumentException e) {
                    if (bLenient || isValid) {
                        errln("Fail: Unexpected IllegalArgumentException - " + in + "[" + tzid + "] (default)");
                    }
                }

                // WALLTIME_FIRST
                calFirst.setLenient(bLenient);
                calFirst.setTimeZone(tz);
                try {
                    in.setTo(calFirst);
                    calGMT.setTimeInMillis(calFirst.getTimeInMillis());
                    CalFields outFirstGMT = CalFields.createFrom(calGMT);
                    if (!bLenient && !isValid) {
                        errln("Fail: IllegalArgumentException expected - " + in + "[" + tzid + "] (WALLTIME_FIRST)");
                    } else if (!outFirstGMT.equals(expFirstGMT)) {
                        errln("Fail: WALLTIME_FIRST " + in + "[" + tzid + "] is parsed as " + outFirstGMT + "[GMT]. Expected: " + expFirstGMT + "[GMT]");
                    }
                } catch (IllegalArgumentException e) {
                    if (bLenient || isValid) {
                        errln("Fail: Unexpected IllegalArgumentException - " + in + "[" + tzid + "] (WALLTIME_FIRST)");
                    }
                }

                // WALLTIME_NEXT_VALID
                calNextAvail.setLenient(bLenient);
                calNextAvail.setTimeZone(tz);
                try {
                    in.setTo(calNextAvail);
                    calGMT.setTimeInMillis(calNextAvail.getTimeInMillis());
                    CalFields outNextAvailGMT = CalFields.createFrom(calGMT);
                    if (!bLenient && !isValid) {
                        errln("Fail: IllegalArgumentException expected - " + in + "[" + tzid + "] (WALLTIME_NEXT_VALID)");
                    } else if (!outNextAvailGMT.equals(expNextAvailGMT)) {
                        errln("Fail: WALLTIME_NEXT_VALID " + in + "[" + tzid + "] is parsed as " + outNextAvailGMT + "[GMT]. Expected: " + expNextAvailGMT + "[GMT]");
                    }
                } catch (IllegalArgumentException e) {
                    if (bLenient || isValid) {
                        errln("Fail: Unexpected IllegalArgumentException - " + in + "[" + tzid + "] (WALLTIME_NEXT_VALID)");
                    }
                }
            }
        }
    }

    @Test
    public void TestFieldDifference() {
        class TFDItem {
            public String tzname;
            public String locale;
            public long start;
            public long target;
            public boolean progressive; // true to compute progressive difference for each field, false to reset calendar after each call
            int yDiff;
            int MDiff;
            int dDiff;
            int HDiff;
            int mDiff;
            int sDiff; // 0x7FFFFFFF indicates overflow error expected
             // Simple constructor
            public TFDItem(String tz, String loc, long st, long tg, boolean prg, int yD, int MD, int dD, int HD, int mD, int sD ) {
                tzname = tz;
                locale = loc;
                start = st;
                target = tg;
                progressive = prg;
                yDiff = yD;
                MDiff = MD;
                dDiff = dD;
                HDiff = HD;
                mDiff = mD;
                sDiff = sD;
            }
        };
        final TFDItem[] tfdItems = {
            //           timezobe      locale        start            target            prog   yDf  MDf    dDf     HDf       mDf         sDf
            // For these we compute the progressive difference for each field - not resetting the calendar after each call
            new TFDItem( "US/Pacific", "en_US",        1267459800000L,  1277772600000L, true,    0,   3,    27,      9,       40,          0 ), // 2010-Mar-01 08:10 -> 2010-Jun-28 17:50
            new TFDItem( "US/Pacific", "en_US",        1267459800000L,  1299089280000L, true,    1,   0,     1,      1,       58,          0 ), // 2010-Mar-01 08:10 -> 2011-Mar-02 10:08
            // For these we compute the total difference for each field - resetting the calendar after each call
            new TFDItem( "GMT",        "en_US",        0,               1073692800000L, false,  34, 408, 12427, 298248, 17894880, 1073692800 ), // 1970-Jan-01 00:00 -> 2004-Jan-10 00:00
            new TFDItem( "GMT",        "en_US",        0,               1073779200000L, false,  34, 408, 12428, 298272, 17896320, 1073779200 ), // 1970-Jan-01 00:00 -> 2004-Jan-11 00:00
            new TFDItem( "GMT",        "en_US",        0,               2147472000000L, false,  68, 816, 24855, 596520, 35791200, 2147472000 ), // 1970-Jan-01 00:00 -> 2038-Jan-19 00:00
//          new TFDItem( "GMT",        "en_US",        0,               2147558400000L, false,  68, 816, 24856, 596544, 35792640, 0x7FFFFFFF ), // 1970-Jan-01 00:00 -> 2038-Jan-20 00:00, seconds overflow => exception in ICU4J
            new TFDItem( "GMT",        "en_US",        0,              -1073692800000L, false, -34,-408,-12427,-298248,-17894880,-1073692800 ), // 1970-Jan-01 00:00 -> 1935-Dec-24 00:00
            new TFDItem( "GMT",        "en_US",        0,              -1073779200000L, false, -34,-408,-12428,-298272,-17896320,-1073779200 ), // 1970-Jan-01 00:00 -> 1935-Dec-23 00:00
            // check fwd/backward on either side of era boundary and across era boundary
            new TFDItem( "GMT",        "en_US",      -61978089600000L,-61820409600000L, false,   4,  59,  1825,  43800,  2628000,  157680000 ), // CE   5-Dec-31 00:00 -> CE  10-Dec-30 00:00
            new TFDItem( "GMT",        "en_US",      -61820409600000L,-61978089600000L, false,  -4, -59, -1825, -43800, -2628000, -157680000 ), // CE  10-Dec-30 00:00 -> CE   5-Dec-31 00:00
            new TFDItem( "GMT",        "en_US",      -62451129600000L,-62293449600000L, false,   4,  59,  1825,  43800,  2628000,  157680000 ), // BCE 10-Jan-04 00:00 -> BCE  5-Jan-03 00:00
            new TFDItem( "GMT",        "en_US",      -62293449600000L,-62451129600000L, false,  -4, -59, -1825, -43800, -2628000, -157680000 ), // BCE  5-Jan-03 00:00 -> BCE 10-Jan-04 00:00
            new TFDItem( "GMT",        "en_US",      -62293449600000L,-61978089600000L, false,   9, 119,  3650,  87600,  5256000,  315360000 ), // BCE  5-Jan-03 00:00 -> CE   5-Dec-31 00:00
            new TFDItem( "GMT",        "en_US",      -61978089600000L,-62293449600000L, false,  -9,-119, -3650, -87600, -5256000, -315360000 ), // CE   5-Dec-31 00:00 -> BCE  5-Jan-03 00:00
            new TFDItem( "GMT", "en@calendar=roc",    -1672704000000L, -1515024000000L, false,   4,  59,  1825,  43800,  2628000,  157680000 ), // MG   5-Dec-30 00:00 -> MG  10-Dec-29 00:00
            new TFDItem( "GMT", "en@calendar=roc",    -1515024000000L, -1672704000000L, false,  -4, -59, -1825, -43800, -2628000, -157680000 ), // MG  10-Dec-29 00:00 -> MG   5-Dec-30 00:00
            new TFDItem( "GMT", "en@calendar=roc",    -2145744000000L, -1988064000000L, false,   4,  59,  1825,  43800,  2628000,  157680000 ), // BMG 10-Jan-03 00:00 -> BMG  5-Jan-02 00:00
            new TFDItem( "GMT", "en@calendar=roc",    -1988064000000L, -2145744000000L, false,  -4, -59, -1825, -43800, -2628000, -157680000 ), // BMG  5-Jan-02 00:00 -> BMG 10-Jan-03 00:00
            new TFDItem( "GMT", "en@calendar=roc",    -1988064000000L, -1672704000000L, false,   9, 119,  3650,  87600,  5256000,  315360000 ), // BMG  5-Jan-02 00:00 -> MG   5-Dec-30 00:00
            new TFDItem( "GMT", "en@calendar=roc",    -1672704000000L, -1988064000000L, false,  -9,-119, -3650, -87600, -5256000, -315360000 ), // MG   5-Dec-30 00:00 -> BMG  5-Jan-02 00:00
            new TFDItem( "GMT", "en@calendar=coptic",-53026531200000L,-52868851200000L, false,   4,  64,  1825,  43800,  2628000,  157680000 ), // Er1  5-Nas-05 00:00 -> Er1 10-Nas-04 00:00
            new TFDItem( "GMT", "en@calendar=coptic",-52868851200000L,-53026531200000L, false,  -4, -64, -1825, -43800, -2628000, -157680000 ), // Er1 10-Nas-04 00:00 -> Er1  5-Nas-05 00:00
            new TFDItem( "GMT", "en@calendar=coptic",-53499571200000L,-53341891200000L, false,   4,  64,  1825,  43800,  2628000,  157680000 ), // Er0 10-Tou-04 00:00 -> Er0  5-Tou-02 00:00
            new TFDItem( "GMT", "en@calendar=coptic",-53341891200000L,-53499571200000L, false,  -4, -64, -1825, -43800, -2628000, -157680000 ), // Er0  5-Tou-02 00:00 -> Er0 10-Tou-04 00:00
            new TFDItem( "GMT", "en@calendar=coptic",-53341891200000L,-53026531200000L, false,   9, 129,  3650,  87600,  5256000,  315360000 ), // Er0  5-Tou-02 00:00 -> Er1  5-Nas-05 00:00
            new TFDItem( "GMT", "en@calendar=coptic",-53026531200000L,-53341891200000L, false,  -9,-129, -3650, -87600, -5256000, -315360000 ), // Er1  5-Nas-05 00:00 -> Er0  5-Tou-02 00:00
        };
        for (TFDItem tfdItem: tfdItems) {
            TimeZone timezone = TimeZone.getFrozenTimeZone(tfdItem.tzname);
            Calendar ucal = Calendar.getInstance(timezone, new ULocale(tfdItem.locale));
            ucal.setTimeInMillis(tfdItem.target);
            Date targetDate = ucal.getTime();
            int yDf, MDf, dDf, HDf, mDf, sDf;
            if (tfdItem.progressive) {
                ucal.setTimeInMillis(tfdItem.start);
                yDf = ucal.fieldDifference(targetDate, YEAR);
                MDf = ucal.fieldDifference(targetDate, MONTH);
                dDf = ucal.fieldDifference(targetDate, DATE);
                HDf = ucal.fieldDifference(targetDate, HOUR);
                mDf = ucal.fieldDifference(targetDate, MINUTE);
                sDf = ucal.fieldDifference(targetDate, SECOND);
                if ( yDf != tfdItem.yDiff || MDf != tfdItem.MDiff || dDf != tfdItem.dDiff || HDf != tfdItem.HDiff || mDf != tfdItem.mDiff || sDf != tfdItem.sDiff ) {
                    errln("Fail: for locale \"" + tfdItem.locale + "\", start " + tfdItem.start + ", target " +  tfdItem.target + ", expected y-M-d-H-m-s progressive diffs " +
                            tfdItem.yDiff +","+ tfdItem.MDiff +","+ tfdItem.dDiff +","+ tfdItem.HDiff +","+ tfdItem.mDiff +","+ tfdItem.sDiff + ", got " +
                            yDf +","+ MDf +","+ dDf +","+ HDf +","+ mDf +","+ sDf);
                }
            } else {
                ucal.setTimeInMillis(tfdItem.start);
                yDf = ucal.fieldDifference(targetDate, YEAR);
                ucal.setTimeInMillis(tfdItem.start);
                MDf = ucal.fieldDifference(targetDate, MONTH);
                ucal.setTimeInMillis(tfdItem.start);
                dDf = ucal.fieldDifference(targetDate, DATE);
                ucal.setTimeInMillis(tfdItem.start);
                HDf = ucal.fieldDifference(targetDate, HOUR);
                ucal.setTimeInMillis(tfdItem.start);
                mDf = ucal.fieldDifference(targetDate, MINUTE);
                if ( yDf != tfdItem.yDiff || MDf != tfdItem.MDiff || dDf != tfdItem.dDiff || HDf != tfdItem.HDiff || mDf != tfdItem.mDiff ) {
                    errln("Fail: for locale \"" + tfdItem.locale + "\", start " + tfdItem.start + ", target " +  tfdItem.target + ", expected y-M-d-H-m total diffs " +
                            tfdItem.yDiff +","+ tfdItem.MDiff +","+ tfdItem.dDiff +","+ tfdItem.HDiff +","+ tfdItem.mDiff + ", got " +
                            yDf +","+ MDf +","+ dDf +","+ HDf +","+ mDf);
                }
                ucal.setTimeInMillis(tfdItem.start);
                sDf = ucal.fieldDifference(targetDate, SECOND);
                if ( sDf != 0x7FFFFFFF && sDf != tfdItem.sDiff ) {
                    errln("Fail: for locale \"" + tfdItem.locale + "\", start " + tfdItem.start + ", target " +  tfdItem.target + ", expected seconds total diffs " +
                            tfdItem.sDiff + ", got " + sDf);
                }
            }
        }
    }

    @Test
    public void TestAddRollEra0AndEraBounds() {
        final String[] localeIDs = {
            // calendars with non-modern era 0 that goes backwards, max era == 1
            "en@calendar=gregorian",
            "en@calendar=roc",
            "en@calendar=coptic",
            // calendars with non-modern era 0 that goes forwards, max era > 1
            "en@calendar=japanese",
            "en@calendar=chinese",
            // calendars with non-modern era 0 that goes forwards, max era == 1
            "en@calendar=ethiopic",
            // calendars with only one era  = 0, forwards
            "en@calendar=buddhist",
            "en@calendar=hebrew",
            "en@calendar=islamic",
            "en@calendar=indian",
            //"en@calendar=persian", // no persian calendar in ICU4J yet
            "en@calendar=ethiopic-amete-alem",
        };
        TimeZone zoneGMT = TimeZone.getFrozenTimeZone("GMT");
        for (String localeID : localeIDs) {
            Calendar ucalTest = Calendar.getInstance(zoneGMT, new ULocale(localeID));
            String calType = ucalTest.getType();
            boolean era0YearsGoBackwards = (calType.equals("gregorian") || calType.equals("roc") || calType.equals("coptic"));
            int yrBefore, yrAfter, yrMax, eraAfter, eraMax, eraNow;

            ucalTest.clear();
            ucalTest.set(Calendar.YEAR, 2);
            ucalTest.set(Calendar.ERA, 0);
            yrBefore = ucalTest.get(Calendar.YEAR);
            ucalTest.add(Calendar.YEAR, 1);
            yrAfter = ucalTest.get(Calendar.YEAR);
            if ( (era0YearsGoBackwards && yrAfter>yrBefore) || (!era0YearsGoBackwards && yrAfter<yrBefore) ) {
                errln("Fail: era 0 add 1 year does not move forward in time for " + localeID);
            }

            ucalTest.clear();
            ucalTest.set(Calendar.YEAR, 2);
            ucalTest.set(Calendar.ERA, 0);
            yrBefore = ucalTest.get(Calendar.YEAR);
            ucalTest.roll(Calendar.YEAR, 1);
            yrAfter = ucalTest.get(Calendar.YEAR);
            if ( (era0YearsGoBackwards && yrAfter>yrBefore) || (!era0YearsGoBackwards && yrAfter<yrBefore) ) {
                errln("Fail: era 0 roll 1 year does not move forward in time for " + localeID);
            }

            ucalTest.clear();
            ucalTest.set(Calendar.YEAR, 1);
            ucalTest.set(Calendar.ERA, 0);
            if (era0YearsGoBackwards) {
                ucalTest.roll(Calendar.YEAR, 1);
                yrAfter = ucalTest.get(Calendar.YEAR);
                eraAfter = ucalTest.get(Calendar.ERA);
                if (eraAfter != 0 || yrAfter != 1) {
                    errln("Fail: era 0 roll 1 year from year 1 does not stay within era or pin to year 1 for "
                            + localeID + " (get era " + eraAfter + " year " + yrAfter + ")");
                }
            } else {
                // roll backward in time to where era 0 years go negative, except for the Chinese
                // calendar, which uses negative eras instead of having years outside the range 1-60
                ucalTest.roll(Calendar.YEAR, -2);
                yrAfter = ucalTest.get(Calendar.YEAR);
                eraAfter = ucalTest.get(Calendar.ERA);
                if ( !calType.equals("chinese") && (eraAfter != 0 || yrAfter != -1) ) {
                    errln("Fail: era 0 roll -2 years from year 1 does not stay within era or produce year -1 for "
                            + localeID + " (get era " + eraAfter + " year " + yrAfter + ")");
                }
            }

            ucalTest.clear();
            {
                int eraMin = ucalTest.getMinimum(Calendar.ERA);
                if (eraMin != 0 && calType.compareTo("chinese") != 0) {
                    errln("Fail: getMinimum returns minimum era " + eraMin + " (should be 0) for calType " + calType);
                }
            }

            ucalTest.clear();
            ucalTest.set(Calendar.YEAR, 1);
            ucalTest.set(Calendar.ERA, 0);
            eraMax = ucalTest.getMaximum(Calendar.ERA);
            if (eraMax > 0) {
                // try similar tests for era 1 (if calendar has it), in which years always go forward

                ucalTest.clear();
                ucalTest.set(Calendar.YEAR, 2);
                ucalTest.set(Calendar.ERA, 1);
                yrBefore = ucalTest.get(Calendar.YEAR);
                ucalTest.add(Calendar.YEAR, 1);
                yrAfter = ucalTest.get(Calendar.YEAR);
                if ( yrAfter<yrBefore ) {
                    errln("Fail: era 1 add 1 year does not move forward in time for " + localeID);
                }

                ucalTest.clear();
                ucalTest.set(Calendar.YEAR, 2);
                ucalTest.set(Calendar.ERA, 1);
                yrBefore = ucalTest.get(Calendar.YEAR);
                ucalTest.roll(Calendar.YEAR, 1);
                yrAfter = ucalTest.get(Calendar.YEAR);
                if ( yrAfter<yrBefore ) {
                    errln("Fail: era 1 roll 1 year does not move forward in time for " + localeID);
                }

                ucalTest.clear();
                ucalTest.set(Calendar.YEAR, 1);
                ucalTest.set(Calendar.ERA, 1);
                yrMax = ucalTest.getActualMaximum(Calendar.YEAR);
                ucalTest.roll(Calendar.YEAR, -1); // roll down which should pin or wrap to end
                yrAfter = ucalTest.get(Calendar.YEAR);
                eraAfter = ucalTest.get(Calendar.ERA);
                // if yrMax is reasonable we should wrap to that, else we should pin at yr 1
                if (yrMax >= 32768) {
                    if (eraAfter != 1 || yrAfter != 1) {
                        errln("Fail: era 1 roll -1 year from year 1 does not stay within era or pin to year 1 for "
                                + localeID + " (get era " + eraAfter + " year " + yrAfter + ")");
                    }
                } else if (eraAfter != 1 || yrAfter != yrMax) {
                    errln("Fail: era 1 roll -1 year from year 1 does not stay within era or wrap to year "
                            + yrMax + " for " + localeID + " (get era " + eraAfter + " year " + yrAfter + ")");
                } else {
                    ucalTest.roll(Calendar.YEAR, 1); // now roll up which should wrap to beginning
                    yrAfter = ucalTest.get(Calendar.YEAR);
                    eraAfter = ucalTest.get(Calendar.ERA);
                    if (eraAfter != 1 || yrAfter != 1) {
                        errln("Fail: era 1 roll 1 year from year " + yrMax +
                                " does not stay within era or wrap to year 1 for "
                                + localeID + " (get era " + eraAfter + " year " + yrAfter + ")");
                    }
                }

                // if current era  > 1, try the same roll tests for current era
                ucalTest.setTime(new Date());
                eraNow = ucalTest.get(Calendar.ERA);
                if (eraNow > 1) {
                    ucalTest.clear();
                    ucalTest.set(Calendar.YEAR, 1);
                    ucalTest.set(Calendar.ERA, eraNow);
                    yrMax = ucalTest.getActualMaximum(Calendar.YEAR); // max year value for this era
                    ucalTest.roll(Calendar.YEAR, -1);
                    yrAfter = ucalTest.get(Calendar.YEAR);
                    eraAfter = ucalTest.get(Calendar.ERA);
                    // if yrMax is reasonable we should wrap to that, else we should pin at yr 1
                    if (yrMax >= 32768) {
                        if (eraAfter != eraNow || yrAfter != 1) {
                            errln("Fail: era " + eraNow +
                                    " roll -1 year from year 1 does not stay within era or pin to year 1 for "
                                    + localeID + " (get era " + eraAfter + " year " + yrAfter + ")");
                        }
                    } else if (eraAfter != eraNow || yrAfter != yrMax) {
                        errln("Fail: era " + eraNow +
                                " roll -1 year from year 1 does not stay within era or wrap to year " + yrMax
                                + " for " + localeID + " (get era " + eraAfter + " year " + yrAfter + ")");
                    } else {
                        ucalTest.roll(Calendar.YEAR, 1); // now roll up which should wrap to beginning
                        yrAfter = ucalTest.get(Calendar.YEAR);
                        eraAfter = ucalTest.get(Calendar.ERA);
                        if (eraAfter != eraNow || yrAfter != 1) {
                            errln("Fail: era " + eraNow + " roll 1 year from year " + yrMax +
                                    " does not stay within era or wrap to year 1 for "
                                    + localeID + " (get era " + eraAfter + " year " + yrAfter + ")");
                        }
                    }
                }
            }
        }
    }

    @Test
    public void TestWeekData() {
        // Each line contains two locales using the same set of week rule data.
        final String LOCALE_PAIRS[] = {
            "en",       "en_US",
            "de",       "de_DE",
            "de_DE",    "en_DE",
            "en_GB",    "und_GB",
            "ar_EG",    "en_EG",
            "ar_SA",    "fr_SA",
        };

        for (int i = 0; i < LOCALE_PAIRS.length; i += 2) {
            Calendar cal1 = Calendar.getInstance(new ULocale(LOCALE_PAIRS[i]));
            Calendar cal2 = Calendar.getInstance(new ULocale(LOCALE_PAIRS[i + 1]));

            // First day of week
            int dow1 = cal1.getFirstDayOfWeek();
            int dow2 = cal2.getFirstDayOfWeek();
            if (dow1 != dow2) {
                errln("getFirstDayOfWeek: " + LOCALE_PAIRS[i] + "->" + dow1 + ", " + LOCALE_PAIRS[i + 1] + "->" + dow2);
            }

            // Minimum days in first week
            int minDays1 = cal1.getMinimalDaysInFirstWeek();
            int minDays2 = cal2.getMinimalDaysInFirstWeek();
            if (minDays1 != minDays2) {
                errln("getMinimalDaysInFirstWeek: " + LOCALE_PAIRS[i] + "->" + minDays1 + ", " + LOCALE_PAIRS[i + 1] + "->" + minDays2);
            }

            // Weekdays and Weekends
            for (int d = Calendar.SUNDAY; d <= Calendar.SATURDAY; d++) {
                int wdt1 = cal1.getDayOfWeekType(d);
                int wdt2 = cal2.getDayOfWeekType(d);
                if (wdt1 != wdt2) {
                    errln("getDayOfWeekType(" + d + "): " + LOCALE_PAIRS[i] + "->" + wdt1 + ", " + LOCALE_PAIRS[i + 1] + "->" + wdt2);
                }
            }
        }
    }

    @Test
    public void TestAddAcrossZoneTransition() {
        class TestData {
            String zone;
            CalFields base;
            int deltaDays;
            int skippedWTOpt;
            CalFields expected;

            TestData(String zone, CalFields base, int deltaDays, int skippedWTOpt, CalFields expected) {
                this.zone = zone;
                this.base = base;
                this.deltaDays = deltaDays;
                this.skippedWTOpt = skippedWTOpt;
                this.expected = expected;
            }
        }

        TestData[] data = new TestData[] {
            // Add 1 day, from the date before DST transition
            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 1, 59, 59, 999), 1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2014, 3, 9, 1, 59, 59, 999)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 1, 59, 59, 999), 1, Calendar.WALLTIME_LAST,
                                                new CalFields(2014, 3, 9, 1, 59, 59, 999)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 1, 59, 59, 999), 1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2014, 3, 9, 1, 59, 59, 999)),


            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 2, 0, 0, 0), 1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2014, 3, 9, 1, 0, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 2, 0, 0, 0), 1, Calendar.WALLTIME_LAST,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 2, 0, 0, 0), 1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),


            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 2, 30, 0, 0), 1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2014, 3, 9, 1, 30, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 2, 30, 0, 0), 1, Calendar.WALLTIME_LAST,
                                                new CalFields(2014, 3, 9, 3, 30, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 2, 30, 0, 0), 1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),


            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 3, 0, 0, 0), 1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 3, 0, 0, 0), 1, Calendar.WALLTIME_LAST,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 8, 3, 0, 0, 0), 1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),


            // Subtract 1 day, from one day after DST transition
            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 1, 59, 59, 999), -1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2014, 3, 9, 1, 59, 59, 999)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 1, 59, 59, 999), -1, Calendar.WALLTIME_LAST,
                                                new CalFields(2014, 3, 9, 1, 59, 59, 999)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 1, 59, 59, 999), -1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2014, 3, 9, 1, 59, 59, 999)),


            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 2, 0, 0, 0), -1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2014, 3, 9, 1, 0, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 2, 0, 0, 0), -1, Calendar.WALLTIME_LAST,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 2, 0, 0, 0), -1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),


            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 2, 30, 0, 0), -1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2014, 3, 9, 1, 30, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 2, 30, 0, 0), -1, Calendar.WALLTIME_LAST,
                                                new CalFields(2014, 3, 9, 3, 30, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 2, 30, 0, 0), -1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),


            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 3, 0, 0, 0), -1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 3, 0, 0, 0), -1, Calendar.WALLTIME_LAST,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),

            new TestData("America/Los_Angeles", new CalFields(2014, 3, 10, 3, 0, 0, 0), -1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2014, 3, 9, 3, 0, 0, 0)),


            // Test case for ticket#10544
            new TestData("America/Santiago",    new CalFields(2013, 4, 27, 0, 0, 0, 0), 134, Calendar.WALLTIME_FIRST,
                                                new CalFields(2013, 9, 7, 23, 0, 0, 0)),

            new TestData("America/Santiago",    new CalFields(2013, 4, 27, 0, 0, 0, 0), 134, Calendar.WALLTIME_LAST,
                                                new CalFields(2013, 9, 8, 1, 0, 0, 0)),

            new TestData("America/Santiago",    new CalFields(2013, 4, 27, 0, 0, 0, 0), 134, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2013, 9, 8, 1, 0, 0, 0)),


            new TestData("America/Santiago",    new CalFields(2013, 4, 27, 0, 30, 0, 0), 134, Calendar.WALLTIME_FIRST,
                                                new CalFields(2013, 9, 7, 23, 30, 0, 0)),

            new TestData("America/Santiago",    new CalFields(2013, 4, 27, 0, 30, 0, 0), 134, Calendar.WALLTIME_LAST,
                                                new CalFields(2013, 9, 8, 1, 30, 0, 0)),

            new TestData("America/Santiago",    new CalFields(2013, 4, 27, 0, 30, 0, 0), 134, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2013, 9, 8, 1, 0, 0, 0)),


            // Extreme transition - Pacific/Apia completely skips 2011-12-30
            new TestData("Pacific/Apia",        new CalFields(2011, 12, 29, 0, 0, 0, 0), 1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2011, 12, 31, 0, 0, 0, 0)),

            new TestData("Pacific/Apia",        new CalFields(2011, 12, 29, 0, 0, 0, 0), 1, Calendar.WALLTIME_LAST,
                                                new CalFields(2011, 12, 31, 0, 0, 0, 0)),

            new TestData("Pacific/Apia",        new CalFields(2011, 12, 29, 0, 0, 0, 0), 1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2011, 12, 31, 0, 0, 0, 0)),


            new TestData("Pacific/Apia",        new CalFields(2011, 12, 31, 12, 0, 0, 0), -1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2011, 12, 29, 12, 0, 0, 0)),

            new TestData("Pacific/Apia",        new CalFields(2011, 12, 31, 12, 0, 0, 0), -1, Calendar.WALLTIME_LAST,
                                                new CalFields(2011, 12, 29, 12, 0, 0, 0)),

            new TestData("Pacific/Apia",        new CalFields(2011, 12, 31, 12, 0, 0, 0), -1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2011, 12, 29, 12, 0, 0, 0)),


            // 30 minutes DST - Australia/Lord_Howe
            new TestData("Australia/Lord_Howe", new CalFields(2013, 10, 5, 2, 15, 0, 0), 1, Calendar.WALLTIME_FIRST,
                                                new CalFields(2013, 10, 6, 1, 45, 0, 0)),

            new TestData("Australia/Lord_Howe", new CalFields(2013, 10, 5, 2, 15, 0, 0), 1, Calendar.WALLTIME_LAST,
                                                new CalFields(2013, 10, 6, 2, 45, 0, 0)),

            new TestData("Australia/Lord_Howe", new CalFields(2013, 10, 5, 2, 15, 0, 0), 1, Calendar.WALLTIME_NEXT_VALID,
                                                new CalFields(2013, 10, 6, 2, 30, 0, 0)),
        };

        Calendar cal = Calendar.getInstance();
        for (TestData d : data) {
            cal.setTimeZone(TimeZone.getTimeZone(d.zone));
            cal.setSkippedWallTimeOption(d.skippedWTOpt);
            d.base.setTo(cal);
            cal.add(Calendar.DATE, d.deltaDays);

            if (!d.expected.isEquivalentTo(cal)) {
                CalFields res = CalFields.createFrom(cal);
                String optDisp = d.skippedWTOpt == Calendar.WALLTIME_FIRST ? "FIRST" :
                    d.skippedWTOpt == Calendar.WALLTIME_LAST ? "LAST" : "NEXT_VALID";
                errln("Error: base:" + d.base.toString() + ", tz:" + d.zone
                        + ", delta:" + d.deltaDays + " day(s), opt:" + optDisp
                        + ", result:" + res.toString() + " - expected:" + d.expected.toString());
            }
        }
    }

    public void TestSimpleDateFormatCoverage() {

        class StubSimpleDateFormat extends SimpleDateFormat {
            private static final long serialVersionUID = 1L;

            public StubSimpleDateFormat(String pattern, Locale loc) {
                new SimpleDateFormat(pattern, loc);
            }

            public void run(){
                Calendar cal = Calendar.getInstance(Locale.US);
                cal.clear();
                cal.set(2000, Calendar.MARCH, 18, 15,  0, 1); // Sat 15:00

                DateFormatSymbols theseSymbols = this.getSymbols();
                String shouldBeMonday = theseSymbols.getWeekdays()[Calendar.MONDAY];
                assertEquals("Should be Monday", "Monday", shouldBeMonday);

                String [] matchData = {"16", "2016", "2016AD", "Monday", "lunes"};
                int matchIndex =  matchString("Monday March 28, 2016", 0, Calendar.DAY_OF_WEEK, matchData, cal);
                assertEquals("matchData for Monday", 6, matchIndex); // Position of the pointer after the matched string.
                matchIndex =  matchString("Monday March 28, 2016 AD", 17, Calendar.YEAR, matchData, cal);
                assertEquals("matchData for 2016", 21, matchIndex); // Position of the pointer after the matched string.

                char ch = 'y';
                int count = 4;
                int beginOffset = 0;
                cal.set(Calendar.YEAR, 2000);  // Reset this
                assertEquals("calendar year reset", 2000, cal.get(Calendar.YEAR));
                FieldPosition pos = new FieldPosition(java.text.DateFormat.YEAR_FIELD);
                String subFormatResult = subFormat(ch, count, beginOffset,
                        pos, theseSymbols, cal);
                assertEquals("subFormat result", "2000", subFormatResult);

                String testParseString = "some text with a date 2017-03-15";
                int start = 22;
                boolean obeyCount = true;
                boolean allowNegative = false;
                boolean ambiguousYear[] = {true, false, true};
                int subParseResult = subParse(testParseString, start, ch, count,
                        obeyCount, allowNegative, ambiguousYear, cal);
                assertEquals("subParseResult result", 26, subParseResult);
                assertEquals("parsed year", 2017, cal.get(Calendar.YEAR));
            }
        }
        StubSimpleDateFormat stub = new StubSimpleDateFormat("EEE MMM dd yyyy G HH:mm:ss.SSS", Locale.US);
        stub.run();
    }
}