KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > chrono > TestIslamicChronology


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.joda.time.chrono;
17
18 import java.util.Locale JavaDoc;
19 import java.util.TimeZone JavaDoc;
20
21 import junit.framework.TestCase;
22 import junit.framework.TestSuite;
23
24 import org.joda.time.Chronology;
25 import org.joda.time.DateTime;
26 import org.joda.time.DateTimeConstants;
27 import org.joda.time.DateTimeField;
28 import org.joda.time.DateTimeUtils;
29 import org.joda.time.DateTimeZone;
30 import org.joda.time.DurationFieldType;
31 import org.joda.time.DateTime.Property;
32
33 /**
34  * This class is a Junit unit test for IslamicChronology.
35  *
36  * @author Stephen Colebourne
37  */

38 public class TestIslamicChronology extends TestCase {
39
40     private static long SKIP = 1 * DateTimeConstants.MILLIS_PER_DAY;
41
42     private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
43     private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
44     private static final DateTimeZone TOKYO = DateTimeZone.forID("Asia/Tokyo");
45     private static final Chronology ISLAMIC_UTC = IslamicChronology.getInstanceUTC();
46     private static final Chronology JULIAN_UTC = JulianChronology.getInstanceUTC();
47     private static final Chronology ISO_UTC = ISOChronology.getInstanceUTC();
48
49     long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
50                      366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
51                      365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
52                      366 + 365;
53     // 2002-06-09
54
private long TEST_TIME_NOW =
55             (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
56
57     private DateTimeZone originalDateTimeZone = null;
58     private TimeZone JavaDoc originalTimeZone = null;
59     private Locale JavaDoc originalLocale = null;
60
61     public static void main(String JavaDoc[] args) {
62         junit.textui.TestRunner.run(suite());
63     }
64
65     public static TestSuite suite() {
66         SKIP = 1 * DateTimeConstants.MILLIS_PER_DAY;
67         return new TestSuite(TestIslamicChronology.class);
68     }
69
70     public TestIslamicChronology(String JavaDoc name) {
71         super(name);
72     }
73
74     protected void setUp() throws Exception JavaDoc {
75         DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
76         originalDateTimeZone = DateTimeZone.getDefault();
77         originalTimeZone = TimeZone.getDefault();
78         originalLocale = Locale.getDefault();
79         DateTimeZone.setDefault(LONDON);
80         TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
81         Locale.setDefault(Locale.UK);
82     }
83
84     protected void tearDown() throws Exception JavaDoc {
85         DateTimeUtils.setCurrentMillisSystem();
86         DateTimeZone.setDefault(originalDateTimeZone);
87         TimeZone.setDefault(originalTimeZone);
88         Locale.setDefault(originalLocale);
89         originalDateTimeZone = null;
90         originalTimeZone = null;
91         originalLocale = null;
92     }
93
94     //-----------------------------------------------------------------------
95
public void testFactoryUTC() {
96         assertEquals(DateTimeZone.UTC, IslamicChronology.getInstanceUTC().getZone());
97         assertSame(IslamicChronology.class, IslamicChronology.getInstanceUTC().getClass());
98     }
99
100     public void testFactory() {
101         assertEquals(LONDON, IslamicChronology.getInstance().getZone());
102         assertSame(IslamicChronology.class, IslamicChronology.getInstance().getClass());
103     }
104
105     public void testFactory_Zone() {
106         assertEquals(TOKYO, IslamicChronology.getInstance(TOKYO).getZone());
107         assertEquals(PARIS, IslamicChronology.getInstance(PARIS).getZone());
108         assertEquals(LONDON, IslamicChronology.getInstance(null).getZone());
109         assertSame(IslamicChronology.class, IslamicChronology.getInstance(TOKYO).getClass());
110     }
111
112     //-----------------------------------------------------------------------
113
public void testEquality() {
114         assertSame(IslamicChronology.getInstance(TOKYO), IslamicChronology.getInstance(TOKYO));
115         assertSame(IslamicChronology.getInstance(LONDON), IslamicChronology.getInstance(LONDON));
116         assertSame(IslamicChronology.getInstance(PARIS), IslamicChronology.getInstance(PARIS));
117         assertSame(IslamicChronology.getInstanceUTC(), IslamicChronology.getInstanceUTC());
118         assertSame(IslamicChronology.getInstance(), IslamicChronology.getInstance(LONDON));
119     }
120
121     public void testWithUTC() {
122         assertSame(IslamicChronology.getInstanceUTC(), IslamicChronology.getInstance(LONDON).withUTC());
123         assertSame(IslamicChronology.getInstanceUTC(), IslamicChronology.getInstance(TOKYO).withUTC());
124         assertSame(IslamicChronology.getInstanceUTC(), IslamicChronology.getInstanceUTC().withUTC());
125         assertSame(IslamicChronology.getInstanceUTC(), IslamicChronology.getInstance().withUTC());
126     }
127
128     public void testWithZone() {
129         assertSame(IslamicChronology.getInstance(TOKYO), IslamicChronology.getInstance(TOKYO).withZone(TOKYO));
130         assertSame(IslamicChronology.getInstance(LONDON), IslamicChronology.getInstance(TOKYO).withZone(LONDON));
131         assertSame(IslamicChronology.getInstance(PARIS), IslamicChronology.getInstance(TOKYO).withZone(PARIS));
132         assertSame(IslamicChronology.getInstance(LONDON), IslamicChronology.getInstance(TOKYO).withZone(null));
133         assertSame(IslamicChronology.getInstance(PARIS), IslamicChronology.getInstance().withZone(PARIS));
134         assertSame(IslamicChronology.getInstance(PARIS), IslamicChronology.getInstanceUTC().withZone(PARIS));
135     }
136
137     public void testToString() {
138         assertEquals("IslamicChronology[Europe/London]", IslamicChronology.getInstance(LONDON).toString());
139         assertEquals("IslamicChronology[Asia/Tokyo]", IslamicChronology.getInstance(TOKYO).toString());
140         assertEquals("IslamicChronology[Europe/London]", IslamicChronology.getInstance().toString());
141         assertEquals("IslamicChronology[UTC]", IslamicChronology.getInstanceUTC().toString());
142     }
143
144     //-----------------------------------------------------------------------
145
public void testDurationFields() {
146         assertEquals("eras", IslamicChronology.getInstance().eras().getName());
147         assertEquals("centuries", IslamicChronology.getInstance().centuries().getName());
148         assertEquals("years", IslamicChronology.getInstance().years().getName());
149         assertEquals("weekyears", IslamicChronology.getInstance().weekyears().getName());
150         assertEquals("months", IslamicChronology.getInstance().months().getName());
151         assertEquals("weeks", IslamicChronology.getInstance().weeks().getName());
152         assertEquals("days", IslamicChronology.getInstance().days().getName());
153         assertEquals("halfdays", IslamicChronology.getInstance().halfdays().getName());
154         assertEquals("hours", IslamicChronology.getInstance().hours().getName());
155         assertEquals("minutes", IslamicChronology.getInstance().minutes().getName());
156         assertEquals("seconds", IslamicChronology.getInstance().seconds().getName());
157         assertEquals("millis", IslamicChronology.getInstance().millis().getName());
158         
159         assertEquals(false, IslamicChronology.getInstance().eras().isSupported());
160         assertEquals(true, IslamicChronology.getInstance().centuries().isSupported());
161         assertEquals(true, IslamicChronology.getInstance().years().isSupported());
162         assertEquals(true, IslamicChronology.getInstance().weekyears().isSupported());
163         assertEquals(true, IslamicChronology.getInstance().months().isSupported());
164         assertEquals(true, IslamicChronology.getInstance().weeks().isSupported());
165         assertEquals(true, IslamicChronology.getInstance().days().isSupported());
166         assertEquals(true, IslamicChronology.getInstance().halfdays().isSupported());
167         assertEquals(true, IslamicChronology.getInstance().hours().isSupported());
168         assertEquals(true, IslamicChronology.getInstance().minutes().isSupported());
169         assertEquals(true, IslamicChronology.getInstance().seconds().isSupported());
170         assertEquals(true, IslamicChronology.getInstance().millis().isSupported());
171         
172         assertEquals(false, IslamicChronology.getInstance().centuries().isPrecise());
173         assertEquals(false, IslamicChronology.getInstance().years().isPrecise());
174         assertEquals(false, IslamicChronology.getInstance().weekyears().isPrecise());
175         assertEquals(false, IslamicChronology.getInstance().months().isPrecise());
176         assertEquals(false, IslamicChronology.getInstance().weeks().isPrecise());
177         assertEquals(false, IslamicChronology.getInstance().days().isPrecise());
178         assertEquals(false, IslamicChronology.getInstance().halfdays().isPrecise());
179         assertEquals(true, IslamicChronology.getInstance().hours().isPrecise());
180         assertEquals(true, IslamicChronology.getInstance().minutes().isPrecise());
181         assertEquals(true, IslamicChronology.getInstance().seconds().isPrecise());
182         assertEquals(true, IslamicChronology.getInstance().millis().isPrecise());
183         
184         assertEquals(false, IslamicChronology.getInstanceUTC().centuries().isPrecise());
185         assertEquals(false, IslamicChronology.getInstanceUTC().years().isPrecise());
186         assertEquals(false, IslamicChronology.getInstanceUTC().weekyears().isPrecise());
187         assertEquals(false, IslamicChronology.getInstanceUTC().months().isPrecise());
188         assertEquals(true, IslamicChronology.getInstanceUTC().weeks().isPrecise());
189         assertEquals(true, IslamicChronology.getInstanceUTC().days().isPrecise());
190         assertEquals(true, IslamicChronology.getInstanceUTC().halfdays().isPrecise());
191         assertEquals(true, IslamicChronology.getInstanceUTC().hours().isPrecise());
192         assertEquals(true, IslamicChronology.getInstanceUTC().minutes().isPrecise());
193         assertEquals(true, IslamicChronology.getInstanceUTC().seconds().isPrecise());
194         assertEquals(true, IslamicChronology.getInstanceUTC().millis().isPrecise());
195     }
196
197     public void testDateFields() {
198         assertEquals("era", IslamicChronology.getInstance().era().getName());
199         assertEquals("centuryOfEra", IslamicChronology.getInstance().centuryOfEra().getName());
200         assertEquals("yearOfCentury", IslamicChronology.getInstance().yearOfCentury().getName());
201         assertEquals("yearOfEra", IslamicChronology.getInstance().yearOfEra().getName());
202         assertEquals("year", IslamicChronology.getInstance().year().getName());
203         assertEquals("monthOfYear", IslamicChronology.getInstance().monthOfYear().getName());
204         assertEquals("weekyearOfCentury", IslamicChronology.getInstance().weekyearOfCentury().getName());
205         assertEquals("weekyear", IslamicChronology.getInstance().weekyear().getName());
206         assertEquals("weekOfWeekyear", IslamicChronology.getInstance().weekOfWeekyear().getName());
207         assertEquals("dayOfYear", IslamicChronology.getInstance().dayOfYear().getName());
208         assertEquals("dayOfMonth", IslamicChronology.getInstance().dayOfMonth().getName());
209         assertEquals("dayOfWeek", IslamicChronology.getInstance().dayOfWeek().getName());
210         
211         assertEquals(true, IslamicChronology.getInstance().era().isSupported());
212         assertEquals(true, IslamicChronology.getInstance().centuryOfEra().isSupported());
213         assertEquals(true, IslamicChronology.getInstance().yearOfCentury().isSupported());
214         assertEquals(true, IslamicChronology.getInstance().yearOfEra().isSupported());
215         assertEquals(true, IslamicChronology.getInstance().year().isSupported());
216         assertEquals(true, IslamicChronology.getInstance().monthOfYear().isSupported());
217         assertEquals(true, IslamicChronology.getInstance().weekyearOfCentury().isSupported());
218         assertEquals(true, IslamicChronology.getInstance().weekyear().isSupported());
219         assertEquals(true, IslamicChronology.getInstance().weekOfWeekyear().isSupported());
220         assertEquals(true, IslamicChronology.getInstance().dayOfYear().isSupported());
221         assertEquals(true, IslamicChronology.getInstance().dayOfMonth().isSupported());
222         assertEquals(true, IslamicChronology.getInstance().dayOfWeek().isSupported());
223     }
224
225     public void testTimeFields() {
226         assertEquals("halfdayOfDay", IslamicChronology.getInstance().halfdayOfDay().getName());
227         assertEquals("clockhourOfHalfday", IslamicChronology.getInstance().clockhourOfHalfday().getName());
228         assertEquals("hourOfHalfday", IslamicChronology.getInstance().hourOfHalfday().getName());
229         assertEquals("clockhourOfDay", IslamicChronology.getInstance().clockhourOfDay().getName());
230         assertEquals("hourOfDay", IslamicChronology.getInstance().hourOfDay().getName());
231         assertEquals("minuteOfDay", IslamicChronology.getInstance().minuteOfDay().getName());
232         assertEquals("minuteOfHour", IslamicChronology.getInstance().minuteOfHour().getName());
233         assertEquals("secondOfDay", IslamicChronology.getInstance().secondOfDay().getName());
234         assertEquals("secondOfMinute", IslamicChronology.getInstance().secondOfMinute().getName());
235         assertEquals("millisOfDay", IslamicChronology.getInstance().millisOfDay().getName());
236         assertEquals("millisOfSecond", IslamicChronology.getInstance().millisOfSecond().getName());
237         
238         assertEquals(true, IslamicChronology.getInstance().halfdayOfDay().isSupported());
239         assertEquals(true, IslamicChronology.getInstance().clockhourOfHalfday().isSupported());
240         assertEquals(true, IslamicChronology.getInstance().hourOfHalfday().isSupported());
241         assertEquals(true, IslamicChronology.getInstance().clockhourOfDay().isSupported());
242         assertEquals(true, IslamicChronology.getInstance().hourOfDay().isSupported());
243         assertEquals(true, IslamicChronology.getInstance().minuteOfDay().isSupported());
244         assertEquals(true, IslamicChronology.getInstance().minuteOfHour().isSupported());
245         assertEquals(true, IslamicChronology.getInstance().secondOfDay().isSupported());
246         assertEquals(true, IslamicChronology.getInstance().secondOfMinute().isSupported());
247         assertEquals(true, IslamicChronology.getInstance().millisOfDay().isSupported());
248         assertEquals(true, IslamicChronology.getInstance().millisOfSecond().isSupported());
249     }
250
251     //-----------------------------------------------------------------------
252
public void testEpoch() {
253         DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ISLAMIC_UTC);
254         DateTime expectedEpoch = new DateTime(622, 7, 16, 0, 0, 0, 0, JULIAN_UTC);
255         assertEquals(expectedEpoch.getMillis(), epoch.getMillis());
256     }
257
258     public void testEra() {
259         assertEquals(1, IslamicChronology.AH);
260         try {
261             new DateTime(-1, 13, 5, 0, 0, 0, 0, ISLAMIC_UTC);
262             fail();
263         } catch (IllegalArgumentException JavaDoc ex) {}
264     }
265
266     //-----------------------------------------------------------------------
267
public void testFieldConstructor() {
268         DateTime date = new DateTime(1364, 12, 6, 0, 0, 0, 0, ISLAMIC_UTC);
269         DateTime expectedDate = new DateTime(1945, 11, 12, 0, 0, 0, 0, ISO_UTC);
270         assertEquals(expectedDate.getMillis(), date.getMillis());
271     }
272
273     //-----------------------------------------------------------------------
274
/**
275      * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
276      */

277     public void testCalendar() {
278         if (TestAll.FAST) {
279             return;
280         }
281         System.out.println("\nTestIslamicChronology.testCalendar");
282         DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ISLAMIC_UTC);
283         long millis = epoch.getMillis();
284         long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
285         DateTimeField dayOfWeek = ISLAMIC_UTC.dayOfWeek();
286         DateTimeField dayOfYear = ISLAMIC_UTC.dayOfYear();
287         DateTimeField dayOfMonth = ISLAMIC_UTC.dayOfMonth();
288         DateTimeField monthOfYear = ISLAMIC_UTC.monthOfYear();
289         DateTimeField year = ISLAMIC_UTC.year();
290         DateTimeField yearOfEra = ISLAMIC_UTC.yearOfEra();
291         DateTimeField era = ISLAMIC_UTC.era();
292         int expectedDOW = new DateTime(622, 7, 16, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek();
293         int expectedDOY = 1;
294         int expectedDay = 1;
295         int expectedMonth = 1;
296         int expectedYear = 1;
297         while (millis < end) {
298             int dowValue = dayOfWeek.get(millis);
299             int doyValue = dayOfYear.get(millis);
300             int dayValue = dayOfMonth.get(millis);
301             int monthValue = monthOfYear.get(millis);
302             int yearValue = year.get(millis);
303             int yearOfEraValue = yearOfEra.get(millis);
304             int dayOfYearLen = dayOfYear.getMaximumValue(millis);
305             int monthLen = dayOfMonth.getMaximumValue(millis);
306             if (monthValue < 1 || monthValue > 12) {
307                 fail("Bad month: " + millis);
308             }
309             
310             // test era
311
assertEquals(1, era.get(millis));
312             assertEquals("AH", era.getAsText(millis));
313             assertEquals("AH", era.getAsShortText(millis));
314             
315             // test date
316
assertEquals(expectedDOY, doyValue);
317             assertEquals(expectedMonth, monthValue);
318             assertEquals(expectedDay, dayValue);
319             assertEquals(expectedDOW, dowValue);
320             assertEquals(expectedYear, yearValue);
321             assertEquals(expectedYear, yearOfEraValue);
322             
323             // test leap year
324
boolean leap = ((11 * yearValue + 14) % 30) < 11;
325             assertEquals(leap, year.isLeap(millis));
326             
327             // test month length
328
switch (monthValue) {
329                 case 1:
330                 case 3:
331                 case 5:
332                 case 7:
333                 case 9:
334                 case 11:
335                     assertEquals(30, monthLen);
336                     break;
337                 case 2:
338                 case 4:
339                 case 6:
340                 case 8:
341                 case 10:
342                     assertEquals(29, monthLen);
343                     break;
344                 case 12:
345                     assertEquals((leap ? 30 : 29), monthLen);
346                     break;
347             }
348             
349             // test year length
350
assertEquals((leap ? 355 : 354), dayOfYearLen);
351             
352             // recalculate date
353
expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
354             expectedDay++;
355             expectedDOY++;
356             if (expectedDay > monthLen) {
357                 expectedDay = 1;
358                 expectedMonth++;
359                 if (expectedMonth == 13) {
360                     expectedMonth = 1;
361                     expectedDOY = 1;
362                     expectedYear++;
363                 }
364             }
365             millis += SKIP;
366         }
367     }
368
369     public void testSampleDate1() {
370         DateTime dt = new DateTime(1945, 11, 12, 0, 0, 0, 0, ISO_UTC);
371         dt = dt.withChronology(ISLAMIC_UTC);
372         assertEquals(IslamicChronology.AH, dt.getEra());
373         assertEquals(14, dt.getCenturyOfEra()); // TODO confirm
374
assertEquals(64, dt.getYearOfCentury());
375         assertEquals(1364, dt.getYearOfEra());
376         
377         assertEquals(1364, dt.getYear());
378         Property fld = dt.year();
379         assertEquals(false, fld.isLeap());
380         assertEquals(0, fld.getLeapAmount());
381         assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
382         assertEquals(new DateTime(1365, 12, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
383         
384         assertEquals(12, dt.getMonthOfYear());
385         fld = dt.monthOfYear();
386         assertEquals(false, fld.isLeap());
387         assertEquals(0, fld.getLeapAmount());
388         assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
389         assertEquals(1, fld.getMinimumValue());
390         assertEquals(1, fld.getMinimumValueOverall());
391         assertEquals(12, fld.getMaximumValue());
392         assertEquals(12, fld.getMaximumValueOverall());
393         assertEquals(new DateTime(1365, 1, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
394         assertEquals(new DateTime(1364, 1, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addWrapFieldToCopy(1));
395         
396         assertEquals(6, dt.getDayOfMonth());
397         fld = dt.dayOfMonth();
398         assertEquals(false, fld.isLeap());
399         assertEquals(0, fld.getLeapAmount());
400         assertEquals(null, fld.getLeapDurationField());
401         assertEquals(1, fld.getMinimumValue());
402         assertEquals(1, fld.getMinimumValueOverall());
403         assertEquals(29, fld.getMaximumValue());
404         assertEquals(30, fld.getMaximumValueOverall());
405         assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
406         
407         assertEquals(DateTimeConstants.MONDAY, dt.getDayOfWeek());
408         fld = dt.dayOfWeek();
409         assertEquals(false, fld.isLeap());
410         assertEquals(0, fld.getLeapAmount());
411         assertEquals(null, fld.getLeapDurationField());
412         assertEquals(1, fld.getMinimumValue());
413         assertEquals(1, fld.getMinimumValueOverall());
414         assertEquals(7, fld.getMaximumValue());
415         assertEquals(7, fld.getMaximumValueOverall());
416         assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
417         
418         assertEquals(6 * 30 + 5 * 29 + 6, dt.getDayOfYear());
419         fld = dt.dayOfYear();
420         assertEquals(false, fld.isLeap());
421         assertEquals(0, fld.getLeapAmount());
422         assertEquals(null, fld.getLeapDurationField());
423         assertEquals(1, fld.getMinimumValue());
424         assertEquals(1, fld.getMinimumValueOverall());
425         assertEquals(354, fld.getMaximumValue());
426         assertEquals(355, fld.getMaximumValueOverall());
427         assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
428         
429         assertEquals(0, dt.getHourOfDay());
430         assertEquals(0, dt.getMinuteOfHour());
431         assertEquals(0, dt.getSecondOfMinute());
432         assertEquals(0, dt.getMillisOfSecond());
433     }
434
435     public void testSampleDate2() {
436         DateTime dt = new DateTime(2005, 11, 26, 0, 0, 0, 0, ISO_UTC);
437         dt = dt.withChronology(ISLAMIC_UTC);
438         assertEquals(IslamicChronology.AH, dt.getEra());
439         assertEquals(15, dt.getCenturyOfEra()); // TODO confirm
440
assertEquals(26, dt.getYearOfCentury());
441         assertEquals(1426, dt.getYearOfEra());
442         
443         assertEquals(1426, dt.getYear());
444         Property fld = dt.year();
445         assertEquals(true, fld.isLeap());
446         assertEquals(1, fld.getLeapAmount());
447         assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
448         
449         assertEquals(10, dt.getMonthOfYear());
450         fld = dt.monthOfYear();
451         assertEquals(false, fld.isLeap());
452         assertEquals(0, fld.getLeapAmount());
453         assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
454         assertEquals(1, fld.getMinimumValue());
455         assertEquals(1, fld.getMinimumValueOverall());
456         assertEquals(12, fld.getMaximumValue());
457         assertEquals(12, fld.getMaximumValueOverall());
458         
459         assertEquals(24, dt.getDayOfMonth());
460         fld = dt.dayOfMonth();
461         assertEquals(false, fld.isLeap());
462         assertEquals(0, fld.getLeapAmount());
463         assertEquals(null, fld.getLeapDurationField());
464         assertEquals(1, fld.getMinimumValue());
465         assertEquals(1, fld.getMinimumValueOverall());
466         assertEquals(29, fld.getMaximumValue());
467         assertEquals(30, fld.getMaximumValueOverall());
468         
469         assertEquals(DateTimeConstants.SATURDAY, dt.getDayOfWeek());
470         fld = dt.dayOfWeek();
471         assertEquals(false, fld.isLeap());
472         assertEquals(0, fld.getLeapAmount());
473         assertEquals(null, fld.getLeapDurationField());
474         assertEquals(1, fld.getMinimumValue());
475         assertEquals(1, fld.getMinimumValueOverall());
476         assertEquals(7, fld.getMaximumValue());
477         assertEquals(7, fld.getMaximumValueOverall());
478         
479         assertEquals(5 * 30 + 4 * 29 + 24, dt.getDayOfYear());
480         fld = dt.dayOfYear();
481         assertEquals(false, fld.isLeap());
482         assertEquals(0, fld.getLeapAmount());
483         assertEquals(null, fld.getLeapDurationField());
484         assertEquals(1, fld.getMinimumValue());
485         assertEquals(1, fld.getMinimumValueOverall());
486         assertEquals(355, fld.getMaximumValue());
487         assertEquals(355, fld.getMaximumValueOverall());
488         
489         assertEquals(0, dt.getHourOfDay());
490         assertEquals(0, dt.getMinuteOfHour());
491         assertEquals(0, dt.getSecondOfMinute());
492         assertEquals(0, dt.getMillisOfSecond());
493     }
494
495     public void testSampleDate3() {
496         DateTime dt = new DateTime(1426, 12, 24, 0, 0, 0, 0, ISLAMIC_UTC);
497         assertEquals(IslamicChronology.AH, dt.getEra());
498         
499         assertEquals(1426, dt.getYear());
500         Property fld = dt.year();
501         assertEquals(true, fld.isLeap());
502         assertEquals(1, fld.getLeapAmount());
503         assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
504         
505         assertEquals(12, dt.getMonthOfYear());
506         fld = dt.monthOfYear();
507         assertEquals(true, fld.isLeap());
508         assertEquals(1, fld.getLeapAmount());
509         assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
510         assertEquals(1, fld.getMinimumValue());
511         assertEquals(1, fld.getMinimumValueOverall());
512         assertEquals(12, fld.getMaximumValue());
513         assertEquals(12, fld.getMaximumValueOverall());
514         
515         assertEquals(24, dt.getDayOfMonth());
516         fld = dt.dayOfMonth();
517         assertEquals(false, fld.isLeap());
518         assertEquals(0, fld.getLeapAmount());
519         assertEquals(null, fld.getLeapDurationField());
520         assertEquals(1, fld.getMinimumValue());
521         assertEquals(1, fld.getMinimumValueOverall());
522         assertEquals(30, fld.getMaximumValue());
523         assertEquals(30, fld.getMaximumValueOverall());
524         
525         assertEquals(DateTimeConstants.TUESDAY, dt.getDayOfWeek());
526         fld = dt.dayOfWeek();
527         assertEquals(false, fld.isLeap());
528         assertEquals(0, fld.getLeapAmount());
529         assertEquals(null, fld.getLeapDurationField());
530         assertEquals(1, fld.getMinimumValue());
531         assertEquals(1, fld.getMinimumValueOverall());
532         assertEquals(7, fld.getMaximumValue());
533         assertEquals(7, fld.getMaximumValueOverall());
534         
535         assertEquals(6 * 30 + 5 * 29 + 24, dt.getDayOfYear());
536         fld = dt.dayOfYear();
537         assertEquals(false, fld.isLeap());
538         assertEquals(0, fld.getLeapAmount());
539         assertEquals(null, fld.getLeapDurationField());
540         assertEquals(1, fld.getMinimumValue());
541         assertEquals(1, fld.getMinimumValueOverall());
542         assertEquals(355, fld.getMaximumValue());
543         assertEquals(355, fld.getMaximumValueOverall());
544         
545         assertEquals(0, dt.getHourOfDay());
546         assertEquals(0, dt.getMinuteOfHour());
547         assertEquals(0, dt.getSecondOfMinute());
548         assertEquals(0, dt.getMillisOfSecond());
549     }
550
551     public void testSampleDateWithZone() {
552         DateTime dt = new DateTime(2005, 11, 26, 12, 0, 0, 0, PARIS).withChronology(ISLAMIC_UTC);
553         assertEquals(IslamicChronology.AH, dt.getEra());
554         assertEquals(1426, dt.getYear());
555         assertEquals(10, dt.getMonthOfYear());
556         assertEquals(24, dt.getDayOfMonth());
557         assertEquals(11, dt.getHourOfDay()); // PARIS is UTC+1 in summer (12-1=11)
558
assertEquals(0, dt.getMinuteOfHour());
559         assertEquals(0, dt.getSecondOfMinute());
560         assertEquals(0, dt.getMillisOfSecond());
561     }
562
563     public void test15BasedLeapYear() {
564         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(1));
565         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(2));
566         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(3));
567         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(4));
568         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(5));
569         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(6));
570         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(7));
571         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(8));
572         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(9));
573         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(10));
574         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(11));
575         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(12));
576         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(13));
577         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(14));
578         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(15));
579         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(16));
580         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(17));
581         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(18));
582         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(19));
583         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(20));
584         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(21));
585         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(22));
586         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(23));
587         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(24));
588         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(25));
589         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(26));
590         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(27));
591         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(28));
592         assertEquals(true, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(29));
593         assertEquals(false, IslamicChronology.LEAP_YEAR_15_BASED.isLeapYear(30));
594     }
595
596     public void test16BasedLeapYear() {
597         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(1));
598         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(2));
599         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(3));
600         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(4));
601         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(5));
602         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(6));
603         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(7));
604         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(8));
605         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(9));
606         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(10));
607         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(11));
608         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(12));
609         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(13));
610         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(14));
611         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(15));
612         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(16));
613         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(17));
614         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(18));
615         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(19));
616         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(20));
617         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(21));
618         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(22));
619         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(23));
620         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(24));
621         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(25));
622         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(26));
623         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(27));
624         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(28));
625         assertEquals(true, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(29));
626         assertEquals(false, IslamicChronology.LEAP_YEAR_16_BASED.isLeapYear(30));
627     }
628
629     public void testIndianBasedLeapYear() {
630         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(1));
631         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(2));
632         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(3));
633         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(4));
634         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(5));
635         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(6));
636         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(7));
637         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(8));
638         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(9));
639         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(10));
640         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(11));
641         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(12));
642         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(13));
643         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(14));
644         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(15));
645         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(16));
646         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(17));
647         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(18));
648         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(19));
649         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(20));
650         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(21));
651         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(22));
652         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(23));
653         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(24));
654         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(25));
655         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(26));
656         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(27));
657         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(28));
658         assertEquals(true, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(29));
659         assertEquals(false, IslamicChronology.LEAP_YEAR_INDIAN.isLeapYear(30));
660     }
661
662     public void testHabashAlHasibBasedLeapYear() {
663         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(1));
664         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(2));
665         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(3));
666         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(4));
667         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(5));
668         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(6));
669         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(7));
670         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(8));
671         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(9));
672         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(10));
673         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(11));
674         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(12));
675         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(13));
676         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(14));
677         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(15));
678         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(16));
679         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(17));
680         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(18));
681         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(19));
682         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(20));
683         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(21));
684         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(22));
685         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(23));
686         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(24));
687         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(25));
688         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(26));
689         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(27));
690         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(28));
691         assertEquals(false, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(29));
692         assertEquals(true, IslamicChronology.LEAP_YEAR_HABASH_AL_HASIB.isLeapYear(30));
693     }
694
695 }
696
Popular Tags