View Javadoc

1   /*
2    *  Copyright 2001-2007 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;
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.chrono.CopticChronology;
25  import org.joda.time.chrono.ISOChronology;
26  
27  /**
28   * This class is a JUnit test for Duration.
29   *
30   * @author Stephen Colebourne
31   */
32  public class TestPeriod_Constructors extends TestCase {
33      // Test in 2002/03 as time zones are more well known
34      // (before the late 90's they were all over the place)
35  
36      private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
37      
38      long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
39                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
40                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
41                       366 + 365;
42      long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
43                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
44                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
45                       366 + 365 + 365;
46      
47      // 2002-06-09
48      private long TEST_TIME_NOW =
49              (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
50              
51      private DateTimeZone originalDateTimeZone = null;
52      private TimeZone originalTimeZone = null;
53      private Locale originalLocale = null;
54  
55      public static void main(String[] args) {
56          junit.textui.TestRunner.run(suite());
57      }
58  
59      public static TestSuite suite() {
60          return new TestSuite(TestPeriod_Constructors.class);
61      }
62  
63      public TestPeriod_Constructors(String name) {
64          super(name);
65      }
66  
67      protected void setUp() throws Exception {
68          DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
69          originalDateTimeZone = DateTimeZone.getDefault();
70          originalTimeZone = TimeZone.getDefault();
71          originalLocale = Locale.getDefault();
72          DateTimeZone.setDefault(LONDON);
73          TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
74          Locale.setDefault(Locale.UK);
75      }
76  
77      protected void tearDown() throws Exception {
78          DateTimeUtils.setCurrentMillisSystem();
79          DateTimeZone.setDefault(originalDateTimeZone);
80          TimeZone.setDefault(originalTimeZone);
81          Locale.setDefault(originalLocale);
82          originalDateTimeZone = null;
83          originalTimeZone = null;
84          originalLocale = null;
85      }
86  
87      //-----------------------------------------------------------------------
88      public void testConstants() throws Throwable {
89          Period test = Period.ZERO;
90          assertEquals(PeriodType.standard(), test.getPeriodType());
91          assertEquals(0, test.getYears());
92          assertEquals(0, test.getMonths());
93          assertEquals(0, test.getWeeks());
94          assertEquals(0, test.getDays());
95          assertEquals(0, test.getHours());
96          assertEquals(0, test.getMinutes());
97          assertEquals(0, test.getSeconds());
98          assertEquals(0, test.getMillis());
99      }
100 
101     //-----------------------------------------------------------------------
102     public void testParse_noFormatter() throws Throwable {
103         assertEquals(new Period(1, 2, 3, 4, 5, 6, 7, 890), Period.parse("P1Y2M3W4DT5H6M7.890S"));
104     }
105 
106     //-----------------------------------------------------------------------
107     public void testConstructor1() throws Throwable {
108         Period test = new Period();
109         assertEquals(PeriodType.standard(), test.getPeriodType());
110         assertEquals(0, test.getYears());
111         assertEquals(0, test.getMonths());
112         assertEquals(0, test.getWeeks());
113         assertEquals(0, test.getDays());
114         assertEquals(0, test.getHours());
115         assertEquals(0, test.getMinutes());
116         assertEquals(0, test.getSeconds());
117         assertEquals(0, test.getMillis());
118     }
119 
120     //-----------------------------------------------------------------------
121     public void testConstructor_long1() throws Throwable {
122         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
123                 5 * DateTimeConstants.MILLIS_PER_HOUR +
124                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
125                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
126         Period test = new Period(length);
127         assertEquals(PeriodType.standard(), test.getPeriodType());
128         assertEquals(0, test.getYears());
129         assertEquals(0, test.getMonths());
130         assertEquals(0, test.getWeeks());
131         assertEquals(0, test.getDays());
132         assertEquals((4 * 24) + 5, test.getHours());
133         assertEquals(6, test.getMinutes());
134         assertEquals(7, test.getSeconds());
135         assertEquals(8, test.getMillis());
136     }
137 
138     public void testConstructor_long2() throws Throwable {
139         long length =
140                 5 * DateTimeConstants.MILLIS_PER_HOUR +
141                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
142                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
143         Period test = new Period(length);
144         assertEquals(PeriodType.standard(), test.getPeriodType());
145         assertEquals(0, test.getYears());
146         assertEquals(0, test.getMonths());
147         assertEquals(0, test.getWeeks());
148         assertEquals(0, test.getDays());
149         assertEquals(5, test.getHours());
150         assertEquals(6, test.getMinutes());
151         assertEquals(7, test.getSeconds());
152         assertEquals(8, test.getMillis());
153     }
154 
155     public void testConstructor_long3() throws Throwable {
156         long length =
157             (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
158             5L * DateTimeConstants.MILLIS_PER_HOUR +
159             6L * DateTimeConstants.MILLIS_PER_MINUTE +
160             7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
161         Period test = new Period(length);
162         assertEquals(PeriodType.standard(), test.getPeriodType());
163         // only time fields are precise in AllType
164         assertEquals(0, test.getYears());  // (4 + (3 * 7) + (2 * 30) + 365) == 450
165         assertEquals(0, test.getMonths());
166         assertEquals(0, test.getWeeks());
167         assertEquals(0, test.getDays());
168         assertEquals((450 * 24) + 5, test.getHours());
169         assertEquals(6, test.getMinutes());
170         assertEquals(7, test.getSeconds());
171         assertEquals(8, test.getMillis());
172     }
173 
174     public void testConstructor_long_fixedZone() throws Throwable {
175         DateTimeZone zone = DateTimeZone.getDefault();
176         try {
177             DateTimeZone.setDefault(DateTimeZone.forOffsetHours(2));
178             long length =
179                 (4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
180                 5L * DateTimeConstants.MILLIS_PER_HOUR +
181                 6L * DateTimeConstants.MILLIS_PER_MINUTE +
182                 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
183             Period test = new Period(length);
184             assertEquals(PeriodType.standard(), test.getPeriodType());
185             // only time fields are precise in AllType
186             assertEquals(0, test.getYears());  // (4 + (3 * 7) + (2 * 30) + 365) == 450
187             assertEquals(0, test.getMonths());
188             assertEquals(0, test.getWeeks());
189             assertEquals(0, test.getDays());
190             assertEquals((450 * 24) + 5, test.getHours());
191             assertEquals(6, test.getMinutes());
192             assertEquals(7, test.getSeconds());
193             assertEquals(8, test.getMillis());
194         } finally {
195             DateTimeZone.setDefault(zone);
196         }
197     }
198 
199     //-----------------------------------------------------------------------
200     public void testConstructor_long_PeriodType1() throws Throwable {
201         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
202                 5 * DateTimeConstants.MILLIS_PER_HOUR +
203                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
204                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
205         Period test = new Period(length, (PeriodType) null);
206         assertEquals(PeriodType.standard(), test.getPeriodType());
207         assertEquals(0, test.getYears());
208         assertEquals(0, test.getMonths());
209         assertEquals(0, test.getWeeks());
210         assertEquals(0, test.getDays());
211         assertEquals((4 * 24) + 5, test.getHours());
212         assertEquals(6, test.getMinutes());
213         assertEquals(7, test.getSeconds());
214         assertEquals(8, test.getMillis());
215     }
216 
217     public void testConstructor_long_PeriodType2() throws Throwable {
218         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
219                 5 * DateTimeConstants.MILLIS_PER_HOUR +
220                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
221                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
222         Period test = new Period(length, PeriodType.millis());
223         assertEquals(PeriodType.millis(), test.getPeriodType());
224         assertEquals(0, test.getYears());
225         assertEquals(0, test.getMonths());
226         assertEquals(0, test.getWeeks());
227         assertEquals(0, test.getDays());
228         assertEquals(0, test.getHours());
229         assertEquals(0, test.getMinutes());
230         assertEquals(0, test.getSeconds());
231         assertEquals(length, test.getMillis());
232     }
233 
234     public void testConstructor_long_PeriodType3() throws Throwable {
235         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
236                 5 * DateTimeConstants.MILLIS_PER_HOUR +
237                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
238                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
239         Period test = new Period(length, PeriodType.dayTime());
240         assertEquals(PeriodType.dayTime(), test.getPeriodType());
241         assertEquals(0, test.getYears());
242         assertEquals(0, test.getMonths());
243         assertEquals(0, test.getWeeks());
244         assertEquals(0, test.getDays());
245         assertEquals((4 * 24) + 5, test.getHours());
246         assertEquals(6, test.getMinutes());
247         assertEquals(7, test.getSeconds());
248         assertEquals(8, test.getMillis());
249     }
250 
251     public void testConstructor_long_PeriodType4() throws Throwable {
252         long length =
253                 5 * DateTimeConstants.MILLIS_PER_HOUR +
254                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
255                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
256         Period test = new Period(length, PeriodType.standard().withMillisRemoved());
257         assertEquals(PeriodType.standard().withMillisRemoved(), test.getPeriodType());
258         assertEquals(0, test.getYears());
259         assertEquals(0, test.getMonths());
260         assertEquals(0, test.getWeeks());
261         assertEquals(0, test.getDays());
262         assertEquals(5, test.getHours());
263         assertEquals(6, test.getMinutes());
264         assertEquals(7, test.getSeconds());
265         assertEquals(0, test.getMillis());
266     }
267 
268     //-----------------------------------------------------------------------
269     public void testConstructor_long_Chronology1() throws Throwable {
270         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
271                 5 * DateTimeConstants.MILLIS_PER_HOUR +
272                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
273                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
274         Period test = new Period(length, ISOChronology.getInstance());
275         assertEquals(PeriodType.standard(), test.getPeriodType());
276         assertEquals(0, test.getYears());
277         assertEquals(0, test.getMonths());
278         assertEquals(0, test.getWeeks());
279         assertEquals(0, test.getDays());
280         assertEquals((4 * 24) + 5, test.getHours());
281         assertEquals(6, test.getMinutes());
282         assertEquals(7, test.getSeconds());
283         assertEquals(8, test.getMillis());
284     }
285 
286     public void testConstructor_long_Chronology2() throws Throwable {
287         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
288                 5 * DateTimeConstants.MILLIS_PER_HOUR +
289                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
290                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
291         Period test = new Period(length, ISOChronology.getInstanceUTC());
292         assertEquals(PeriodType.standard(), test.getPeriodType());
293         assertEquals(0, test.getYears());
294         assertEquals(0, test.getMonths());
295         assertEquals(0, test.getWeeks());
296         assertEquals(4, test.getDays());
297         assertEquals(5, test.getHours());
298         assertEquals(6, test.getMinutes());
299         assertEquals(7, test.getSeconds());
300         assertEquals(8, test.getMillis());
301     }
302 
303     public void testConstructor_long_Chronology3() throws Throwable {
304         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
305                 5 * DateTimeConstants.MILLIS_PER_HOUR +
306                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
307                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
308         Period test = new Period(length, (Chronology) null);
309         assertEquals(PeriodType.standard(), test.getPeriodType());
310         assertEquals(0, test.getYears());
311         assertEquals(0, test.getMonths());
312         assertEquals(0, test.getWeeks());
313         assertEquals(0, test.getDays());
314         assertEquals((4 * 24) + 5, test.getHours());
315         assertEquals(6, test.getMinutes());
316         assertEquals(7, test.getSeconds());
317         assertEquals(8, test.getMillis());
318     }
319 
320     //-----------------------------------------------------------------------
321     public void testConstructor_long_PeriodType_Chronology1() throws Throwable {
322         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
323                 5 * DateTimeConstants.MILLIS_PER_HOUR +
324                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
325                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
326         Period test = new Period(length, PeriodType.time().withMillisRemoved(), ISOChronology.getInstance());
327         assertEquals(PeriodType.time().withMillisRemoved(), test.getPeriodType());
328         assertEquals(0, test.getYears());
329         assertEquals(0, test.getMonths());
330         assertEquals(0, test.getWeeks());
331         assertEquals(0, test.getDays());
332         assertEquals((4 * 24) + 5, test.getHours());
333         assertEquals(6, test.getMinutes());
334         assertEquals(7, test.getSeconds());
335         assertEquals(0, test.getMillis());
336     }
337 
338     public void testConstructor_long_PeriodType_Chronology2() throws Throwable {
339         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
340                 5 * DateTimeConstants.MILLIS_PER_HOUR +
341                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
342                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
343         Period test = new Period(length, PeriodType.standard(), ISOChronology.getInstanceUTC());
344         assertEquals(PeriodType.standard(), test.getPeriodType());
345         assertEquals(0, test.getYears());
346         assertEquals(0, test.getMonths());
347         assertEquals(0, test.getWeeks());
348         assertEquals(4, test.getDays());
349         assertEquals(5, test.getHours());
350         assertEquals(6, test.getMinutes());
351         assertEquals(7, test.getSeconds());
352         assertEquals(8, test.getMillis());
353     }
354 
355     public void testConstructor_long_PeriodType_Chronology3() throws Throwable {
356         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
357                 5 * DateTimeConstants.MILLIS_PER_HOUR +
358                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
359                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
360         Period test = new Period(length, PeriodType.standard(), (Chronology) null);
361         assertEquals(PeriodType.standard(), test.getPeriodType());
362         assertEquals(0, test.getYears());
363         assertEquals(0, test.getMonths());
364         assertEquals(0, test.getWeeks());
365         assertEquals(0, test.getDays());
366         assertEquals((4 * 24) + 5, test.getHours());
367         assertEquals(6, test.getMinutes());
368         assertEquals(7, test.getSeconds());
369         assertEquals(8, test.getMillis());
370     }
371 
372     public void testConstructor_long_PeriodType_Chronology4() throws Throwable {
373         long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
374                 5 * DateTimeConstants.MILLIS_PER_HOUR +
375                 6 * DateTimeConstants.MILLIS_PER_MINUTE +
376                 7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
377         Period test = new Period(length, (PeriodType) null, (Chronology) null);
378         assertEquals(PeriodType.standard(), test.getPeriodType());
379         assertEquals(0, test.getYears());
380         assertEquals(0, test.getMonths());
381         assertEquals(0, test.getWeeks());
382         assertEquals(0, test.getDays());
383         assertEquals((4 * 24) + 5, test.getHours());
384         assertEquals(6, test.getMinutes());
385         assertEquals(7, test.getSeconds());
386         assertEquals(8, test.getMillis());
387     }
388 
389     //-----------------------------------------------------------------------
390     /**
391      * Test constructor (4ints)
392      */
393     public void testConstructor_4int1() throws Throwable {
394         Period test = new Period(5, 6, 7, 8);
395         assertEquals(PeriodType.standard(), test.getPeriodType());
396         assertEquals(0, test.getYears());
397         assertEquals(0, test.getMonths());
398         assertEquals(0, test.getWeeks());
399         assertEquals(0, test.getDays());
400         assertEquals(5, test.getHours());
401         assertEquals(6, test.getMinutes());
402         assertEquals(7, test.getSeconds());
403         assertEquals(8, test.getMillis());
404     }
405 
406     //-----------------------------------------------------------------------
407     /**
408      * Test constructor (8ints)
409      */
410     public void testConstructor_8int1() throws Throwable {
411         Period test = new Period(1, 2, 3, 4, 5, 6, 7, 8);
412         assertEquals(PeriodType.standard(), test.getPeriodType());
413         assertEquals(1, test.getYears());
414         assertEquals(2, test.getMonths());
415         assertEquals(3, test.getWeeks());
416         assertEquals(4, test.getDays());
417         assertEquals(5, test.getHours());
418         assertEquals(6, test.getMinutes());
419         assertEquals(7, test.getSeconds());
420         assertEquals(8, test.getMillis());
421     }
422 
423     //-----------------------------------------------------------------------
424     /**
425      * Test constructor (8ints)
426      */
427     public void testConstructor_8int__PeriodType1() throws Throwable {
428         Period test = new Period(1, 2, 3, 4, 5, 6, 7, 8, null);
429         assertEquals(PeriodType.standard(), test.getPeriodType());
430         assertEquals(1, test.getYears());
431         assertEquals(2, test.getMonths());
432         assertEquals(3, test.getWeeks());
433         assertEquals(4, test.getDays());
434         assertEquals(5, test.getHours());
435         assertEquals(6, test.getMinutes());
436         assertEquals(7, test.getSeconds());
437         assertEquals(8, test.getMillis());
438     }
439 
440     public void testConstructor_8int__PeriodType2() throws Throwable {
441         Period test = new Period(0, 0, 0, 0, 5, 6, 7, 8, PeriodType.dayTime());
442         assertEquals(PeriodType.dayTime(), test.getPeriodType());
443         assertEquals(0, test.getYears());
444         assertEquals(0, test.getMonths());
445         assertEquals(0, test.getWeeks());
446         assertEquals(0, test.getDays());
447         assertEquals(5, test.getHours());
448         assertEquals(6, test.getMinutes());
449         assertEquals(7, test.getSeconds());
450         assertEquals(8, test.getMillis());
451     }
452 
453     public void testConstructor_8int__PeriodType3() throws Throwable {
454         try {
455             new Period(1, 2, 3, 4, 5, 6, 7, 8, PeriodType.dayTime());
456             fail();
457         } catch (IllegalArgumentException ex) {}
458     }
459 
460     //-----------------------------------------------------------------------
461     public void testConstructor_long_long1() throws Throwable {
462         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
463         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
464         Period test = new Period(dt1.getMillis(), dt2.getMillis());
465         assertEquals(PeriodType.standard(), test.getPeriodType());
466         assertEquals(1, test.getYears());
467         assertEquals(1, test.getMonths());
468         assertEquals(0, test.getWeeks());
469         assertEquals(1, test.getDays());
470         assertEquals(1, test.getHours());
471         assertEquals(1, test.getMinutes());
472         assertEquals(1, test.getSeconds());
473         assertEquals(1, test.getMillis());
474     }
475 
476     public void testConstructor_long_long2() throws Throwable {
477         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
478         DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
479         Period test = new Period(dt1.getMillis(), dt2.getMillis());
480         assertEquals(PeriodType.standard(), test.getPeriodType());
481         assertEquals(1, test.getYears());
482         assertEquals(1, test.getMonths());
483         assertEquals(1, test.getWeeks());
484         assertEquals(1, test.getDays());
485         assertEquals(1, test.getHours());
486         assertEquals(1, test.getMinutes());
487         assertEquals(1, test.getSeconds());
488         assertEquals(1, test.getMillis());
489     }
490 
491     //-----------------------------------------------------------------------
492     public void testConstructor_long_long_PeriodType1() throws Throwable {
493         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
494         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
495         Period test = new Period(dt1.getMillis(), dt2.getMillis(), (PeriodType) null);
496         assertEquals(PeriodType.standard(), test.getPeriodType());
497         assertEquals(1, test.getYears());
498         assertEquals(1, test.getMonths());
499         assertEquals(0, test.getWeeks());
500         assertEquals(1, test.getDays());
501         assertEquals(1, test.getHours());
502         assertEquals(1, test.getMinutes());
503         assertEquals(1, test.getSeconds());
504         assertEquals(1, test.getMillis());
505     }
506 
507     public void testConstructor_long_long_PeriodType2() throws Throwable {
508         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
509         DateTime dt2 = new DateTime(2004, 7, 10, 1, 1, 1, 1);
510         Period test = new Period(dt1.getMillis(), dt2.getMillis(), PeriodType.dayTime());
511         assertEquals(PeriodType.dayTime(), test.getPeriodType());
512         assertEquals(0, test.getYears());
513         assertEquals(0, test.getMonths());
514         assertEquals(0, test.getWeeks());
515         assertEquals(31, test.getDays());
516         assertEquals(1, test.getHours());
517         assertEquals(1, test.getMinutes());
518         assertEquals(1, test.getSeconds());
519         assertEquals(1, test.getMillis());
520     }
521 
522     public void testConstructor_long_long_PeriodType3() throws Throwable {
523         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
524         DateTime dt2 = new DateTime(2004, 6, 9, 1, 1, 1, 1);
525         Period test = new Period(dt1.getMillis(), dt2.getMillis(), PeriodType.standard().withMillisRemoved());
526         assertEquals(PeriodType.standard().withMillisRemoved(), test.getPeriodType());
527         assertEquals(0, test.getYears());
528         assertEquals(0, test.getMonths());
529         assertEquals(0, test.getWeeks());
530         assertEquals(0, test.getDays());
531         assertEquals(1, test.getHours());
532         assertEquals(1, test.getMinutes());
533         assertEquals(1, test.getSeconds());
534         assertEquals(0, test.getMillis());
535     }
536 
537     public void testToPeriod_PeriodType3() {
538         DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10);
539         DateTime dt2 = new DateTime(2005, 6, 9, 12, 14, 16, 18);
540         Period test = new Period(dt1.getMillis(), dt2.getMillis(), PeriodType.yearWeekDayTime());
541         
542         assertEquals(PeriodType.yearWeekDayTime(), test.getPeriodType());
543         assertEquals(1, test.getYears());  // tests using years and not weekyears
544         assertEquals(0, test.getMonths());
545         assertEquals(0, test.getWeeks());
546         assertEquals(0, test.getDays());
547         assertEquals(5, test.getHours());
548         assertEquals(6, test.getMinutes());
549         assertEquals(7, test.getSeconds());
550         assertEquals(8, test.getMillis());
551     }
552 
553     //-----------------------------------------------------------------------
554     public void testConstructor_long_long_Chronology1() throws Throwable {
555         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, CopticChronology.getInstance());
556         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, CopticChronology.getInstance());
557         Period test = new Period(dt1.getMillis(), dt2.getMillis(), CopticChronology.getInstance());
558         assertEquals(PeriodType.standard(), test.getPeriodType());
559         assertEquals(1, test.getYears());
560         assertEquals(1, test.getMonths());
561         assertEquals(0, test.getWeeks());
562         assertEquals(1, test.getDays());
563         assertEquals(1, test.getHours());
564         assertEquals(1, test.getMinutes());
565         assertEquals(1, test.getSeconds());
566         assertEquals(1, test.getMillis());
567     }
568 
569     public void testConstructor_long_long_Chronology2() throws Throwable {
570         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
571         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
572         Period test = new Period(dt1.getMillis(), dt2.getMillis(), (Chronology) null);
573         assertEquals(PeriodType.standard(), test.getPeriodType());
574         assertEquals(1, test.getYears());
575         assertEquals(1, test.getMonths());
576         assertEquals(0, test.getWeeks());
577         assertEquals(1, test.getDays());
578         assertEquals(1, test.getHours());
579         assertEquals(1, test.getMinutes());
580         assertEquals(1, test.getSeconds());
581         assertEquals(1, test.getMillis());
582     }
583 
584     //-----------------------------------------------------------------------
585     public void testConstructor_long_long_PeriodType_Chronology1() throws Throwable {
586         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, CopticChronology.getInstance());
587         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, CopticChronology.getInstance());
588         Period test = new Period(dt1.getMillis(), dt2.getMillis(), (PeriodType) null, CopticChronology.getInstance());
589         assertEquals(PeriodType.standard(), test.getPeriodType());
590         assertEquals(1, test.getYears());
591         assertEquals(1, test.getMonths());
592         assertEquals(0, test.getWeeks());
593         assertEquals(1, test.getDays());
594         assertEquals(1, test.getHours());
595         assertEquals(1, test.getMinutes());
596         assertEquals(1, test.getSeconds());
597         assertEquals(1, test.getMillis());
598     }
599 
600     public void testConstructor_long_long_PeriodType_Chronology2() throws Throwable {
601         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
602         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
603         Period test = new Period(dt1.getMillis(), dt2.getMillis(), (PeriodType) null, null);
604         assertEquals(PeriodType.standard(), test.getPeriodType());
605         assertEquals(1, test.getYears());
606         assertEquals(1, test.getMonths());
607         assertEquals(0, test.getWeeks());
608         assertEquals(1, test.getDays());
609         assertEquals(1, test.getHours());
610         assertEquals(1, test.getMinutes());
611         assertEquals(1, test.getSeconds());
612         assertEquals(1, test.getMillis());
613     }
614 
615     //-----------------------------------------------------------------------
616     public void testConstructor_RI_RI1() throws Throwable {
617         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
618         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
619         Period test = new Period(dt1, dt2);
620         assertEquals(PeriodType.standard(), test.getPeriodType());
621         assertEquals(1, test.getYears());
622         assertEquals(1, test.getMonths());
623         assertEquals(0, test.getWeeks());
624         assertEquals(1, test.getDays());
625         assertEquals(1, test.getHours());
626         assertEquals(1, test.getMinutes());
627         assertEquals(1, test.getSeconds());
628         assertEquals(1, test.getMillis());
629     }
630 
631     public void testConstructor_RI_RI2() throws Throwable {
632         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
633         DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
634         Period test = new Period(dt1, dt2);
635         assertEquals(PeriodType.standard(), test.getPeriodType());
636         assertEquals(1, test.getYears());
637         assertEquals(1, test.getMonths());
638         assertEquals(1, test.getWeeks());
639         assertEquals(1, test.getDays());
640         assertEquals(1, test.getHours());
641         assertEquals(1, test.getMinutes());
642         assertEquals(1, test.getSeconds());
643         assertEquals(1, test.getMillis());
644     }
645 
646     public void testConstructor_RI_RI3() throws Throwable {
647         DateTime dt1 = null;  // 2002-06-09T01:00+01:00
648         DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
649         Period test = new Period(dt1, dt2);
650         assertEquals(PeriodType.standard(), test.getPeriodType());
651         assertEquals(3, test.getYears());
652         assertEquals(1, test.getMonths());
653         assertEquals(1, test.getWeeks());
654         assertEquals(1, test.getDays());
655         assertEquals(0, test.getHours());
656         assertEquals(1, test.getMinutes());
657         assertEquals(1, test.getSeconds());
658         assertEquals(1, test.getMillis());
659     }
660 
661     public void testConstructor_RI_RI4() throws Throwable {
662         DateTime dt1 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
663         DateTime dt2 = null;  // 2002-06-09T01:00+01:00
664         Period test = new Period(dt1, dt2);
665         assertEquals(PeriodType.standard(), test.getPeriodType());
666         assertEquals(-3, test.getYears());
667         assertEquals(-1, test.getMonths());
668         assertEquals(-1, test.getWeeks());
669         assertEquals(-1, test.getDays());
670         assertEquals(0, test.getHours());
671         assertEquals(-1, test.getMinutes());
672         assertEquals(-1, test.getSeconds());
673         assertEquals(-1, test.getMillis());
674     }
675 
676     public void testConstructor_RI_RI5() throws Throwable {
677         DateTime dt1 = null;  // 2002-06-09T01:00+01:00
678         DateTime dt2 = null;  // 2002-06-09T01:00+01:00
679         Period test = new Period(dt1, dt2);
680         assertEquals(PeriodType.standard(), test.getPeriodType());
681         assertEquals(0, test.getYears());
682         assertEquals(0, test.getMonths());
683         assertEquals(0, test.getWeeks());
684         assertEquals(0, test.getDays());
685         assertEquals(0, test.getHours());
686         assertEquals(0, test.getMinutes());
687         assertEquals(0, test.getSeconds());
688         assertEquals(0, test.getMillis());
689     }
690 
691     //-----------------------------------------------------------------------
692     public void testConstructor_RI_RI_PeriodType1() throws Throwable {
693         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
694         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
695         Period test = new Period(dt1, dt2, null);
696         assertEquals(PeriodType.standard(), test.getPeriodType());
697         assertEquals(1, test.getYears());
698         assertEquals(1, test.getMonths());
699         assertEquals(0, test.getWeeks());
700         assertEquals(1, test.getDays());
701         assertEquals(1, test.getHours());
702         assertEquals(1, test.getMinutes());
703         assertEquals(1, test.getSeconds());
704         assertEquals(1, test.getMillis());
705     }
706 
707     public void testConstructor_RI_RI_PeriodType2() throws Throwable {
708         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
709         DateTime dt2 = new DateTime(2004, 7, 10, 1, 1, 1, 1);
710         Period test = new Period(dt1, dt2, PeriodType.dayTime());
711         assertEquals(PeriodType.dayTime(), test.getPeriodType());
712         assertEquals(0, test.getYears());
713         assertEquals(0, test.getMonths());
714         assertEquals(0, test.getWeeks());
715         assertEquals(31, test.getDays());
716         assertEquals(1, test.getHours());
717         assertEquals(1, test.getMinutes());
718         assertEquals(1, test.getSeconds());
719         assertEquals(1, test.getMillis());
720     }
721 
722     public void testConstructor_RI_RI_PeriodType3() throws Throwable {
723         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
724         DateTime dt2 = new DateTime(2004, 6, 9, 1, 1, 1, 1);
725         Period test = new Period(dt1, dt2, PeriodType.standard().withMillisRemoved());
726         assertEquals(PeriodType.standard().withMillisRemoved(), test.getPeriodType());
727         assertEquals(0, test.getYears());
728         assertEquals(0, test.getMonths());
729         assertEquals(0, test.getWeeks());
730         assertEquals(0, test.getDays());
731         assertEquals(1, test.getHours());
732         assertEquals(1, test.getMinutes());
733         assertEquals(1, test.getSeconds());
734         assertEquals(0, test.getMillis());
735     }
736 
737     public void testConstructor_RI_RI_PeriodType4() throws Throwable {
738         DateTime dt1 = null;  // 2002-06-09T01:00+01:00
739         DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
740         Period test = new Period(dt1, dt2, PeriodType.standard());
741         assertEquals(PeriodType.standard(), test.getPeriodType());
742         assertEquals(3, test.getYears());
743         assertEquals(1, test.getMonths());
744         assertEquals(1, test.getWeeks());
745         assertEquals(1, test.getDays());
746         assertEquals(0, test.getHours());
747         assertEquals(1, test.getMinutes());
748         assertEquals(1, test.getSeconds());
749         assertEquals(1, test.getMillis());
750     }
751 
752     public void testConstructor_RI_RI_PeriodType5() throws Throwable {
753         DateTime dt1 = null;  // 2002-06-09T01:00+01:00
754         DateTime dt2 = null;  // 2002-06-09T01:00+01:00
755         Period test = new Period(dt1, dt2, PeriodType.standard());
756         assertEquals(PeriodType.standard(), test.getPeriodType());
757         assertEquals(0, test.getYears());
758         assertEquals(0, test.getMonths());
759         assertEquals(0, test.getWeeks());
760         assertEquals(0, test.getDays());
761         assertEquals(0, test.getHours());
762         assertEquals(0, test.getMinutes());
763         assertEquals(0, test.getSeconds());
764         assertEquals(0, test.getMillis());
765     }
766 
767     //-----------------------------------------------------------------------
768     public void testConstructor_RP_RP1() throws Throwable {
769         YearMonthDay dt1 = new YearMonthDay(2004, 6, 9);
770         YearMonthDay dt2 = new YearMonthDay(2005, 7, 10);
771         Period test = new Period(dt1, dt2);
772         assertEquals(PeriodType.standard(), test.getPeriodType());
773         assertEquals(1, test.getYears());
774         assertEquals(1, test.getMonths());
775         assertEquals(0, test.getWeeks());
776         assertEquals(1, test.getDays());
777         assertEquals(0, test.getHours());
778         assertEquals(0, test.getMinutes());
779         assertEquals(0, test.getSeconds());
780         assertEquals(0, test.getMillis());
781     }
782 
783     public void testConstructor_RP_RP2() throws Throwable {
784         YearMonthDay dt1 = new YearMonthDay(2004, 6, 9);
785         YearMonthDay dt2 = new YearMonthDay(2005, 5, 17);
786         Period test = new Period(dt1, dt2);
787         assertEquals(PeriodType.standard(), test.getPeriodType());
788         assertEquals(0, test.getYears());
789         assertEquals(11, test.getMonths());
790         assertEquals(1, test.getWeeks());
791         assertEquals(1, test.getDays());
792         assertEquals(0, test.getHours());
793         assertEquals(0, test.getMinutes());
794         assertEquals(0, test.getSeconds());
795         assertEquals(0, test.getMillis());
796     }
797 
798     public void testConstructor_RP_RP2Local() throws Throwable {
799         LocalDate dt1 = new LocalDate(2004, 6, 9);
800         LocalDate dt2 = new LocalDate(2005, 5, 17);
801         Period test = new Period(dt1, dt2);
802         assertEquals(PeriodType.standard(), test.getPeriodType());
803         assertEquals(0, test.getYears());
804         assertEquals(11, test.getMonths());
805         assertEquals(1, test.getWeeks());
806         assertEquals(1, test.getDays());
807         assertEquals(0, test.getHours());
808         assertEquals(0, test.getMinutes());
809         assertEquals(0, test.getSeconds());
810         assertEquals(0, test.getMillis());
811     }
812 
813     public void testConstructor_RP_RP3() throws Throwable {
814         YearMonthDay dt1 = null;
815         YearMonthDay dt2 = new YearMonthDay(2005, 7, 17);
816         try {
817             new Period(dt1, dt2);
818             fail();
819         } catch (IllegalArgumentException ex) {}
820     }
821 
822     public void testConstructor_RP_RP4() throws Throwable {
823         YearMonthDay dt1 = new YearMonthDay(2005, 7, 17);
824         YearMonthDay dt2 = null;
825         try {
826             new Period(dt1, dt2);
827             fail();
828         } catch (IllegalArgumentException ex) {}
829     }
830 
831     public void testConstructor_RP_RP5() throws Throwable {
832         YearMonthDay dt1 = null;
833         YearMonthDay dt2 = null;
834         try {
835             new Period(dt1, dt2);
836             fail();
837         } catch (IllegalArgumentException ex) {}
838     }
839 
840     public void testConstructor_RP_RP6() throws Throwable {
841         YearMonthDay dt1 = new YearMonthDay(2005, 7, 17);
842         TimeOfDay dt2 = new TimeOfDay(10, 20, 30, 40);
843         try {
844             new Period(dt1, dt2);
845             fail();
846         } catch (IllegalArgumentException ex) {}
847     }
848 
849     public void testConstructor_RP_RP7() throws Throwable {
850         Partial dt1 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.monthOfYear(), 12);
851         Partial dt2 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 14);
852         try {
853             new Period(dt1, dt2);
854             fail();
855         } catch (IllegalArgumentException ex) {}
856     }
857 
858     public void testConstructor_RP_RP8() throws Throwable {
859         Partial dt1 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 12);
860         Partial dt2 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 14);
861         try {
862             new Period(dt1, dt2);
863             fail();
864         } catch (IllegalArgumentException ex) {}
865     }
866 
867     //-----------------------------------------------------------------------
868     public void testConstructor_RP_RP_PeriodType1() throws Throwable {
869         YearMonthDay dt1 = new YearMonthDay(2004, 6, 9);
870         YearMonthDay dt2 = new YearMonthDay(2005, 7, 10);
871         Period test = new Period(dt1, dt2, PeriodType.standard());
872         assertEquals(PeriodType.standard(), test.getPeriodType());
873         assertEquals(1, test.getYears());
874         assertEquals(1, test.getMonths());
875         assertEquals(0, test.getWeeks());
876         assertEquals(1, test.getDays());
877         assertEquals(0, test.getHours());
878         assertEquals(0, test.getMinutes());
879         assertEquals(0, test.getSeconds());
880         assertEquals(0, test.getMillis());
881     }
882 
883     public void testConstructor_RP_RP_PeriodType2() throws Throwable {
884         YearMonthDay dt1 = new YearMonthDay(2004, 6, 9);
885         YearMonthDay dt2 = new YearMonthDay(2005, 5, 17);
886         Period test = new Period(dt1, dt2, PeriodType.yearMonthDay());
887         assertEquals(PeriodType.yearMonthDay(), test.getPeriodType());
888         assertEquals(0, test.getYears());
889         assertEquals(11, test.getMonths());
890         assertEquals(0, test.getWeeks());
891         assertEquals(8, test.getDays());
892         assertEquals(0, test.getHours());
893         assertEquals(0, test.getMinutes());
894         assertEquals(0, test.getSeconds());
895         assertEquals(0, test.getMillis());
896     }
897 
898     public void testConstructor_RP_RP_PeriodType2Local() throws Throwable {
899         LocalDate dt1 = new LocalDate(2004, 6, 9);
900         LocalDate dt2 = new LocalDate(2005, 5, 17);
901         Period test = new Period(dt1, dt2, PeriodType.yearMonthDay());
902         assertEquals(PeriodType.yearMonthDay(), test.getPeriodType());
903         assertEquals(0, test.getYears());
904         assertEquals(11, test.getMonths());
905         assertEquals(0, test.getWeeks());
906         assertEquals(8, test.getDays());
907         assertEquals(0, test.getHours());
908         assertEquals(0, test.getMinutes());
909         assertEquals(0, test.getSeconds());
910         assertEquals(0, test.getMillis());
911     }
912 
913     public void testConstructor_RP_RP_PeriodType3() throws Throwable {
914         YearMonthDay dt1 = null;
915         YearMonthDay dt2 = new YearMonthDay(2005, 7, 17);
916         try {
917             new Period(dt1, dt2, PeriodType.standard());
918             fail();
919         } catch (IllegalArgumentException ex) {}
920     }
921 
922     public void testConstructor_RP_RP_PeriodType4() throws Throwable {
923         YearMonthDay dt1 = new YearMonthDay(2005, 7, 17);
924         YearMonthDay dt2 = null;
925         try {
926             new Period(dt1, dt2);
927             fail();
928         } catch (IllegalArgumentException ex) {}
929     }
930 
931     public void testConstructor_RP_RP_PeriodType5() throws Throwable {
932         YearMonthDay dt1 = null;
933         YearMonthDay dt2 = null;
934         try {
935             new Period(dt1, dt2, PeriodType.standard());
936             fail();
937         } catch (IllegalArgumentException ex) {}
938     }
939 
940     public void testConstructor_RP_RP_PeriodType6() throws Throwable {
941         YearMonthDay dt1 = new YearMonthDay(2005, 7, 17);
942         TimeOfDay dt2 = new TimeOfDay(10, 20, 30, 40);
943         try {
944             new Period(dt1, dt2, PeriodType.standard());
945             fail();
946         } catch (IllegalArgumentException ex) {}
947     }
948 
949     public void testConstructor_RP_RP_PeriodType7() throws Throwable {
950         Partial dt1 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.monthOfYear(), 12);
951         Partial dt2 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 14);
952         try {
953             new Period(dt1, dt2, PeriodType.standard());
954             fail();
955         } catch (IllegalArgumentException ex) {}
956     }
957 
958     public void testConstructor_RP_RP_PeriodType8() throws Throwable {
959         Partial dt1 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 12);
960         Partial dt2 = new Partial().with(DateTimeFieldType.year(), 2005).with(DateTimeFieldType.hourOfDay(), 14);
961         try {
962             new Period(dt1, dt2, PeriodType.standard());
963             fail();
964         } catch (IllegalArgumentException ex) {}
965     }
966 
967     //-----------------------------------------------------------------------
968     public void testConstructor_RI_RD1() throws Throwable {
969         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
970         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
971         Duration dur = new Interval(dt1, dt2).toDuration();
972         Period test = new Period(dt1, dur);
973         assertEquals(PeriodType.standard(), test.getPeriodType());
974         assertEquals(1, test.getYears());
975         assertEquals(1, test.getMonths());
976         assertEquals(0, test.getWeeks());
977         assertEquals(1, test.getDays());
978         assertEquals(1, test.getHours());
979         assertEquals(1, test.getMinutes());
980         assertEquals(1, test.getSeconds());
981         assertEquals(1, test.getMillis());
982     }
983 
984     public void testConstructor_RI_RD2() throws Throwable {
985         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
986         Duration dur = null;
987         Period test = new Period(dt1, dur);
988         assertEquals(PeriodType.standard(), test.getPeriodType());
989         assertEquals(0, test.getYears());
990         assertEquals(0, test.getMonths());
991         assertEquals(0, test.getWeeks());
992         assertEquals(0, test.getDays());
993         assertEquals(0, test.getHours());
994         assertEquals(0, test.getMinutes());
995         assertEquals(0, test.getSeconds());
996         assertEquals(0, test.getMillis());
997     }
998 
999     //-----------------------------------------------------------------------
1000     public void testConstructor_RI_RD_PeriodType1() throws Throwable {
1001         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1002         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
1003         Duration dur = new Interval(dt1, dt2).toDuration();
1004         Period test = new Period(dt1, dur, PeriodType.yearDayTime());
1005         assertEquals(PeriodType.yearDayTime(), test.getPeriodType());
1006         assertEquals(1, test.getYears());
1007         assertEquals(0, test.getMonths());
1008         assertEquals(0, test.getWeeks());
1009         assertEquals(31, test.getDays());
1010         assertEquals(1, test.getHours());
1011         assertEquals(1, test.getMinutes());
1012         assertEquals(1, test.getSeconds());
1013         assertEquals(1, test.getMillis());
1014     }
1015 
1016     public void testConstructor_RI_RD_PeriodType2() throws Throwable {
1017         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1018         Duration dur = null;
1019         Period test = new Period(dt1, dur, (PeriodType) null);
1020         assertEquals(PeriodType.standard(), test.getPeriodType());
1021         assertEquals(0, test.getYears());
1022         assertEquals(0, test.getMonths());
1023         assertEquals(0, test.getWeeks());
1024         assertEquals(0, test.getDays());
1025         assertEquals(0, test.getHours());
1026         assertEquals(0, test.getMinutes());
1027         assertEquals(0, test.getSeconds());
1028         assertEquals(0, test.getMillis());
1029     }
1030 
1031     //-----------------------------------------------------------------------
1032     public void testConstructor_RD_RI1() throws Throwable {
1033         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1034         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
1035         Duration dur = new Interval(dt1, dt2).toDuration();
1036         Period test = new Period(dur, dt2);
1037         assertEquals(PeriodType.standard(), test.getPeriodType());
1038         assertEquals(1, test.getYears());
1039         assertEquals(1, test.getMonths());
1040         assertEquals(0, test.getWeeks());
1041         assertEquals(1, test.getDays());
1042         assertEquals(1, test.getHours());
1043         assertEquals(1, test.getMinutes());
1044         assertEquals(1, test.getSeconds());
1045         assertEquals(1, test.getMillis());
1046     }
1047 
1048     public void testConstructor_RD_RI2() throws Throwable {
1049         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1050         Duration dur = null;
1051         Period test = new Period(dur, dt1);
1052         assertEquals(PeriodType.standard(), test.getPeriodType());
1053         assertEquals(0, test.getYears());
1054         assertEquals(0, test.getMonths());
1055         assertEquals(0, test.getWeeks());
1056         assertEquals(0, test.getDays());
1057         assertEquals(0, test.getHours());
1058         assertEquals(0, test.getMinutes());
1059         assertEquals(0, test.getSeconds());
1060         assertEquals(0, test.getMillis());
1061     }
1062 
1063     //-----------------------------------------------------------------------
1064     public void testConstructor_RD_RI_PeriodType1() throws Throwable {
1065         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1066         DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
1067         Duration dur = new Interval(dt1, dt2).toDuration();
1068         Period test = new Period(dur, dt2, PeriodType.yearDayTime());
1069         assertEquals(PeriodType.yearDayTime(), test.getPeriodType());
1070         assertEquals(1, test.getYears());
1071         assertEquals(0, test.getMonths());
1072         assertEquals(0, test.getWeeks());
1073         assertEquals(31, test.getDays());
1074         assertEquals(1, test.getHours());
1075         assertEquals(1, test.getMinutes());
1076         assertEquals(1, test.getSeconds());
1077         assertEquals(1, test.getMillis());
1078     }
1079 
1080     public void testConstructor_RD_RI_PeriodType2() throws Throwable {
1081         DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1082         Duration dur = null;
1083         Period test = new Period(dur, dt1, (PeriodType) null);
1084         assertEquals(PeriodType.standard(), test.getPeriodType());
1085         assertEquals(0, test.getYears());
1086         assertEquals(0, test.getMonths());
1087         assertEquals(0, test.getWeeks());
1088         assertEquals(0, test.getDays());
1089         assertEquals(0, test.getHours());
1090         assertEquals(0, test.getMinutes());
1091         assertEquals(0, test.getSeconds());
1092         assertEquals(0, test.getMillis());
1093     }
1094 
1095     //-----------------------------------------------------------------------
1096     /**
1097      * Test constructor (Object)
1098      */
1099     public void testConstructor_Object1() throws Throwable {
1100         Period test = new Period("P1Y2M3D");
1101         assertEquals(PeriodType.standard(), test.getPeriodType());
1102         assertEquals(1, test.getYears());
1103         assertEquals(2, test.getMonths());
1104         assertEquals(0, test.getWeeks());
1105         assertEquals(3, test.getDays());
1106         assertEquals(0, test.getHours());
1107         assertEquals(0, test.getMinutes());
1108         assertEquals(0, test.getSeconds());
1109         assertEquals(0, test.getMillis());
1110     }
1111 
1112     public void testConstructor_Object2() throws Throwable {
1113         Period test = new Period((Object) null);
1114         assertEquals(PeriodType.standard(), test.getPeriodType());
1115         assertEquals(0, test.getYears());
1116         assertEquals(0, test.getMonths());
1117         assertEquals(0, test.getWeeks());
1118         assertEquals(0, test.getDays());
1119         assertEquals(0, test.getHours());
1120         assertEquals(0, test.getMinutes());
1121         assertEquals(0, test.getSeconds());
1122         assertEquals(0, test.getMillis());
1123     }
1124 
1125     public void testConstructor_Object3() throws Throwable {
1126         Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4, PeriodType.dayTime()));
1127         assertEquals(PeriodType.dayTime(), test.getPeriodType());
1128         assertEquals(0, test.getYears());
1129         assertEquals(0, test.getMonths());
1130         assertEquals(0, test.getWeeks());
1131         assertEquals(0, test.getDays());
1132         assertEquals(1, test.getHours());
1133         assertEquals(2, test.getMinutes());
1134         assertEquals(3, test.getSeconds());
1135         assertEquals(4, test.getMillis());
1136     }
1137 
1138     public void testConstructor_Object4() throws Throwable {
1139         Period base = new Period(1, 1, 0, 1, 1, 1, 1, 1, PeriodType.standard());
1140         Period test = new Period(base);
1141         assertEquals(PeriodType.standard(), test.getPeriodType());
1142         assertEquals(1, test.getYears());
1143         assertEquals(1, test.getMonths());
1144         assertEquals(0, test.getWeeks());
1145         assertEquals(1, test.getDays());
1146         assertEquals(1, test.getHours());
1147         assertEquals(1, test.getMinutes());
1148         assertEquals(1, test.getSeconds());
1149         assertEquals(1, test.getMillis());
1150     }
1151 
1152     //-----------------------------------------------------------------------
1153     /**
1154      * Test constructor (Object)
1155      */
1156     public void testConstructor_Object_PeriodType1() throws Throwable {
1157         Period test = new Period("P1Y2M3D", PeriodType.yearMonthDayTime());
1158         assertEquals(PeriodType.yearMonthDayTime(), test.getPeriodType());
1159         assertEquals(1, test.getYears());
1160         assertEquals(2, test.getMonths());
1161         assertEquals(0, test.getWeeks());
1162         assertEquals(3, test.getDays());
1163         assertEquals(0, test.getHours());
1164         assertEquals(0, test.getMinutes());
1165         assertEquals(0, test.getSeconds());
1166         assertEquals(0, test.getMillis());
1167     }
1168 
1169     public void testConstructor_Object_PeriodType2() throws Throwable {
1170         Period test = new Period((Object) null, PeriodType.yearMonthDayTime());
1171         assertEquals(PeriodType.yearMonthDayTime(), test.getPeriodType());
1172         assertEquals(0, test.getYears());
1173         assertEquals(0, test.getMonths());
1174         assertEquals(0, test.getWeeks());
1175         assertEquals(0, test.getDays());
1176         assertEquals(0, test.getHours());
1177         assertEquals(0, test.getMinutes());
1178         assertEquals(0, test.getSeconds());
1179         assertEquals(0, test.getMillis());
1180     }
1181 
1182     public void testConstructor_Object_PeriodType3() throws Throwable {
1183         Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4, PeriodType.dayTime()), PeriodType.yearMonthDayTime());
1184         assertEquals(PeriodType.yearMonthDayTime(), test.getPeriodType());
1185         assertEquals(0, test.getYears());
1186         assertEquals(0, test.getMonths());
1187         assertEquals(0, test.getWeeks());
1188         assertEquals(0, test.getDays());
1189         assertEquals(1, test.getHours());
1190         assertEquals(2, test.getMinutes());
1191         assertEquals(3, test.getSeconds());
1192         assertEquals(4, test.getMillis());
1193     }
1194 
1195     public void testConstructor_Object_PeriodType4() throws Throwable {
1196         Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4, PeriodType.dayTime()), (PeriodType) null);
1197         assertEquals(PeriodType.dayTime(), test.getPeriodType());
1198         assertEquals(0, test.getYears());
1199         assertEquals(0, test.getMonths());
1200         assertEquals(0, test.getWeeks());
1201         assertEquals(0, test.getDays());
1202         assertEquals(1, test.getHours());
1203         assertEquals(2, test.getMinutes());
1204         assertEquals(3, test.getSeconds());
1205         assertEquals(4, test.getMillis());
1206     }
1207 
1208     //-----------------------------------------------------------------------
1209     public void testFactoryYears() throws Throwable {
1210         Period test = Period.years(6);
1211         assertEquals(PeriodType.standard(), test.getPeriodType());
1212         assertEquals(6, test.getYears());
1213         assertEquals(0, test.getMonths());
1214         assertEquals(0, test.getWeeks());
1215         assertEquals(0, test.getDays());
1216         assertEquals(0, test.getHours());
1217         assertEquals(0, test.getMinutes());
1218         assertEquals(0, test.getSeconds());
1219         assertEquals(0, test.getMillis());
1220     }
1221 
1222     public void testFactoryMonths() throws Throwable {
1223         Period test = Period.months(6);
1224         assertEquals(PeriodType.standard(), test.getPeriodType());
1225         assertEquals(0, test.getYears());
1226         assertEquals(6, test.getMonths());
1227         assertEquals(0, test.getWeeks());
1228         assertEquals(0, test.getDays());
1229         assertEquals(0, test.getHours());
1230         assertEquals(0, test.getMinutes());
1231         assertEquals(0, test.getSeconds());
1232         assertEquals(0, test.getMillis());
1233     }
1234 
1235     public void testFactoryWeeks() throws Throwable {
1236         Period test = Period.weeks(6);
1237         assertEquals(PeriodType.standard(), test.getPeriodType());
1238         assertEquals(0, test.getYears());
1239         assertEquals(0, test.getMonths());
1240         assertEquals(6, test.getWeeks());
1241         assertEquals(0, test.getDays());
1242         assertEquals(0, test.getHours());
1243         assertEquals(0, test.getMinutes());
1244         assertEquals(0, test.getSeconds());
1245         assertEquals(0, test.getMillis());
1246     }
1247 
1248     public void testFactoryDays() throws Throwable {
1249         Period test = Period.days(6);
1250         assertEquals(PeriodType.standard(), test.getPeriodType());
1251         assertEquals(0, test.getYears());
1252         assertEquals(0, test.getMonths());
1253         assertEquals(0, test.getWeeks());
1254         assertEquals(6, test.getDays());
1255         assertEquals(0, test.getHours());
1256         assertEquals(0, test.getMinutes());
1257         assertEquals(0, test.getSeconds());
1258         assertEquals(0, test.getMillis());
1259     }
1260 
1261     public void testFactoryHours() throws Throwable {
1262         Period test = Period.hours(6);
1263         assertEquals(PeriodType.standard(), test.getPeriodType());
1264         assertEquals(0, test.getYears());
1265         assertEquals(0, test.getMonths());
1266         assertEquals(0, test.getWeeks());
1267         assertEquals(0, test.getDays());
1268         assertEquals(6, test.getHours());
1269         assertEquals(0, test.getMinutes());
1270         assertEquals(0, test.getSeconds());
1271         assertEquals(0, test.getMillis());
1272     }
1273 
1274     public void testFactoryMinutes() throws Throwable {
1275         Period test = Period.minutes(6);
1276         assertEquals(PeriodType.standard(), test.getPeriodType());
1277         assertEquals(0, test.getYears());
1278         assertEquals(0, test.getMonths());
1279         assertEquals(0, test.getWeeks());
1280         assertEquals(0, test.getDays());
1281         assertEquals(0, test.getHours());
1282         assertEquals(6, test.getMinutes());
1283         assertEquals(0, test.getSeconds());
1284         assertEquals(0, test.getMillis());
1285     }
1286 
1287     public void testFactorySeconds() throws Throwable {
1288         Period test = Period.seconds(6);
1289         assertEquals(PeriodType.standard(), test.getPeriodType());
1290         assertEquals(0, test.getYears());
1291         assertEquals(0, test.getMonths());
1292         assertEquals(0, test.getWeeks());
1293         assertEquals(0, test.getDays());
1294         assertEquals(0, test.getHours());
1295         assertEquals(0, test.getMinutes());
1296         assertEquals(6, test.getSeconds());
1297         assertEquals(0, test.getMillis());
1298     }
1299 
1300     public void testFactoryMillis() throws Throwable {
1301         Period test = Period.millis(6);
1302         assertEquals(PeriodType.standard(), test.getPeriodType());
1303         assertEquals(0, test.getYears());
1304         assertEquals(0, test.getMonths());
1305         assertEquals(0, test.getWeeks());
1306         assertEquals(0, test.getDays());
1307         assertEquals(0, test.getHours());
1308         assertEquals(0, test.getMinutes());
1309         assertEquals(0, test.getSeconds());
1310         assertEquals(6, test.getMillis());
1311     }
1312 
1313     //-----------------------------------------------------------------------
1314     public void testFactoryFieldDifference1() throws Throwable {
1315         YearMonthDay start = new YearMonthDay(2005, 4, 9);
1316         DateTimeFieldType[] types = new DateTimeFieldType[] {
1317             DateTimeFieldType.year(),
1318             DateTimeFieldType.monthOfYear(),
1319             DateTimeFieldType.dayOfMonth(),
1320         };
1321         Partial end = new Partial(types, new int[] {2004, 6, 7});
1322         Period test = Period.fieldDifference(start, end);
1323         assertEquals(PeriodType.yearMonthDay(), test.getPeriodType());
1324         assertEquals(-1, test.getYears());
1325         assertEquals(2, test.getMonths());
1326         assertEquals(0, test.getWeeks());
1327         assertEquals(-2, test.getDays());
1328         assertEquals(0, test.getHours());
1329         assertEquals(0, test.getMinutes());
1330         assertEquals(0, test.getSeconds());
1331         assertEquals(0, test.getMillis());
1332     }
1333 
1334     public void testFactoryFieldDifference2() throws Throwable {
1335         YearMonthDay ymd = new YearMonthDay(2005, 4, 9);
1336         try {
1337             Period.fieldDifference(ymd, (ReadablePartial) null);
1338             fail();
1339         } catch (IllegalArgumentException ex) {}
1340         try {
1341             Period.fieldDifference((ReadablePartial) null, ymd);
1342             fail();
1343         } catch (IllegalArgumentException ex) {}
1344     }
1345 
1346     public void testFactoryFieldDifference3() throws Throwable {
1347         YearMonthDay start = new YearMonthDay(2005, 4, 9);
1348         TimeOfDay endTime = new TimeOfDay(12, 30, 40, 0);
1349         try {
1350             Period.fieldDifference(start, endTime);
1351             fail();
1352         } catch (IllegalArgumentException ex) {}
1353     }
1354 
1355     public void testFactoryFieldDifference4() throws Throwable {
1356         DateTimeFieldType[] types = new DateTimeFieldType[] {
1357             DateTimeFieldType.year(),
1358             DateTimeFieldType.monthOfYear(),
1359             DateTimeFieldType.dayOfWeek(),
1360         };
1361         YearMonthDay start = new YearMonthDay(2005, 4, 9);
1362         Partial end = new Partial(types, new int[] {1, 2, 3});
1363         try {
1364             Period.fieldDifference(start, end);
1365             fail();
1366         } catch (IllegalArgumentException ex) {}
1367     }
1368 
1369     public void testFactoryFieldDifference5() throws Throwable {
1370         DateTimeFieldType[] types = new DateTimeFieldType[] {
1371             DateTimeFieldType.year(),
1372             DateTimeFieldType.dayOfMonth(),
1373             DateTimeFieldType.dayOfWeek(),
1374         };
1375         Partial start = new Partial(types, new int[] {1, 2, 3});
1376         Partial end = new Partial(types, new int[] {1, 2, 3});
1377         try {
1378             Period.fieldDifference(start, end);
1379             fail();
1380         } catch (IllegalArgumentException ex) {}
1381     }
1382 
1383 }