View Javadoc

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;
19  import java.util.TimeZone;
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.DurationField;
31  import org.joda.time.DurationFieldType;
32  import org.joda.time.DateTime.Property;
33  
34  /**
35   * This class is a Junit unit test for EthiopicChronology.
36   *
37   * @author Stephen Colebourne
38   */
39  public class TestEthiopicChronology extends TestCase {
40  
41      private static final int MILLIS_PER_DAY = DateTimeConstants.MILLIS_PER_DAY;
42  
43      private static long SKIP = 1 * MILLIS_PER_DAY;
44  
45      private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
46      private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
47      private static final DateTimeZone TOKYO = DateTimeZone.forID("Asia/Tokyo");
48      private static final Chronology ETHIOPIC_UTC = EthiopicChronology.getInstanceUTC();
49      private static final Chronology JULIAN_UTC = JulianChronology.getInstanceUTC();
50      private static final Chronology ISO_UTC = ISOChronology.getInstanceUTC();
51  
52      long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
53                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
54                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
55                       366 + 365;
56      // 2002-06-09
57      private long TEST_TIME_NOW =
58              (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * MILLIS_PER_DAY;
59  
60      private DateTimeZone originalDateTimeZone = null;
61      private TimeZone originalTimeZone = null;
62      private Locale originalLocale = null;
63  
64      public static void main(String[] args) {
65          junit.textui.TestRunner.run(suite());
66      }
67  
68      public static TestSuite suite() {
69          SKIP = 1 * MILLIS_PER_DAY;
70          return new TestSuite(TestEthiopicChronology.class);
71      }
72  
73      public TestEthiopicChronology(String name) {
74          super(name);
75      }
76  
77      protected void setUp() throws Exception {
78          DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
79          originalDateTimeZone = DateTimeZone.getDefault();
80          originalTimeZone = TimeZone.getDefault();
81          originalLocale = Locale.getDefault();
82          DateTimeZone.setDefault(LONDON);
83          TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
84          Locale.setDefault(Locale.UK);
85      }
86  
87      protected void tearDown() throws Exception {
88          DateTimeUtils.setCurrentMillisSystem();
89          DateTimeZone.setDefault(originalDateTimeZone);
90          TimeZone.setDefault(originalTimeZone);
91          Locale.setDefault(originalLocale);
92          originalDateTimeZone = null;
93          originalTimeZone = null;
94          originalLocale = null;
95      }
96  
97      //-----------------------------------------------------------------------
98      public void testFactoryUTC() {
99          assertEquals(DateTimeZone.UTC, EthiopicChronology.getInstanceUTC().getZone());
100         assertSame(EthiopicChronology.class, EthiopicChronology.getInstanceUTC().getClass());
101     }
102 
103     public void testFactory() {
104         assertEquals(LONDON, EthiopicChronology.getInstance().getZone());
105         assertSame(EthiopicChronology.class, EthiopicChronology.getInstance().getClass());
106     }
107 
108     public void testFactory_Zone() {
109         assertEquals(TOKYO, EthiopicChronology.getInstance(TOKYO).getZone());
110         assertEquals(PARIS, EthiopicChronology.getInstance(PARIS).getZone());
111         assertEquals(LONDON, EthiopicChronology.getInstance(null).getZone());
112         assertSame(EthiopicChronology.class, EthiopicChronology.getInstance(TOKYO).getClass());
113     }
114 
115     //-----------------------------------------------------------------------
116     public void testEquality() {
117         assertSame(EthiopicChronology.getInstance(TOKYO), EthiopicChronology.getInstance(TOKYO));
118         assertSame(EthiopicChronology.getInstance(LONDON), EthiopicChronology.getInstance(LONDON));
119         assertSame(EthiopicChronology.getInstance(PARIS), EthiopicChronology.getInstance(PARIS));
120         assertSame(EthiopicChronology.getInstanceUTC(), EthiopicChronology.getInstanceUTC());
121         assertSame(EthiopicChronology.getInstance(), EthiopicChronology.getInstance(LONDON));
122     }
123 
124     public void testWithUTC() {
125         assertSame(EthiopicChronology.getInstanceUTC(), EthiopicChronology.getInstance(LONDON).withUTC());
126         assertSame(EthiopicChronology.getInstanceUTC(), EthiopicChronology.getInstance(TOKYO).withUTC());
127         assertSame(EthiopicChronology.getInstanceUTC(), EthiopicChronology.getInstanceUTC().withUTC());
128         assertSame(EthiopicChronology.getInstanceUTC(), EthiopicChronology.getInstance().withUTC());
129     }
130 
131     public void testWithZone() {
132         assertSame(EthiopicChronology.getInstance(TOKYO), EthiopicChronology.getInstance(TOKYO).withZone(TOKYO));
133         assertSame(EthiopicChronology.getInstance(LONDON), EthiopicChronology.getInstance(TOKYO).withZone(LONDON));
134         assertSame(EthiopicChronology.getInstance(PARIS), EthiopicChronology.getInstance(TOKYO).withZone(PARIS));
135         assertSame(EthiopicChronology.getInstance(LONDON), EthiopicChronology.getInstance(TOKYO).withZone(null));
136         assertSame(EthiopicChronology.getInstance(PARIS), EthiopicChronology.getInstance().withZone(PARIS));
137         assertSame(EthiopicChronology.getInstance(PARIS), EthiopicChronology.getInstanceUTC().withZone(PARIS));
138     }
139 
140     public void testToString() {
141         assertEquals("EthiopicChronology[Europe/London]", EthiopicChronology.getInstance(LONDON).toString());
142         assertEquals("EthiopicChronology[Asia/Tokyo]", EthiopicChronology.getInstance(TOKYO).toString());
143         assertEquals("EthiopicChronology[Europe/London]", EthiopicChronology.getInstance().toString());
144         assertEquals("EthiopicChronology[UTC]", EthiopicChronology.getInstanceUTC().toString());
145     }
146 
147     //-----------------------------------------------------------------------
148     public void testDurationFields() {
149         assertEquals("eras", EthiopicChronology.getInstance().eras().getName());
150         assertEquals("centuries", EthiopicChronology.getInstance().centuries().getName());
151         assertEquals("years", EthiopicChronology.getInstance().years().getName());
152         assertEquals("weekyears", EthiopicChronology.getInstance().weekyears().getName());
153         assertEquals("months", EthiopicChronology.getInstance().months().getName());
154         assertEquals("weeks", EthiopicChronology.getInstance().weeks().getName());
155         assertEquals("days", EthiopicChronology.getInstance().days().getName());
156         assertEquals("halfdays", EthiopicChronology.getInstance().halfdays().getName());
157         assertEquals("hours", EthiopicChronology.getInstance().hours().getName());
158         assertEquals("minutes", EthiopicChronology.getInstance().minutes().getName());
159         assertEquals("seconds", EthiopicChronology.getInstance().seconds().getName());
160         assertEquals("millis", EthiopicChronology.getInstance().millis().getName());
161         
162         assertEquals(false, EthiopicChronology.getInstance().eras().isSupported());
163         assertEquals(true, EthiopicChronology.getInstance().centuries().isSupported());
164         assertEquals(true, EthiopicChronology.getInstance().years().isSupported());
165         assertEquals(true, EthiopicChronology.getInstance().weekyears().isSupported());
166         assertEquals(true, EthiopicChronology.getInstance().months().isSupported());
167         assertEquals(true, EthiopicChronology.getInstance().weeks().isSupported());
168         assertEquals(true, EthiopicChronology.getInstance().days().isSupported());
169         assertEquals(true, EthiopicChronology.getInstance().halfdays().isSupported());
170         assertEquals(true, EthiopicChronology.getInstance().hours().isSupported());
171         assertEquals(true, EthiopicChronology.getInstance().minutes().isSupported());
172         assertEquals(true, EthiopicChronology.getInstance().seconds().isSupported());
173         assertEquals(true, EthiopicChronology.getInstance().millis().isSupported());
174         
175         assertEquals(false, EthiopicChronology.getInstance().centuries().isPrecise());
176         assertEquals(false, EthiopicChronology.getInstance().years().isPrecise());
177         assertEquals(false, EthiopicChronology.getInstance().weekyears().isPrecise());
178         assertEquals(false, EthiopicChronology.getInstance().months().isPrecise());
179         assertEquals(false, EthiopicChronology.getInstance().weeks().isPrecise());
180         assertEquals(false, EthiopicChronology.getInstance().days().isPrecise());
181         assertEquals(false, EthiopicChronology.getInstance().halfdays().isPrecise());
182         assertEquals(true, EthiopicChronology.getInstance().hours().isPrecise());
183         assertEquals(true, EthiopicChronology.getInstance().minutes().isPrecise());
184         assertEquals(true, EthiopicChronology.getInstance().seconds().isPrecise());
185         assertEquals(true, EthiopicChronology.getInstance().millis().isPrecise());
186         
187         assertEquals(false, EthiopicChronology.getInstanceUTC().centuries().isPrecise());
188         assertEquals(false, EthiopicChronology.getInstanceUTC().years().isPrecise());
189         assertEquals(false, EthiopicChronology.getInstanceUTC().weekyears().isPrecise());
190         assertEquals(false, EthiopicChronology.getInstanceUTC().months().isPrecise());
191         assertEquals(true, EthiopicChronology.getInstanceUTC().weeks().isPrecise());
192         assertEquals(true, EthiopicChronology.getInstanceUTC().days().isPrecise());
193         assertEquals(true, EthiopicChronology.getInstanceUTC().halfdays().isPrecise());
194         assertEquals(true, EthiopicChronology.getInstanceUTC().hours().isPrecise());
195         assertEquals(true, EthiopicChronology.getInstanceUTC().minutes().isPrecise());
196         assertEquals(true, EthiopicChronology.getInstanceUTC().seconds().isPrecise());
197         assertEquals(true, EthiopicChronology.getInstanceUTC().millis().isPrecise());
198         
199         DateTimeZone gmt = DateTimeZone.forID("Etc/GMT");
200         assertEquals(false, EthiopicChronology.getInstance(gmt).centuries().isPrecise());
201         assertEquals(false, EthiopicChronology.getInstance(gmt).years().isPrecise());
202         assertEquals(false, EthiopicChronology.getInstance(gmt).weekyears().isPrecise());
203         assertEquals(false, EthiopicChronology.getInstance(gmt).months().isPrecise());
204         assertEquals(true, EthiopicChronology.getInstance(gmt).weeks().isPrecise());
205         assertEquals(true, EthiopicChronology.getInstance(gmt).days().isPrecise());
206         assertEquals(true, EthiopicChronology.getInstance(gmt).halfdays().isPrecise());
207         assertEquals(true, EthiopicChronology.getInstance(gmt).hours().isPrecise());
208         assertEquals(true, EthiopicChronology.getInstance(gmt).minutes().isPrecise());
209         assertEquals(true, EthiopicChronology.getInstance(gmt).seconds().isPrecise());
210         assertEquals(true, EthiopicChronology.getInstance(gmt).millis().isPrecise());
211     }
212 
213     public void testDateFields() {
214         assertEquals("era", EthiopicChronology.getInstance().era().getName());
215         assertEquals("centuryOfEra", EthiopicChronology.getInstance().centuryOfEra().getName());
216         assertEquals("yearOfCentury", EthiopicChronology.getInstance().yearOfCentury().getName());
217         assertEquals("yearOfEra", EthiopicChronology.getInstance().yearOfEra().getName());
218         assertEquals("year", EthiopicChronology.getInstance().year().getName());
219         assertEquals("monthOfYear", EthiopicChronology.getInstance().monthOfYear().getName());
220         assertEquals("weekyearOfCentury", EthiopicChronology.getInstance().weekyearOfCentury().getName());
221         assertEquals("weekyear", EthiopicChronology.getInstance().weekyear().getName());
222         assertEquals("weekOfWeekyear", EthiopicChronology.getInstance().weekOfWeekyear().getName());
223         assertEquals("dayOfYear", EthiopicChronology.getInstance().dayOfYear().getName());
224         assertEquals("dayOfMonth", EthiopicChronology.getInstance().dayOfMonth().getName());
225         assertEquals("dayOfWeek", EthiopicChronology.getInstance().dayOfWeek().getName());
226         
227         assertEquals(true, EthiopicChronology.getInstance().era().isSupported());
228         assertEquals(true, EthiopicChronology.getInstance().centuryOfEra().isSupported());
229         assertEquals(true, EthiopicChronology.getInstance().yearOfCentury().isSupported());
230         assertEquals(true, EthiopicChronology.getInstance().yearOfEra().isSupported());
231         assertEquals(true, EthiopicChronology.getInstance().year().isSupported());
232         assertEquals(true, EthiopicChronology.getInstance().monthOfYear().isSupported());
233         assertEquals(true, EthiopicChronology.getInstance().weekyearOfCentury().isSupported());
234         assertEquals(true, EthiopicChronology.getInstance().weekyear().isSupported());
235         assertEquals(true, EthiopicChronology.getInstance().weekOfWeekyear().isSupported());
236         assertEquals(true, EthiopicChronology.getInstance().dayOfYear().isSupported());
237         assertEquals(true, EthiopicChronology.getInstance().dayOfMonth().isSupported());
238         assertEquals(true, EthiopicChronology.getInstance().dayOfWeek().isSupported());
239     }
240 
241     public void testTimeFields() {
242         assertEquals("halfdayOfDay", EthiopicChronology.getInstance().halfdayOfDay().getName());
243         assertEquals("clockhourOfHalfday", EthiopicChronology.getInstance().clockhourOfHalfday().getName());
244         assertEquals("hourOfHalfday", EthiopicChronology.getInstance().hourOfHalfday().getName());
245         assertEquals("clockhourOfDay", EthiopicChronology.getInstance().clockhourOfDay().getName());
246         assertEquals("hourOfDay", EthiopicChronology.getInstance().hourOfDay().getName());
247         assertEquals("minuteOfDay", EthiopicChronology.getInstance().minuteOfDay().getName());
248         assertEquals("minuteOfHour", EthiopicChronology.getInstance().minuteOfHour().getName());
249         assertEquals("secondOfDay", EthiopicChronology.getInstance().secondOfDay().getName());
250         assertEquals("secondOfMinute", EthiopicChronology.getInstance().secondOfMinute().getName());
251         assertEquals("millisOfDay", EthiopicChronology.getInstance().millisOfDay().getName());
252         assertEquals("millisOfSecond", EthiopicChronology.getInstance().millisOfSecond().getName());
253         
254         assertEquals(true, EthiopicChronology.getInstance().halfdayOfDay().isSupported());
255         assertEquals(true, EthiopicChronology.getInstance().clockhourOfHalfday().isSupported());
256         assertEquals(true, EthiopicChronology.getInstance().hourOfHalfday().isSupported());
257         assertEquals(true, EthiopicChronology.getInstance().clockhourOfDay().isSupported());
258         assertEquals(true, EthiopicChronology.getInstance().hourOfDay().isSupported());
259         assertEquals(true, EthiopicChronology.getInstance().minuteOfDay().isSupported());
260         assertEquals(true, EthiopicChronology.getInstance().minuteOfHour().isSupported());
261         assertEquals(true, EthiopicChronology.getInstance().secondOfDay().isSupported());
262         assertEquals(true, EthiopicChronology.getInstance().secondOfMinute().isSupported());
263         assertEquals(true, EthiopicChronology.getInstance().millisOfDay().isSupported());
264         assertEquals(true, EthiopicChronology.getInstance().millisOfSecond().isSupported());
265     }
266 
267     //-----------------------------------------------------------------------
268     public void testEpoch() {
269         DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ETHIOPIC_UTC);
270         assertEquals(new DateTime(8, 8, 29, 0, 0, 0, 0, JULIAN_UTC), epoch.withChronology(JULIAN_UTC));
271     }
272 
273     public void testEra() {
274         assertEquals(1, EthiopicChronology.EE);
275         try {
276             new DateTime(-1, 13, 5, 0, 0, 0, 0, ETHIOPIC_UTC);
277             fail();
278         } catch (IllegalArgumentException ex) {}
279     }
280 
281     //-----------------------------------------------------------------------
282     /**
283      * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
284      */
285     public void testCalendar() {
286         if (TestAll.FAST) {
287             return;
288         }
289         System.out.println("\nTestEthiopicChronology.testCalendar");
290         DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ETHIOPIC_UTC);
291         long millis = epoch.getMillis();
292         long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis();
293         DateTimeField dayOfWeek = ETHIOPIC_UTC.dayOfWeek();
294         DateTimeField dayOfYear = ETHIOPIC_UTC.dayOfYear();
295         DateTimeField dayOfMonth = ETHIOPIC_UTC.dayOfMonth();
296         DateTimeField monthOfYear = ETHIOPIC_UTC.monthOfYear();
297         DateTimeField year = ETHIOPIC_UTC.year();
298         DateTimeField yearOfEra = ETHIOPIC_UTC.yearOfEra();
299         DateTimeField era = ETHIOPIC_UTC.era();
300         int expectedDOW = new DateTime(8, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek();
301         int expectedDOY = 1;
302         int expectedDay = 1;
303         int expectedMonth = 1;
304         int expectedYear = 1;
305         while (millis < end) {
306             int dowValue = dayOfWeek.get(millis);
307             int doyValue = dayOfYear.get(millis);
308             int dayValue = dayOfMonth.get(millis);
309             int monthValue = monthOfYear.get(millis);
310             int yearValue = year.get(millis);
311             int yearOfEraValue = yearOfEra.get(millis);
312             int monthLen = dayOfMonth.getMaximumValue(millis);
313             if (monthValue < 1 || monthValue > 13) {
314                 fail("Bad month: " + millis);
315             }
316             
317             // test era
318             assertEquals(1, era.get(millis));
319             assertEquals("EE", era.getAsText(millis));
320             assertEquals("EE", era.getAsShortText(millis));
321             
322             // test date
323             assertEquals(expectedYear, yearValue);
324             assertEquals(expectedYear, yearOfEraValue);
325             assertEquals(expectedMonth, monthValue);
326             assertEquals(expectedDay, dayValue);
327             assertEquals(expectedDOW, dowValue);
328             assertEquals(expectedDOY, doyValue);
329             
330             // test leap year
331             assertEquals(yearValue % 4 == 3, year.isLeap(millis));
332             
333             // test month length
334             if (monthValue == 13) {
335                 assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis));
336                 if (yearValue % 4 == 3) {
337                     assertEquals(6, monthLen);
338                 } else {
339                     assertEquals(5, monthLen);
340                 }
341             } else {
342                 assertEquals(30, monthLen);
343             }
344             
345             // recalculate date
346             expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
347             expectedDay++;
348             expectedDOY++;
349             if (expectedDay == 31 && expectedMonth < 13) {
350                 expectedDay = 1;
351                 expectedMonth++;
352             } else if (expectedMonth == 13) {
353                 if (expectedYear % 4 == 3 && expectedDay == 7) {
354                     expectedDay = 1;
355                     expectedMonth = 1;
356                     expectedYear++;
357                     expectedDOY = 1;
358                 } else if (expectedYear % 4 != 3 && expectedDay == 6) {
359                     expectedDay = 1;
360                     expectedMonth = 1;
361                     expectedYear++;
362                     expectedDOY = 1;
363                 }
364             }
365             millis += SKIP;
366         }
367     }
368 
369     public void testSampleDate() {
370         DateTime dt = new DateTime(2004, 6, 9, 0, 0, 0, 0, ISO_UTC).withChronology(ETHIOPIC_UTC);
371         assertEquals(EthiopicChronology.EE, dt.getEra());
372         assertEquals(20, dt.getCenturyOfEra());  // TODO confirm
373         assertEquals(96, dt.getYearOfCentury());
374         assertEquals(1996, dt.getYearOfEra());
375         
376         assertEquals(1996, dt.getYear());
377         Property fld = dt.year();
378         assertEquals(false, fld.isLeap());
379         assertEquals(0, fld.getLeapAmount());
380         assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
381         assertEquals(new DateTime(1997, 10, 2, 0, 0, 0, 0, ETHIOPIC_UTC), fld.addToCopy(1));
382         
383         assertEquals(10, dt.getMonthOfYear());
384         fld = dt.monthOfYear();
385         assertEquals(false, fld.isLeap());
386         assertEquals(0, fld.getLeapAmount());
387         assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
388         assertEquals(1, fld.getMinimumValue());
389         assertEquals(1, fld.getMinimumValueOverall());
390         assertEquals(13, fld.getMaximumValue());
391         assertEquals(13, fld.getMaximumValueOverall());
392         assertEquals(new DateTime(1997, 1, 2, 0, 0, 0, 0, ETHIOPIC_UTC), fld.addToCopy(4));
393         assertEquals(new DateTime(1996, 1, 2, 0, 0, 0, 0, ETHIOPIC_UTC), fld.addWrapFieldToCopy(4));
394         
395         assertEquals(2, dt.getDayOfMonth());
396         fld = dt.dayOfMonth();
397         assertEquals(false, fld.isLeap());
398         assertEquals(0, fld.getLeapAmount());
399         assertEquals(null, fld.getLeapDurationField());
400         assertEquals(1, fld.getMinimumValue());
401         assertEquals(1, fld.getMinimumValueOverall());
402         assertEquals(30, fld.getMaximumValue());
403         assertEquals(30, fld.getMaximumValueOverall());
404         assertEquals(new DateTime(1996, 10, 3, 0, 0, 0, 0, ETHIOPIC_UTC), fld.addToCopy(1));
405         
406         assertEquals(DateTimeConstants.WEDNESDAY, dt.getDayOfWeek());
407         fld = dt.dayOfWeek();
408         assertEquals(false, fld.isLeap());
409         assertEquals(0, fld.getLeapAmount());
410         assertEquals(null, fld.getLeapDurationField());
411         assertEquals(1, fld.getMinimumValue());
412         assertEquals(1, fld.getMinimumValueOverall());
413         assertEquals(7, fld.getMaximumValue());
414         assertEquals(7, fld.getMaximumValueOverall());
415         assertEquals(new DateTime(1996, 10, 3, 0, 0, 0, 0, ETHIOPIC_UTC), fld.addToCopy(1));
416         
417         assertEquals(9 * 30 + 2, dt.getDayOfYear());
418         fld = dt.dayOfYear();
419         assertEquals(false, fld.isLeap());
420         assertEquals(0, fld.getLeapAmount());
421         assertEquals(null, fld.getLeapDurationField());
422         assertEquals(1, fld.getMinimumValue());
423         assertEquals(1, fld.getMinimumValueOverall());
424         assertEquals(365, fld.getMaximumValue());
425         assertEquals(366, fld.getMaximumValueOverall());
426         assertEquals(new DateTime(1996, 10, 3, 0, 0, 0, 0, ETHIOPIC_UTC), fld.addToCopy(1));
427         
428         assertEquals(0, dt.getHourOfDay());
429         assertEquals(0, dt.getMinuteOfHour());
430         assertEquals(0, dt.getSecondOfMinute());
431         assertEquals(0, dt.getMillisOfSecond());
432     }
433 
434     public void testSampleDateWithZone() {
435         DateTime dt = new DateTime(2004, 6, 9, 12, 0, 0, 0, PARIS).withChronology(ETHIOPIC_UTC);
436         assertEquals(EthiopicChronology.EE, dt.getEra());
437         assertEquals(1996, dt.getYear());
438         assertEquals(1996, dt.getYearOfEra());
439         assertEquals(10, dt.getMonthOfYear());
440         assertEquals(2, dt.getDayOfMonth());
441         assertEquals(10, dt.getHourOfDay());  // PARIS is UTC+2 in summer (12-2=10)
442         assertEquals(0, dt.getMinuteOfHour());
443         assertEquals(0, dt.getSecondOfMinute());
444         assertEquals(0, dt.getMillisOfSecond());
445     }
446 
447     public void testDurationYear() {
448         // Leap 1999, NotLeap 1996,97,98
449         DateTime dt96 = new DateTime(1996, 10, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
450         DateTime dt97 = new DateTime(1997, 10, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
451         DateTime dt98 = new DateTime(1998, 10, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
452         DateTime dt99 = new DateTime(1999, 10, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
453         DateTime dt00 = new DateTime(2000, 10, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
454         
455         DurationField fld = dt96.year().getDurationField();
456         assertEquals(ETHIOPIC_UTC.years(), fld);
457         assertEquals(1L * 365L * MILLIS_PER_DAY, fld.getMillis(1, dt96.getMillis()));
458         assertEquals(2L * 365L * MILLIS_PER_DAY, fld.getMillis(2, dt96.getMillis()));
459         assertEquals(3L * 365L * MILLIS_PER_DAY, fld.getMillis(3, dt96.getMillis()));
460         assertEquals((4L * 365L + 1L) * MILLIS_PER_DAY, fld.getMillis(4, dt96.getMillis()));
461         
462         assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 4, fld.getMillis(1));
463         assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 2, fld.getMillis(2));
464         
465         assertEquals(1L * 365L * MILLIS_PER_DAY, fld.getMillis(1L, dt96.getMillis()));
466         assertEquals(2L * 365L * MILLIS_PER_DAY, fld.getMillis(2L, dt96.getMillis()));
467         assertEquals(3L * 365L * MILLIS_PER_DAY, fld.getMillis(3L, dt96.getMillis()));
468         assertEquals((4L * 365L + 1L) * MILLIS_PER_DAY, fld.getMillis(4L, dt96.getMillis()));
469         
470         assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 4, fld.getMillis(1L));
471         assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 2, fld.getMillis(2L));
472         
473         assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 4, fld.getUnitMillis());
474         
475         assertEquals(0, fld.getValue(1L * 365L * MILLIS_PER_DAY - 1L, dt96.getMillis()));
476         assertEquals(1, fld.getValue(1L * 365L * MILLIS_PER_DAY, dt96.getMillis()));
477         assertEquals(1, fld.getValue(1L * 365L * MILLIS_PER_DAY + 1L, dt96.getMillis()));
478         assertEquals(1, fld.getValue(2L * 365L * MILLIS_PER_DAY - 1L, dt96.getMillis()));
479         assertEquals(2, fld.getValue(2L * 365L * MILLIS_PER_DAY, dt96.getMillis()));
480         assertEquals(2, fld.getValue(2L * 365L * MILLIS_PER_DAY + 1L, dt96.getMillis()));
481         assertEquals(2, fld.getValue(3L * 365L * MILLIS_PER_DAY - 1L, dt96.getMillis()));
482         assertEquals(3, fld.getValue(3L * 365L * MILLIS_PER_DAY, dt96.getMillis()));
483         assertEquals(3, fld.getValue(3L * 365L * MILLIS_PER_DAY + 1L, dt96.getMillis()));
484         assertEquals(3, fld.getValue((4L * 365L + 1L) * MILLIS_PER_DAY - 1L, dt96.getMillis()));
485         assertEquals(4, fld.getValue((4L * 365L + 1L) * MILLIS_PER_DAY, dt96.getMillis()));
486         assertEquals(4, fld.getValue((4L * 365L + 1L) * MILLIS_PER_DAY + 1L, dt96.getMillis()));
487         
488         assertEquals(dt97.getMillis(), fld.add(dt96.getMillis(), 1));
489         assertEquals(dt98.getMillis(), fld.add(dt96.getMillis(), 2));
490         assertEquals(dt99.getMillis(), fld.add(dt96.getMillis(), 3));
491         assertEquals(dt00.getMillis(), fld.add(dt96.getMillis(), 4));
492         
493         assertEquals(dt97.getMillis(), fld.add(dt96.getMillis(), 1L));
494         assertEquals(dt98.getMillis(), fld.add(dt96.getMillis(), 2L));
495         assertEquals(dt99.getMillis(), fld.add(dt96.getMillis(), 3L));
496         assertEquals(dt00.getMillis(), fld.add(dt96.getMillis(), 4L));
497     }
498 
499     public void testDurationMonth() {
500         // Leap 1999, NotLeap 1996,97,98
501         DateTime dt11 = new DateTime(1999, 11, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
502         DateTime dt12 = new DateTime(1999, 12, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
503         DateTime dt13 = new DateTime(1999, 13, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
504         DateTime dt01 = new DateTime(2000, 1, 2, 0, 0, 0, 0, ETHIOPIC_UTC);
505         
506         DurationField fld = dt11.monthOfYear().getDurationField();
507         assertEquals(ETHIOPIC_UTC.months(), fld);
508         assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1, dt11.getMillis()));
509         assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2, dt11.getMillis()));
510         assertEquals((2L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(3, dt11.getMillis()));
511         assertEquals((3L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(4, dt11.getMillis()));
512         
513         assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1));
514         assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2));
515         assertEquals(13L * 30L * MILLIS_PER_DAY, fld.getMillis(13));
516         
517         assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1L, dt11.getMillis()));
518         assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2L, dt11.getMillis()));
519         assertEquals((2L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(3L, dt11.getMillis()));
520         assertEquals((3L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(4L, dt11.getMillis()));
521         
522         assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1L));
523         assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2L));
524         assertEquals(13L * 30L * MILLIS_PER_DAY, fld.getMillis(13L));
525         
526         assertEquals(0, fld.getValue(1L * 30L * MILLIS_PER_DAY - 1L, dt11.getMillis()));
527         assertEquals(1, fld.getValue(1L * 30L * MILLIS_PER_DAY, dt11.getMillis()));
528         assertEquals(1, fld.getValue(1L * 30L * MILLIS_PER_DAY + 1L, dt11.getMillis()));
529         assertEquals(1, fld.getValue(2L * 30L * MILLIS_PER_DAY - 1L, dt11.getMillis()));
530         assertEquals(2, fld.getValue(2L * 30L * MILLIS_PER_DAY, dt11.getMillis()));
531         assertEquals(2, fld.getValue(2L * 30L * MILLIS_PER_DAY + 1L, dt11.getMillis()));
532         assertEquals(2, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY - 1L, dt11.getMillis()));
533         assertEquals(3, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY, dt11.getMillis()));
534         assertEquals(3, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY + 1L, dt11.getMillis()));
535         assertEquals(3, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY - 1L, dt11.getMillis()));
536         assertEquals(4, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY, dt11.getMillis()));
537         assertEquals(4, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY + 1L, dt11.getMillis()));
538         
539         assertEquals(dt12.getMillis(), fld.add(dt11.getMillis(), 1));
540         assertEquals(dt13.getMillis(), fld.add(dt11.getMillis(), 2));
541         assertEquals(dt01.getMillis(), fld.add(dt11.getMillis(), 3));
542         
543         assertEquals(dt12.getMillis(), fld.add(dt11.getMillis(), 1L));
544         assertEquals(dt13.getMillis(), fld.add(dt11.getMillis(), 2L));
545         assertEquals(dt01.getMillis(), fld.add(dt11.getMillis(), 3L));
546     }
547 
548 }