View Javadoc

1   /*
2    *  Copyright 2001-2013 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.Calendar;
19  import java.util.Date;
20  import java.util.GregorianCalendar;
21  
22  import junit.framework.TestCase;
23  import junit.framework.TestSuite;
24  
25  import org.joda.time.chrono.BuddhistChronology;
26  import org.joda.time.chrono.GregorianChronology;
27  import org.joda.time.chrono.ISOChronology;
28  import org.joda.time.format.DateTimeFormat;
29  import org.joda.time.format.DateTimeFormatter;
30  
31  /**
32   * This class is a Junit unit test for LocalDateTime.
33   *
34   * @author Stephen Colebourne
35   */
36  public class TestLocalDateTime_Constructors extends TestCase {
37  
38      private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
39      private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
40      private static final DateTimeZone MOSCOW = DateTimeZone.forID("Europe/Moscow");
41      private static final Chronology ISO_UTC = ISOChronology.getInstanceUTC();
42      private static final Chronology GREGORIAN_UTC = GregorianChronology.getInstanceUTC();
43      private static final Chronology GREGORIAN_PARIS = GregorianChronology.getInstance(PARIS);
44      private static final Chronology GREGORIAN_MOSCOW = GregorianChronology.getInstance(MOSCOW);
45      private static final Chronology BUDDHIST_UTC = BuddhistChronology.getInstanceUTC();
46      private static final int OFFSET_PARIS = PARIS.getOffset(0L) / DateTimeConstants.MILLIS_PER_HOUR;
47      private static final int OFFSET_MOSCOW = MOSCOW.getOffset(0L) / DateTimeConstants.MILLIS_PER_HOUR;
48      
49      private long MILLIS_OF_DAY =
50          10L * DateTimeConstants.MILLIS_PER_HOUR
51          + 20L * DateTimeConstants.MILLIS_PER_MINUTE
52          + 30L * DateTimeConstants.MILLIS_PER_SECOND
53          + 40L;
54      private long TEST_TIME_NOW =
55          (31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY
56          + MILLIS_OF_DAY;
57  
58      private long TEST_TIME1 =
59          (31L + 28L + 31L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
60          + 12L * DateTimeConstants.MILLIS_PER_HOUR
61          + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
62      private long TEST_TIME2 =
63          (365L + 31L + 28L + 31L + 30L + 7L -1L) * DateTimeConstants.MILLIS_PER_DAY
64          + 14L * DateTimeConstants.MILLIS_PER_HOUR
65          + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
66  
67      private DateTimeZone zone = null;
68  
69      public static void main(String[] args) {
70          junit.textui.TestRunner.run(suite());
71      }
72  
73      public static TestSuite suite() {
74          return new TestSuite(TestLocalDateTime_Constructors.class);
75      }
76  
77      public TestLocalDateTime_Constructors(String name) {
78          super(name);
79      }
80  
81      protected void setUp() throws Exception {
82          DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
83          zone = DateTimeZone.getDefault();
84          DateTimeZone.setDefault(MOSCOW);
85      }
86  
87      protected void tearDown() throws Exception {
88          DateTimeUtils.setCurrentMillisSystem();
89          DateTimeZone.setDefault(zone);
90          zone = null;
91      }
92  
93      //-----------------------------------------------------------------------
94      public void testParse_noFormatter() throws Throwable {
95          assertEquals(new LocalDateTime(2010, 6, 30, 1, 20), LocalDateTime.parse("2010-06-30T01:20"));
96          assertEquals(new LocalDateTime(2010, 1, 2, 14, 50, 30, 432), LocalDateTime.parse("2010-002T14:50:30.432"));
97      }
98  
99      public void testParse_formatter() throws Throwable {
100         DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM HH").withChronology(ISOChronology.getInstance(PARIS));
101         assertEquals(new LocalDateTime(2010, 6, 30, 13, 0), LocalDateTime.parse("2010--30 06 13", f));
102     }
103 
104     //-----------------------------------------------------------------------
105     public void testFactory_fromCalendarFields() throws Exception {
106         GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5, 6);
107         cal.set(Calendar.MILLISECOND, 7);
108         LocalDateTime expected = new LocalDateTime(1970, 2, 3, 4, 5, 6, 7);
109         assertEquals(expected, LocalDateTime.fromCalendarFields(cal));
110     }
111 
112     public void testFactory_fromCalendarFields_beforeYearZero1() throws Exception {
113         GregorianCalendar cal = new GregorianCalendar(1, 1, 3, 4, 5, 6);
114         cal.set(Calendar.ERA, GregorianCalendar.BC);
115         cal.set(Calendar.MILLISECOND, 7);
116         LocalDateTime expected = new LocalDateTime(0, 2, 3, 4, 5, 6, 7);
117         assertEquals(expected, LocalDateTime.fromCalendarFields(cal));
118     }
119 
120     public void testFactory_fromCalendarFields_beforeYearZero3() throws Exception {
121         GregorianCalendar cal = new GregorianCalendar(3, 1, 3, 4, 5, 6);
122         cal.set(Calendar.ERA, GregorianCalendar.BC);
123         cal.set(Calendar.MILLISECOND, 7);
124         LocalDateTime expected = new LocalDateTime(-2, 2, 3, 4, 5, 6, 7);
125         assertEquals(expected, LocalDateTime.fromCalendarFields(cal));
126     }
127 
128     public void testFactory_fromCalendarFields_null() throws Exception {
129         try {
130             LocalDateTime.fromCalendarFields((Calendar) null);
131             fail();
132         } catch (IllegalArgumentException ex) {}
133     }
134 
135     //-----------------------------------------------------------------------
136     public void testFactory_fromDateFields_after1970() throws Exception {
137         GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5, 6);
138         cal.set(Calendar.MILLISECOND, 7);
139         LocalDateTime expected = new LocalDateTime(1970, 2, 3, 4, 5 ,6, 7);
140         assertEquals(expected, LocalDateTime.fromDateFields(cal.getTime()));
141     }
142 
143     public void testFactory_fromDateFields_before1970() throws Exception {
144         GregorianCalendar cal = new GregorianCalendar(1969, 1, 3, 4, 5, 6);
145         cal.set(Calendar.MILLISECOND, 7);
146         LocalDateTime expected = new LocalDateTime(1969, 2, 3, 4, 5 ,6, 7);
147         assertEquals(expected, LocalDateTime.fromDateFields(cal.getTime()));
148     }
149 
150     public void testFactory_fromDateFields_beforeYearZero1() throws Exception {
151         GregorianCalendar cal = new GregorianCalendar(1, 1, 3, 4, 5, 6);
152         cal.set(Calendar.ERA, GregorianCalendar.BC);
153         cal.set(Calendar.MILLISECOND, 7);
154         LocalDateTime expected = new LocalDateTime(0, 2, 3, 4, 5, 6, 7);
155         assertEquals(expected, LocalDateTime.fromDateFields(cal.getTime()));
156     }
157 
158     public void testFactory_fromDateFields_beforeYearZero3() throws Exception {
159         GregorianCalendar cal = new GregorianCalendar(3, 1, 3, 4, 5, 6);
160         cal.set(Calendar.ERA, GregorianCalendar.BC);
161         cal.set(Calendar.MILLISECOND, 7);
162         LocalDateTime expected = new LocalDateTime(-2, 2, 3, 4, 5, 6, 7);
163         assertEquals(expected, LocalDateTime.fromDateFields(cal.getTime()));
164     }
165 
166     public void testFactory_fromDateFields_null() throws Exception {
167         try {
168             LocalDateTime.fromDateFields((Date) null);
169             fail();
170         } catch (IllegalArgumentException ex) {}
171     }
172 
173     //-----------------------------------------------------------------------
174     public void testConstructor() throws Throwable {
175         LocalDateTime test = new LocalDateTime();
176         assertEquals(ISO_UTC, test.getChronology());
177         assertEquals(1970, test.getYear());
178         assertEquals(6, test.getMonthOfYear());
179         assertEquals(9, test.getDayOfMonth());
180         assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
181         assertEquals(20, test.getMinuteOfHour());
182         assertEquals(30, test.getSecondOfMinute());
183         assertEquals(40, test.getMillisOfSecond());
184         assertEquals(test, LocalDateTime.now());
185     }
186 
187     //-----------------------------------------------------------------------
188     public void testConstructor_DateTimeZone() throws Throwable {
189         DateTime dt = new DateTime(2005, 6, 8, 23, 59, 0, 0, LONDON);
190         DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
191         // 23:59 in London is 00:59 the following day in Paris
192         
193         LocalDateTime test = new LocalDateTime(LONDON);
194         assertEquals(ISO_UTC, test.getChronology());
195         assertEquals(2005, test.getYear());
196         assertEquals(6, test.getMonthOfYear());
197         assertEquals(8, test.getDayOfMonth());
198         assertEquals(23, test.getHourOfDay());
199         assertEquals(59, test.getMinuteOfHour());
200         assertEquals(0, test.getSecondOfMinute());
201         assertEquals(0, test.getMillisOfSecond());
202         assertEquals(test, LocalDateTime.now(LONDON));
203         
204         test = new LocalDateTime(PARIS);
205         assertEquals(ISO_UTC, test.getChronology());
206         assertEquals(2005, test.getYear());
207         assertEquals(6, test.getMonthOfYear());
208         assertEquals(9, test.getDayOfMonth());
209         assertEquals(0, test.getHourOfDay());
210         assertEquals(59, test.getMinuteOfHour());
211         assertEquals(0, test.getSecondOfMinute());
212         assertEquals(0, test.getMillisOfSecond());
213         assertEquals(test, LocalDateTime.now(PARIS));
214     }
215 
216     public void testConstructor_nullDateTimeZone() throws Throwable {
217         LocalDateTime test = new LocalDateTime((DateTimeZone) null);
218         assertEquals(ISO_UTC, test.getChronology());
219         assertEquals(1970, test.getYear());
220         assertEquals(6, test.getMonthOfYear());
221         assertEquals(9, test.getDayOfMonth());
222         assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
223         assertEquals(20, test.getMinuteOfHour());
224         assertEquals(30, test.getSecondOfMinute());
225         assertEquals(40, test.getMillisOfSecond());
226     }
227 
228     //-----------------------------------------------------------------------
229     public void testConstructor_Chronology() throws Throwable {
230         LocalDateTime test = new LocalDateTime(GREGORIAN_PARIS);
231         assertEquals(GREGORIAN_UTC, test.getChronology());
232         assertEquals(1970, test.getYear());
233         assertEquals(6, test.getMonthOfYear());
234         assertEquals(9, test.getDayOfMonth());
235         assertEquals(10 + OFFSET_PARIS, test.getHourOfDay());
236         assertEquals(20, test.getMinuteOfHour());
237         assertEquals(30, test.getSecondOfMinute());
238         assertEquals(40, test.getMillisOfSecond());
239         assertEquals(test, LocalDateTime.now(GREGORIAN_PARIS));
240     }
241 
242     public void testConstructor_nullChronology() throws Throwable {
243         LocalDateTime test = new LocalDateTime((Chronology) null);
244         assertEquals(ISO_UTC, test.getChronology());
245         assertEquals(1970, test.getYear());
246         assertEquals(6, test.getMonthOfYear());
247         assertEquals(9, test.getDayOfMonth());
248         assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
249         assertEquals(20, test.getMinuteOfHour());
250         assertEquals(30, test.getSecondOfMinute());
251         assertEquals(40, test.getMillisOfSecond());
252     }
253 
254     //-----------------------------------------------------------------------
255     public void testConstructor_long1() throws Throwable {
256         LocalDateTime test = new LocalDateTime(TEST_TIME1);
257         assertEquals(ISO_UTC, test.getChronology());
258         assertEquals(1970, test.getYear());
259         assertEquals(4, test.getMonthOfYear());
260         assertEquals(6, test.getDayOfMonth());
261         assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
262         assertEquals(24, test.getMinuteOfHour());
263         assertEquals(0, test.getSecondOfMinute());
264         assertEquals(0, test.getMillisOfSecond());
265     }
266 
267     public void testConstructor_long2() throws Throwable {
268         LocalDateTime test = new LocalDateTime(TEST_TIME2);
269         assertEquals(ISO_UTC, test.getChronology());
270         assertEquals(1971, test.getYear());
271         assertEquals(5, test.getMonthOfYear());
272         assertEquals(7, test.getDayOfMonth());
273         assertEquals(14 + OFFSET_MOSCOW, test.getHourOfDay());
274         assertEquals(28, test.getMinuteOfHour());
275         assertEquals(0, test.getSecondOfMinute());
276         assertEquals(0, test.getMillisOfSecond());
277     }
278 
279     //-----------------------------------------------------------------------
280     public void testConstructor_long1_DateTimeZone() throws Throwable {
281         LocalDateTime test = new LocalDateTime(TEST_TIME1, PARIS);
282         assertEquals(ISO_UTC, test.getChronology());
283         assertEquals(1970, test.getYear());
284         assertEquals(4, test.getMonthOfYear());
285         assertEquals(6, test.getDayOfMonth());
286         assertEquals(12 + OFFSET_PARIS, test.getHourOfDay());
287         assertEquals(24, test.getMinuteOfHour());
288         assertEquals(0, test.getSecondOfMinute());
289         assertEquals(0, test.getMillisOfSecond());
290     }
291 
292     public void testConstructor_long2_DateTimeZone() throws Throwable {
293         LocalDateTime test = new LocalDateTime(TEST_TIME2, PARIS);
294         assertEquals(ISO_UTC, test.getChronology());
295         assertEquals(1971, test.getYear());
296         assertEquals(5, test.getMonthOfYear());
297         assertEquals(7, test.getDayOfMonth());
298         assertEquals(14 + OFFSET_PARIS, test.getHourOfDay());
299         assertEquals(28, test.getMinuteOfHour());
300         assertEquals(0, test.getSecondOfMinute());
301         assertEquals(0, test.getMillisOfSecond());
302     }
303 
304     public void testConstructor_long_nullDateTimeZone() throws Throwable {
305         LocalDateTime test = new LocalDateTime(TEST_TIME1, (DateTimeZone) null);
306         assertEquals(ISO_UTC, test.getChronology());
307         assertEquals(1970, test.getYear());
308         assertEquals(4, test.getMonthOfYear());
309         assertEquals(6, test.getDayOfMonth());
310         assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
311         assertEquals(24, test.getMinuteOfHour());
312         assertEquals(0, test.getSecondOfMinute());
313         assertEquals(0, test.getMillisOfSecond());
314     }
315 
316     //-----------------------------------------------------------------------
317     public void testConstructor_long1_Chronology() throws Throwable {
318         LocalDateTime test = new LocalDateTime(TEST_TIME1, GREGORIAN_PARIS);
319         assertEquals(GREGORIAN_UTC, test.getChronology());
320         assertEquals(1970, test.getYear());
321         assertEquals(4, test.getMonthOfYear());
322         assertEquals(6, test.getDayOfMonth());
323         assertEquals(12 + OFFSET_PARIS, test.getHourOfDay());
324         assertEquals(24, test.getMinuteOfHour());
325         assertEquals(0, test.getSecondOfMinute());
326         assertEquals(0, test.getMillisOfSecond());
327     }
328 
329     public void testConstructor_long2_Chronology() throws Throwable {
330         LocalDateTime test = new LocalDateTime(TEST_TIME2, GREGORIAN_PARIS);
331         assertEquals(GREGORIAN_UTC, test.getChronology());
332         assertEquals(1971, test.getYear());
333         assertEquals(5, test.getMonthOfYear());
334         assertEquals(7, test.getDayOfMonth());
335         assertEquals(14 + OFFSET_PARIS, test.getHourOfDay());
336         assertEquals(28, test.getMinuteOfHour());
337         assertEquals(0, test.getSecondOfMinute());
338         assertEquals(0, test.getMillisOfSecond());
339     }
340 
341     public void testConstructor_long_nullChronology() throws Throwable {
342         LocalDateTime test = new LocalDateTime(TEST_TIME1, (Chronology) null);
343         assertEquals(ISO_UTC, test.getChronology());
344         assertEquals(1970, test.getYear());
345         assertEquals(4, test.getMonthOfYear());
346         assertEquals(6, test.getDayOfMonth());
347         assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
348         assertEquals(24, test.getMinuteOfHour());
349         assertEquals(0, test.getSecondOfMinute());
350         assertEquals(0, test.getMillisOfSecond());
351     }
352 
353     //-----------------------------------------------------------------------
354     public void testConstructor_Object1() throws Throwable {
355         Date date = new Date(TEST_TIME1);
356         LocalDateTime test = new LocalDateTime(date);
357         assertEquals(ISO_UTC, test.getChronology());
358         assertEquals(1970, test.getYear());
359         assertEquals(4, test.getMonthOfYear());
360         assertEquals(6, test.getDayOfMonth());
361         assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
362         assertEquals(24, test.getMinuteOfHour());
363         assertEquals(0, test.getSecondOfMinute());
364         assertEquals(0, test.getMillisOfSecond());
365     }
366 
367     public void testConstructor_nullObject() throws Throwable {
368         LocalDateTime test = new LocalDateTime((Object) null);
369         assertEquals(ISO_UTC, test.getChronology());
370         assertEquals(1970, test.getYear());
371         assertEquals(6, test.getMonthOfYear());
372         assertEquals(9, test.getDayOfMonth());
373         assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
374         assertEquals(20, test.getMinuteOfHour());
375         assertEquals(30, test.getSecondOfMinute());
376         assertEquals(40, test.getMillisOfSecond());
377     }
378 
379     public void testConstructor_ObjectString1() throws Throwable {
380         LocalDateTime test = new LocalDateTime("1972-04-06");
381         assertEquals(ISO_UTC, test.getChronology());
382         assertEquals(1972, test.getYear());
383         assertEquals(4, test.getMonthOfYear());
384         assertEquals(6, test.getDayOfMonth());
385         assertEquals(0, test.getHourOfDay());
386         assertEquals(0, test.getMinuteOfHour());
387         assertEquals(0, test.getSecondOfMinute());
388         assertEquals(0, test.getMillisOfSecond());
389     }
390 
391     public void testConstructor_ObjectString2() throws Throwable {
392         LocalDateTime test = new LocalDateTime("1972-037");
393         assertEquals(ISO_UTC, test.getChronology());
394         assertEquals(1972, test.getYear());
395         assertEquals(2, test.getMonthOfYear());
396         assertEquals(6, test.getDayOfMonth());
397         assertEquals(0, test.getHourOfDay());
398         assertEquals(0, test.getMinuteOfHour());
399         assertEquals(0, test.getSecondOfMinute());
400         assertEquals(0, test.getMillisOfSecond());
401     }
402 
403     public void testConstructor_ObjectString3() throws Throwable {
404         LocalDateTime test = new LocalDateTime("1972-04-06T10:20:30.040");
405         assertEquals(ISO_UTC, test.getChronology());
406         assertEquals(1972, test.getYear());
407         assertEquals(4, test.getMonthOfYear());
408         assertEquals(6, test.getDayOfMonth());
409         assertEquals(10, test.getHourOfDay());
410         assertEquals(20, test.getMinuteOfHour());
411         assertEquals(30, test.getSecondOfMinute());
412         assertEquals(40, test.getMillisOfSecond());
413     }
414 
415     public void testConstructor_ObjectString4() throws Throwable {
416         LocalDateTime test = new LocalDateTime("1972-04-06T10:20");
417         assertEquals(ISO_UTC, test.getChronology());
418         assertEquals(1972, test.getYear());
419         assertEquals(4, test.getMonthOfYear());
420         assertEquals(6, test.getDayOfMonth());
421         assertEquals(10, test.getHourOfDay());
422         assertEquals(20, test.getMinuteOfHour());
423         assertEquals(0, test.getSecondOfMinute());
424         assertEquals(0, test.getMillisOfSecond());
425     }
426 
427     public void testConstructor_ObjectStringEx1() throws Throwable {
428         try {
429             new LocalDateTime("1970-04-06T+14:00");
430             fail();
431         } catch (IllegalArgumentException ex) {}
432     }
433 
434     public void testConstructor_ObjectStringEx2() throws Throwable {
435         try {
436             new LocalDateTime("1970-04-06T10:20:30.040+14:00");
437             fail();
438         } catch (IllegalArgumentException ex) {}
439     }
440 
441     public void testConstructor_ObjectStringEx3() throws Throwable {
442         try {
443             new LocalDateTime("T10:20:30.040");
444             fail();
445         } catch (IllegalArgumentException ex) {}
446     }
447 
448     public void testConstructor_ObjectStringEx4() throws Throwable {
449         try {
450             new LocalDateTime("T10:20:30.040+14:00");
451             fail();
452         } catch (IllegalArgumentException ex) {}
453     }
454 
455     public void testConstructor_ObjectStringEx5() throws Throwable {
456         try {
457             new LocalDateTime("10:20:30.040");
458             fail();
459         } catch (IllegalArgumentException ex) {}
460     }
461 
462     public void testConstructor_ObjectStringEx6() throws Throwable {
463         try {
464             new LocalDateTime("10:20:30.040+14:00");
465             fail();
466         } catch (IllegalArgumentException ex) {}
467     }
468 
469     public void testConstructor_ObjectLocalDateTime() throws Throwable {
470         LocalDateTime dt = new LocalDateTime(1970, 5, 6, 10, 20, 30, 40, BUDDHIST_UTC);
471         LocalDateTime test = new LocalDateTime(dt);
472         assertEquals(BUDDHIST_UTC, test.getChronology());
473         assertEquals(1970, test.getYear());
474         assertEquals(5, test.getMonthOfYear());
475         assertEquals(6, test.getDayOfMonth());
476         assertEquals(10, test.getHourOfDay());
477         assertEquals(20, test.getMinuteOfHour());
478         assertEquals(30, test.getSecondOfMinute());
479         assertEquals(40, test.getMillisOfSecond());
480     }
481 
482     public void testConstructor_ObjectLocalDate() throws Throwable {
483         LocalDate date = new LocalDate(1970, 5, 6);
484         try {
485             new LocalDateTime(date);
486             fail();
487         } catch (IllegalArgumentException ex) {}
488     }
489 
490     public void testConstructor_ObjectLocalTime() throws Throwable {
491         LocalTime time = new LocalTime(10, 20, 30, 40);
492         try {
493             new LocalDateTime(time);
494             fail();
495         } catch (IllegalArgumentException ex) {}
496     }
497 
498     //-----------------------------------------------------------------------
499     public void testConstructor_Object_DateTimeZone() throws Throwable {
500         Date date = new Date(TEST_TIME1);
501         LocalDateTime test = new LocalDateTime(date, PARIS);
502         assertEquals(ISO_UTC, test.getChronology());
503         assertEquals(1970, test.getYear());
504         assertEquals(4, test.getMonthOfYear());
505         assertEquals(6, test.getDayOfMonth());
506         assertEquals(12 + OFFSET_PARIS, test.getHourOfDay());
507         assertEquals(24, test.getMinuteOfHour());
508         assertEquals(0, test.getSecondOfMinute());
509         assertEquals(0, test.getMillisOfSecond());
510     }
511 
512     public void testConstructor_Object_DateTimeZoneMoscow() throws Throwable {
513         LocalDateTime test = new LocalDateTime("1970-04-06T12:24:00", MOSCOW);
514         assertEquals(ISO_UTC, test.getChronology());
515         assertEquals(1970, test.getYear());
516         assertEquals(4, test.getMonthOfYear());
517         assertEquals(6, test.getDayOfMonth());
518         assertEquals(12, test.getHourOfDay());
519         assertEquals(24, test.getMinuteOfHour());
520         assertEquals(0, test.getSecondOfMinute());
521         assertEquals(0, test.getMillisOfSecond());
522     }
523 
524     public void testConstructor_Object_DateTimeZoneMoscowBadDateTime() throws Throwable {
525         // 1981-03-31T23:59:59.999+03:00 followed by 1981-04-01T01:00:00.000+04:00
526         // 1981-09-30T23:59:59.999+04:00 followed by 1981-09-30T23:00:00.000+03:00
527         
528         // when a DST non-existing time is passed in, it should still work (ie. zone ignored)
529         LocalDateTime test = new LocalDateTime("1981-04-01T00:30:00", MOSCOW);  // doesnt exist
530         assertEquals(ISO_UTC, test.getChronology());
531         assertEquals(1981, test.getYear());
532         assertEquals(4, test.getMonthOfYear());
533         assertEquals(1, test.getDayOfMonth());
534         assertEquals(0, test.getHourOfDay());
535         assertEquals(30, test.getMinuteOfHour());
536         assertEquals(0, test.getSecondOfMinute());
537         assertEquals(0, test.getMillisOfSecond());
538     }
539 
540     public void testConstructor_nullObject_DateTimeZone() throws Throwable {
541         LocalDateTime test = new LocalDateTime((Object) null, PARIS);
542         assertEquals(ISO_UTC, test.getChronology());
543         assertEquals(1970, test.getYear());
544         assertEquals(6, test.getMonthOfYear());
545         assertEquals(9, test.getDayOfMonth());
546         assertEquals(10 + OFFSET_PARIS, test.getHourOfDay());
547         assertEquals(20, test.getMinuteOfHour());
548         assertEquals(30, test.getSecondOfMinute());
549         assertEquals(40, test.getMillisOfSecond());
550     }
551 
552     public void testConstructor_Object_nullDateTimeZone() throws Throwable {
553         Date date = new Date(TEST_TIME1);
554         LocalDateTime test = new LocalDateTime(date, (DateTimeZone) null);
555         assertEquals(ISO_UTC, test.getChronology());
556         assertEquals(1970, test.getYear());
557         assertEquals(4, test.getMonthOfYear());
558         assertEquals(6, test.getDayOfMonth());
559         assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
560         assertEquals(24, test.getMinuteOfHour());
561         assertEquals(0, test.getSecondOfMinute());
562         assertEquals(0, test.getMillisOfSecond());
563     }
564 
565     public void testConstructor_nullObject_nullDateTimeZone() throws Throwable {
566         LocalDateTime test = new LocalDateTime((Object) null, (DateTimeZone) null);
567         assertEquals(ISO_UTC, test.getChronology());
568         assertEquals(1970, test.getYear());
569         assertEquals(6, test.getMonthOfYear());
570         assertEquals(9, test.getDayOfMonth());
571         assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
572         assertEquals(20, test.getMinuteOfHour());
573         assertEquals(30, test.getSecondOfMinute());
574         assertEquals(40, test.getMillisOfSecond());
575     }
576 
577     //-----------------------------------------------------------------------
578     public void testConstructor_Object_Chronology() throws Throwable {
579         Date date = new Date(TEST_TIME1);
580         LocalDateTime test = new LocalDateTime(date, GREGORIAN_PARIS);
581         assertEquals(GREGORIAN_UTC, test.getChronology());
582         assertEquals(1970, test.getYear());
583         assertEquals(4, test.getMonthOfYear());
584         assertEquals(6, test.getDayOfMonth());
585         assertEquals(12 + OFFSET_PARIS, test.getHourOfDay());
586         assertEquals(24, test.getMinuteOfHour());
587         assertEquals(0, test.getSecondOfMinute());
588         assertEquals(0, test.getMillisOfSecond());
589     }
590 
591     public void testConstructor_Object_Chronology_crossChronology() throws Throwable {
592         LocalDateTime input = new LocalDateTime(1970, 4, 6, 12, 30, 0, 0, ISO_UTC);
593         LocalDateTime test = new LocalDateTime(input, BUDDHIST_UTC);
594         assertEquals(BUDDHIST_UTC, test.getChronology());
595         assertEquals(1970, test.getYear());
596         assertEquals(4, test.getMonthOfYear());
597         assertEquals(6, test.getDayOfMonth());
598         assertEquals(12, test.getHourOfDay());
599         assertEquals(30, test.getMinuteOfHour());
600         assertEquals(0, test.getSecondOfMinute());
601         assertEquals(0, test.getMillisOfSecond());
602     }
603 
604     public void testConstructor_Object_ChronologyMoscow() throws Throwable {
605         LocalDateTime test = new LocalDateTime("1970-04-06T12:24:00", GREGORIAN_MOSCOW);
606         assertEquals(GREGORIAN_UTC, test.getChronology());
607         assertEquals(1970, test.getYear());
608         assertEquals(4, test.getMonthOfYear());
609         assertEquals(6, test.getDayOfMonth());
610         assertEquals(12, test.getHourOfDay());
611         assertEquals(24, test.getMinuteOfHour());
612         assertEquals(0, test.getSecondOfMinute());
613         assertEquals(0, test.getMillisOfSecond());
614     }
615 
616     public void testConstructor_Object_ChronologyMoscowBadDateTime() throws Throwable {
617         // 1981-03-31T23:59:59.999+03:00 followed by 1981-04-01T01:00:00.000+04:00
618         // 1981-09-30T23:59:59.999+04:00 followed by 1981-09-30T23:00:00.000+03:00
619         
620         // when a DST non-existing time is passed in, it should still work (ie. zone ignored)
621         LocalDateTime test = new LocalDateTime("1981-04-01T00:30:00", GREGORIAN_MOSCOW);  // doesnt exist
622         assertEquals(GREGORIAN_UTC, test.getChronology());
623         assertEquals(1981, test.getYear());
624         assertEquals(4, test.getMonthOfYear());
625         assertEquals(1, test.getDayOfMonth());
626         assertEquals(0, test.getHourOfDay());
627         assertEquals(30, test.getMinuteOfHour());
628         assertEquals(0, test.getSecondOfMinute());
629         assertEquals(0, test.getMillisOfSecond());
630     }
631 
632     public void testConstructor_nullObject_Chronology() throws Throwable {
633         LocalDateTime test = new LocalDateTime((Object) null, GREGORIAN_PARIS);
634         assertEquals(GREGORIAN_UTC, test.getChronology());
635         assertEquals(1970, test.getYear());
636         assertEquals(6, test.getMonthOfYear());
637         assertEquals(9, test.getDayOfMonth());
638         assertEquals(10 + OFFSET_PARIS, test.getHourOfDay());
639         assertEquals(20, test.getMinuteOfHour());
640         assertEquals(30, test.getSecondOfMinute());
641         assertEquals(40, test.getMillisOfSecond());
642     }
643 
644     public void testConstructor_Object_nullChronology() throws Throwable {
645         Date date = new Date(TEST_TIME1);
646         LocalDateTime test = new LocalDateTime(date, (Chronology) null);
647         assertEquals(ISO_UTC, test.getChronology());
648         assertEquals(1970, test.getYear());
649         assertEquals(4, test.getMonthOfYear());
650         assertEquals(6, test.getDayOfMonth());
651         assertEquals(12 + OFFSET_MOSCOW, test.getHourOfDay());
652         assertEquals(24, test.getMinuteOfHour());
653         assertEquals(0, test.getSecondOfMinute());
654         assertEquals(0, test.getMillisOfSecond());
655     }
656 
657     public void testConstructor_nullObject_nullChronology() throws Throwable {
658         LocalDateTime test = new LocalDateTime((Object) null, (Chronology) null);
659         assertEquals(ISO_UTC, test.getChronology());
660         assertEquals(1970, test.getYear());
661         assertEquals(6, test.getMonthOfYear());
662         assertEquals(9, test.getDayOfMonth());
663         assertEquals(10 + OFFSET_MOSCOW, test.getHourOfDay());
664         assertEquals(20, test.getMinuteOfHour());
665         assertEquals(30, test.getSecondOfMinute());
666         assertEquals(40, test.getMillisOfSecond());
667     }
668 
669     //-----------------------------------------------------------------------
670     public void testConstructor_int_int_int_int_int() throws Throwable {
671         LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20);
672         assertEquals(ISO_UTC, test.getChronology());
673         assertEquals(2005, test.getYear());
674         assertEquals(6, test.getMonthOfYear());
675         assertEquals(9, test.getDayOfMonth());
676         assertEquals(10, test.getHourOfDay());
677         assertEquals(20, test.getMinuteOfHour());
678         assertEquals(0, test.getSecondOfMinute());
679         assertEquals(0, test.getMillisOfSecond());
680     }
681 
682     //-----------------------------------------------------------------------
683     public void testConstructor_int_int_int_int_int_int() throws Throwable {
684         LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30);
685         assertEquals(ISO_UTC, test.getChronology());
686         assertEquals(2005, test.getYear());
687         assertEquals(6, test.getMonthOfYear());
688         assertEquals(9, test.getDayOfMonth());
689         assertEquals(10, test.getHourOfDay());
690         assertEquals(20, test.getMinuteOfHour());
691         assertEquals(30, test.getSecondOfMinute());
692         assertEquals(0, test.getMillisOfSecond());
693     }
694 
695     //-----------------------------------------------------------------------
696     public void testConstructor_int_int_int_int_int_int_int() throws Throwable {
697         LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40);
698         assertEquals(ISO_UTC, test.getChronology());
699         assertEquals(2005, test.getYear());
700         assertEquals(6, test.getMonthOfYear());
701         assertEquals(9, test.getDayOfMonth());
702         assertEquals(10, test.getHourOfDay());
703         assertEquals(20, test.getMinuteOfHour());
704         assertEquals(30, test.getSecondOfMinute());
705         assertEquals(40, test.getMillisOfSecond());
706         try {
707             new LocalDateTime(Integer.MIN_VALUE, 6, 9, 10, 20, 30, 40);
708             fail();
709         } catch (IllegalArgumentException ex) {}
710         try {
711             new LocalDateTime(Integer.MAX_VALUE, 6, 9, 10, 20, 30, 40);
712             fail();
713         } catch (IllegalArgumentException ex) {}
714         try {
715             new LocalDateTime(2005, 0, 9, 10, 20, 30, 40);
716             fail();
717         } catch (IllegalArgumentException ex) {}
718         try {
719             new LocalDateTime(2005, 13, 9, 10, 20, 30, 40);
720             fail();
721         } catch (IllegalArgumentException ex) {}
722         try {
723             new LocalDateTime(2005, 6, 0, 10, 20, 30, 40);
724             fail();
725         } catch (IllegalArgumentException ex) {}
726         try {
727             new LocalDateTime(2005, 6, 31, 10, 20, 30, 40);
728             fail();
729         } catch (IllegalArgumentException ex) {}
730         new LocalDateTime(2005, 7, 31, 10, 20, 30, 40);
731         try {
732             new LocalDateTime(2005, 7, 32, 10, 20, 30, 40);
733             fail();
734         } catch (IllegalArgumentException ex) {}
735     }
736 
737     public void testConstructor_int_int_int_Chronology() throws Throwable {
738         LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40, GREGORIAN_PARIS);
739         assertEquals(GREGORIAN_UTC, test.getChronology());
740         assertEquals(2005, test.getYear());
741         assertEquals(6, test.getMonthOfYear());
742         assertEquals(9, test.getDayOfMonth());
743         assertEquals(10, test.getHourOfDay());  // PARIS has no effect
744         assertEquals(20, test.getMinuteOfHour());
745         assertEquals(30, test.getSecondOfMinute());
746         assertEquals(40, test.getMillisOfSecond());
747         try {
748             new LocalDateTime(Integer.MIN_VALUE, 6, 9, 10, 20, 30, 40, GREGORIAN_PARIS);
749             fail();
750         } catch (IllegalArgumentException ex) {}
751         try {
752             new LocalDateTime(Integer.MAX_VALUE, 6, 9, 10, 20, 30, 40, GREGORIAN_PARIS);
753             fail();
754         } catch (IllegalArgumentException ex) {}
755         try {
756             new LocalDateTime(2005, 0, 9, 10, 20, 30, 40, GREGORIAN_PARIS);
757             fail();
758         } catch (IllegalArgumentException ex) {}
759         try {
760             new LocalDateTime(2005, 13, 9, 10, 20, 30, 40, GREGORIAN_PARIS);
761             fail();
762         } catch (IllegalArgumentException ex) {}
763         try {
764             new LocalDateTime(2005, 6, 0, 10, 20, 30, 40, GREGORIAN_PARIS);
765             fail();
766         } catch (IllegalArgumentException ex) {}
767         try {
768             new LocalDateTime(2005, 6, 31, 10, 20, 30, 40, GREGORIAN_PARIS);
769             fail();
770         } catch (IllegalArgumentException ex) {}
771         new LocalDateTime(2005, 7, 31, 10, 20, 30, 40, GREGORIAN_PARIS);
772         try {
773             new LocalDateTime(2005, 7, 32, 10, 20, 30, 40, GREGORIAN_PARIS);
774             fail();
775         } catch (IllegalArgumentException ex) {}
776     }
777 
778     public void testConstructor_int_int_int_nullChronology() throws Throwable {
779         LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40, null);
780         assertEquals(ISO_UTC, test.getChronology());
781         assertEquals(2005, test.getYear());
782         assertEquals(6, test.getMonthOfYear());
783         assertEquals(9, test.getDayOfMonth());
784     }
785 
786 }