001    /*
002     *  Copyright 2001-2005 Stephen Colebourne
003     *
004     *  Licensed under the Apache License, Version 2.0 (the "License");
005     *  you may not use this file except in compliance with the License.
006     *  You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     *  Unless required by applicable law or agreed to in writing, software
011     *  distributed under the License is distributed on an "AS IS" BASIS,
012     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     *  See the License for the specific language governing permissions and
014     *  limitations under the License.
015     */
016    package org.joda.time;
017    
018    import java.util.Locale;
019    
020    import junit.framework.TestCase;
021    import junit.framework.TestSuite;
022    
023    /**
024     * This class is a Junit unit test for DateTime.
025     *
026     * @author Stephen Colebourne
027     * @author Mike Schrag
028     */
029    public class TestMutableDateTime_Properties extends TestCase {
030        // Test in 2002/03 as time zones are more well known
031        // (before the late 90's they were all over the place)
032    
033        //private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
034        private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
035        
036        long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
037                         366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
038                         365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
039                         366 + 365;
040        long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
041                         366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
042                         365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
043                         366 + 365 + 365;
044        
045        // 2002-06-09
046        private long TEST_TIME_NOW =
047                (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
048                
049        // 2002-04-05 Fri
050        private long TEST_TIME1 =
051                (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
052                + 12L * DateTimeConstants.MILLIS_PER_HOUR
053                + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
054            
055        // 2003-05-06 Tue
056        private long TEST_TIME2 =
057                (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
058                + 14L * DateTimeConstants.MILLIS_PER_HOUR
059                + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
060            
061        private DateTimeZone zone = null;
062        private Locale locale = null;
063    
064        public static void main(String[] args) {
065            junit.textui.TestRunner.run(suite());
066        }
067    
068        public static TestSuite suite() {
069            return new TestSuite(TestMutableDateTime_Properties.class);
070        }
071    
072        public TestMutableDateTime_Properties(String name) {
073            super(name);
074        }
075    
076        protected void setUp() throws Exception {
077            DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
078            zone = DateTimeZone.getDefault();
079            locale = Locale.getDefault();
080            DateTimeZone.setDefault(LONDON);
081            Locale.setDefault(Locale.UK);
082        }
083    
084        protected void tearDown() throws Exception {
085            DateTimeUtils.setCurrentMillisSystem();
086            DateTimeZone.setDefault(zone);
087            Locale.setDefault(locale);
088            zone = null;
089        }
090    
091        //-----------------------------------------------------------------------
092        public void testTest() {
093            assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
094            assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
095            assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
096        }
097    
098        //-----------------------------------------------------------------------
099        public void testPropertyGetEra() {
100            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
101            assertSame(test.getChronology().era(), test.era().getField());
102            assertEquals("era", test.era().getName());
103            assertEquals("Property[era]", test.era().toString());
104            assertSame(test, test.era().getMutableDateTime());
105            assertEquals(1, test.era().get());
106            assertEquals("AD", test.era().getAsText());
107            assertEquals("ap. J.-C.", test.era().getAsText(Locale.FRENCH));
108            assertEquals("AD", test.era().getAsShortText());
109            assertEquals("ap. J.-C.", test.era().getAsShortText(Locale.FRENCH));
110            assertEquals(test.getChronology().eras(), test.era().getDurationField());
111            assertEquals(null, test.era().getRangeDurationField());
112            assertEquals(2, test.era().getMaximumTextLength(null));
113            assertEquals(9, test.era().getMaximumTextLength(Locale.FRENCH));
114            assertEquals(2, test.era().getMaximumShortTextLength(null));
115            assertEquals(9, test.era().getMaximumShortTextLength(Locale.FRENCH));
116        }
117    
118        //-----------------------------------------------------------------------
119        public void testPropertyGetYearOfEra() {
120            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
121            assertSame(test.getChronology().yearOfEra(), test.yearOfEra().getField());
122            assertEquals("yearOfEra", test.yearOfEra().getName());
123            assertEquals("Property[yearOfEra]", test.yearOfEra().toString());
124            assertEquals(2004, test.yearOfEra().get());
125            assertEquals("2004", test.yearOfEra().getAsText());
126            assertEquals("2004", test.yearOfEra().getAsText(Locale.FRENCH));
127            assertEquals("2004", test.yearOfEra().getAsShortText());
128            assertEquals("2004", test.yearOfEra().getAsShortText(Locale.FRENCH));
129            assertEquals(test.getChronology().years(), test.yearOfEra().getDurationField());
130            assertEquals(null, test.yearOfEra().getRangeDurationField());
131            assertEquals(9, test.yearOfEra().getMaximumTextLength(null));
132            assertEquals(9, test.yearOfEra().getMaximumShortTextLength(null));
133        }
134    
135        //-----------------------------------------------------------------------
136        public void testPropertyGetCenturyOfEra() {
137            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
138            assertSame(test.getChronology().centuryOfEra(), test.centuryOfEra().getField());
139            assertEquals("centuryOfEra", test.centuryOfEra().getName());
140            assertEquals("Property[centuryOfEra]", test.centuryOfEra().toString());
141            assertEquals(20, test.centuryOfEra().get());
142            assertEquals("20", test.centuryOfEra().getAsText());
143            assertEquals("20", test.centuryOfEra().getAsText(Locale.FRENCH));
144            assertEquals("20", test.centuryOfEra().getAsShortText());
145            assertEquals("20", test.centuryOfEra().getAsShortText(Locale.FRENCH));
146            assertEquals(test.getChronology().centuries(), test.centuryOfEra().getDurationField());
147            assertEquals(null, test.centuryOfEra().getRangeDurationField());
148            assertEquals(7, test.centuryOfEra().getMaximumTextLength(null));
149            assertEquals(7, test.centuryOfEra().getMaximumShortTextLength(null));
150        }
151    
152        //-----------------------------------------------------------------------
153        public void testPropertyGetYearOfCentury() {
154            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
155            assertSame(test.getChronology().yearOfCentury(), test.yearOfCentury().getField());
156            assertEquals("yearOfCentury", test.yearOfCentury().getName());
157            assertEquals("Property[yearOfCentury]", test.yearOfCentury().toString());
158            assertEquals(4, test.yearOfCentury().get());
159            assertEquals("4", test.yearOfCentury().getAsText());
160            assertEquals("4", test.yearOfCentury().getAsText(Locale.FRENCH));
161            assertEquals("4", test.yearOfCentury().getAsShortText());
162            assertEquals("4", test.yearOfCentury().getAsShortText(Locale.FRENCH));
163            assertEquals(test.getChronology().years(), test.yearOfCentury().getDurationField());
164            assertEquals(test.getChronology().centuries(), test.yearOfCentury().getRangeDurationField());
165            assertEquals(2, test.yearOfCentury().getMaximumTextLength(null));
166            assertEquals(2, test.yearOfCentury().getMaximumShortTextLength(null));
167        }
168    
169        //-----------------------------------------------------------------------
170        public void testPropertyGetWeekyear() {
171            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
172            assertSame(test.getChronology().weekyear(), test.weekyear().getField());
173            assertEquals("weekyear", test.weekyear().getName());
174            assertEquals("Property[weekyear]", test.weekyear().toString());
175            assertEquals(2004, test.weekyear().get());
176            assertEquals("2004", test.weekyear().getAsText());
177            assertEquals("2004", test.weekyear().getAsText(Locale.FRENCH));
178            assertEquals("2004", test.weekyear().getAsShortText());
179            assertEquals("2004", test.weekyear().getAsShortText(Locale.FRENCH));
180            assertEquals(test.getChronology().weekyears(), test.weekyear().getDurationField());
181            assertEquals(null, test.weekyear().getRangeDurationField());
182            assertEquals(9, test.weekyear().getMaximumTextLength(null));
183            assertEquals(9, test.weekyear().getMaximumShortTextLength(null));
184        }
185    
186        //-----------------------------------------------------------------------
187        public void testPropertyGetYear() {
188            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
189            assertSame(test.getChronology().year(), test.year().getField());
190            assertEquals("year", test.year().getName());
191            assertEquals("Property[year]", test.year().toString());
192            assertEquals(2004, test.year().get());
193            assertEquals("2004", test.year().getAsText());
194            assertEquals("2004", test.year().getAsText(Locale.FRENCH));
195            assertEquals("2004", test.year().getAsShortText());
196            assertEquals("2004", test.year().getAsShortText(Locale.FRENCH));
197            assertEquals(test.getChronology().years(), test.year().getDurationField());
198            assertEquals(null, test.year().getRangeDurationField());
199            assertEquals(9, test.year().getMaximumTextLength(null));
200            assertEquals(9, test.year().getMaximumShortTextLength(null));
201            assertEquals(-292275054, test.year().getMinimumValue());
202            assertEquals(-292275054, test.year().getMinimumValueOverall());
203            assertEquals(292278993, test.year().getMaximumValue());
204            assertEquals(292278993, test.year().getMaximumValueOverall());
205        }
206    
207        public void testPropertyAddYear() {
208            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
209            test.year().add(9);
210            assertEquals("2013-06-09T00:00:00.000+01:00", test.toString());
211        }
212    
213        public void testPropertyAddWrapFieldYear() {
214            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
215            test.year().addWrapField(9);
216            assertEquals("2013-06-09T00:00:00.000+01:00", test.toString());
217        }
218    
219        public void testPropertySetYear() {
220            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
221            test.year().set(1960);
222            assertEquals("1960-06-09T00:00:00.000+01:00", test.toString());
223        }
224    
225        public void testPropertySetTextYear() {
226            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
227            test.year().set("1960");
228            assertEquals("1960-06-09T00:00:00.000+01:00", test.toString());
229        }
230    
231        //-----------------------------------------------------------------------
232        public void testPropertyGetMonthOfYear() {
233            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
234            assertSame(test.getChronology().monthOfYear(), test.monthOfYear().getField());
235            assertEquals("monthOfYear", test.monthOfYear().getName());
236            assertEquals("Property[monthOfYear]", test.monthOfYear().toString());
237            assertEquals(6, test.monthOfYear().get());
238            assertEquals("June", test.monthOfYear().getAsText());
239            assertEquals("juin", test.monthOfYear().getAsText(Locale.FRENCH));
240            assertEquals("Jun", test.monthOfYear().getAsShortText());
241            assertEquals("juin", test.monthOfYear().getAsShortText(Locale.FRENCH));
242            assertEquals(test.getChronology().months(), test.monthOfYear().getDurationField());
243            assertEquals(test.getChronology().years(), test.monthOfYear().getRangeDurationField());
244            assertEquals(9, test.monthOfYear().getMaximumTextLength(null));
245            assertEquals(3, test.monthOfYear().getMaximumShortTextLength(null));
246            test = new MutableDateTime(2004, 7, 9, 0, 0, 0, 0);
247            assertEquals("juillet", test.monthOfYear().getAsText(Locale.FRENCH));
248            assertEquals("juil.", test.monthOfYear().getAsShortText(Locale.FRENCH));
249            assertEquals(1, test.monthOfYear().getMinimumValue());
250            assertEquals(1, test.monthOfYear().getMinimumValueOverall());
251            assertEquals(12, test.monthOfYear().getMaximumValue());
252            assertEquals(12, test.monthOfYear().getMaximumValueOverall());
253            assertEquals(1, test.monthOfYear().getMinimumValue());
254            assertEquals(1, test.monthOfYear().getMinimumValueOverall());
255            assertEquals(12, test.monthOfYear().getMaximumValue());
256            assertEquals(12, test.monthOfYear().getMaximumValueOverall());
257        }
258    
259        public void testPropertyAddMonthOfYear() {
260            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
261            test.monthOfYear().add(6);
262            assertEquals("2004-12-09T00:00:00.000Z", test.toString());
263        }
264    
265        public void testPropertyAddWrapFieldMonthOfYear() {
266            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
267            test.monthOfYear().addWrapField(8);
268            assertEquals("2004-02-09T00:00:00.000Z", test.toString());
269        }
270    
271        public void testPropertySetMonthOfYear() {
272            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
273            test.monthOfYear().set(12);
274            assertEquals("2004-12-09T00:00:00.000Z", test.toString());
275        }
276    
277        public void testPropertySetTextMonthOfYear() {
278            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
279            test.monthOfYear().set("12");
280            assertEquals("2004-12-09T00:00:00.000Z", test.toString());
281            
282            test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
283            test.monthOfYear().set("December");
284            assertEquals("2004-12-09T00:00:00.000Z", test.toString());
285            
286            test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
287            test.monthOfYear().set("Dec");
288            assertEquals("2004-12-09T00:00:00.000Z", test.toString());
289        }
290    
291        //-----------------------------------------------------------------------
292        public void testPropertyGetDayOfMonth() {
293            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
294            assertSame(test.getChronology().dayOfMonth(), test.dayOfMonth().getField());
295            assertEquals("dayOfMonth", test.dayOfMonth().getName());
296            assertEquals("Property[dayOfMonth]", test.dayOfMonth().toString());
297            assertEquals(9, test.dayOfMonth().get());
298            assertEquals("9", test.dayOfMonth().getAsText());
299            assertEquals("9", test.dayOfMonth().getAsText(Locale.FRENCH));
300            assertEquals("9", test.dayOfMonth().getAsShortText());
301            assertEquals("9", test.dayOfMonth().getAsShortText(Locale.FRENCH));
302            assertEquals(test.getChronology().days(), test.dayOfMonth().getDurationField());
303            assertEquals(test.getChronology().months(), test.dayOfMonth().getRangeDurationField());
304            assertEquals(2, test.dayOfMonth().getMaximumTextLength(null));
305            assertEquals(2, test.dayOfMonth().getMaximumShortTextLength(null));
306            assertEquals(1, test.dayOfMonth().getMinimumValue());
307            assertEquals(1, test.dayOfMonth().getMinimumValueOverall());
308            assertEquals(30, test.dayOfMonth().getMaximumValue());
309            assertEquals(31, test.dayOfMonth().getMaximumValueOverall());
310            assertEquals(false, test.dayOfMonth().isLeap());
311            assertEquals(0, test.dayOfMonth().getLeapAmount());
312            assertEquals(null, test.dayOfMonth().getLeapDurationField());
313        }
314    
315        public void testPropertyAddDayOfMonth() {
316            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
317            test.dayOfMonth().add(9);
318            assertEquals("2004-06-18T00:00:00.000+01:00", test.toString());
319        }
320    
321        public void testPropertyAddWrapFieldDayOfMonth() {
322            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
323            test.dayOfMonth().addWrapField(22);
324            assertEquals("2004-06-01T00:00:00.000+01:00", test.toString());
325        }
326    
327        public void testPropertySetDayOfMonth() {
328            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
329            test.dayOfMonth().set(12);
330            assertEquals("2004-06-12T00:00:00.000+01:00", test.toString());
331        }
332    
333        public void testPropertySetTextDayOfMonth() {
334            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
335            test.dayOfMonth().set("12");
336            assertEquals("2004-06-12T00:00:00.000+01:00", test.toString());
337        }
338    
339        //-----------------------------------------------------------------------
340        public void testPropertyGetDayOfYear() {
341            // 31+29+31+30+31+9 = 161
342            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
343            assertSame(test.getChronology().dayOfYear(), test.dayOfYear().getField());
344            assertEquals("dayOfYear", test.dayOfYear().getName());
345            assertEquals("Property[dayOfYear]", test.dayOfYear().toString());
346            assertEquals(161, test.dayOfYear().get());
347            assertEquals("161", test.dayOfYear().getAsText());
348            assertEquals("161", test.dayOfYear().getAsText(Locale.FRENCH));
349            assertEquals("161", test.dayOfYear().getAsShortText());
350            assertEquals("161", test.dayOfYear().getAsShortText(Locale.FRENCH));
351            assertEquals(test.getChronology().days(), test.dayOfYear().getDurationField());
352            assertEquals(test.getChronology().years(), test.dayOfYear().getRangeDurationField());
353            assertEquals(3, test.dayOfYear().getMaximumTextLength(null));
354            assertEquals(3, test.dayOfYear().getMaximumShortTextLength(null));
355            assertEquals(false, test.dayOfYear().isLeap());
356            assertEquals(0, test.dayOfYear().getLeapAmount());
357            assertEquals(null, test.dayOfYear().getLeapDurationField());
358        }
359    
360        public void testPropertyAddDayOfYear() {
361            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
362            test.dayOfYear().add(9);
363            assertEquals("2004-06-18T00:00:00.000+01:00", test.toString());
364        }
365    
366        public void testPropertyAddWrapFieldDayOfYear() {
367            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
368            test.dayOfYear().addWrapField(206);
369            assertEquals("2004-01-01T00:00:00.000Z", test.toString());
370        }
371    
372        public void testPropertySetDayOfYear() {
373            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
374            test.dayOfYear().set(12);
375            assertEquals("2004-01-12T00:00:00.000Z", test.toString());
376        }
377    
378        public void testPropertySetTextDayOfYear() {
379            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
380            test.dayOfYear().set("12");
381            assertEquals("2004-01-12T00:00:00.000Z", test.toString());
382        }
383    
384        //-----------------------------------------------------------------------
385        public void testPropertyGetWeekOfWeekyear() {
386            // 2002-01-01 = Thu
387            // 2002-12-31 = Thu (+364 days)
388            // 2003-12-30 = Thu (+364 days)
389            // 2004-01-03 = Mon             W1
390            // 2004-01-31 = Mon (+28 days)  W5
391            // 2004-02-28 = Mon (+28 days)  W9
392            // 2004-03-27 = Mon (+28 days)  W13
393            // 2004-04-24 = Mon (+28 days)  W17
394            // 2004-05-23 = Mon (+28 days)  W21
395            // 2004-06-05 = Mon (+14 days)  W23
396            // 2004-06-09 = Fri
397            // 2004-12-25 = Mon             W52
398            // 2005-01-01 = Mon             W1
399            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
400            assertSame(test.getChronology().weekOfWeekyear(), test.weekOfWeekyear().getField());
401            assertEquals("weekOfWeekyear", test.weekOfWeekyear().getName());
402            assertEquals("Property[weekOfWeekyear]", test.weekOfWeekyear().toString());
403            assertEquals(24, test.weekOfWeekyear().get());
404            assertEquals("24", test.weekOfWeekyear().getAsText());
405            assertEquals("24", test.weekOfWeekyear().getAsText(Locale.FRENCH));
406            assertEquals("24", test.weekOfWeekyear().getAsShortText());
407            assertEquals("24", test.weekOfWeekyear().getAsShortText(Locale.FRENCH));
408            assertEquals(test.getChronology().weeks(), test.weekOfWeekyear().getDurationField());
409            assertEquals(test.getChronology().weekyears(), test.weekOfWeekyear().getRangeDurationField());
410            assertEquals(2, test.weekOfWeekyear().getMaximumTextLength(null));
411            assertEquals(2, test.weekOfWeekyear().getMaximumShortTextLength(null));
412            assertEquals(false, test.weekOfWeekyear().isLeap());
413            assertEquals(0, test.weekOfWeekyear().getLeapAmount());
414            assertEquals(null, test.weekOfWeekyear().getLeapDurationField());
415        }
416    
417        public void testPropertyAddWeekOfWeekyear() {
418            MutableDateTime test = new MutableDateTime(2004, 6, 7, 0, 0, 0, 0);
419            test.weekOfWeekyear().add(1);
420            assertEquals("2004-06-14T00:00:00.000+01:00", test.toString());
421        }
422    
423        public void testPropertyAddWrapFieldWeekOfWeekyear() {
424            MutableDateTime test = new MutableDateTime(2004, 6, 7, 0, 0, 0, 0);
425            test.weekOfWeekyear().addWrapField(30);
426            assertEquals("2003-12-29T00:00:00.000Z", test.toString());
427        }
428    
429        public void testPropertySetWeekOfWeekyear() {
430            MutableDateTime test = new MutableDateTime(2004, 6, 7, 0, 0, 0, 0);
431            test.weekOfWeekyear().set(4);
432            assertEquals("2004-01-19T00:00:00.000Z", test.toString());
433        }
434    
435        public void testPropertySetTextWeekOfWeekyear() {
436            MutableDateTime test = new MutableDateTime(2004, 6, 7, 0, 0, 0, 0);
437            test.weekOfWeekyear().set("4");
438            assertEquals("2004-01-19T00:00:00.000Z", test.toString());
439        }
440    
441        //-----------------------------------------------------------------------
442        public void testPropertyGetDayOfWeek() {
443            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
444            assertSame(test.getChronology().dayOfWeek(), test.dayOfWeek().getField());
445            assertEquals("dayOfWeek", test.dayOfWeek().getName());
446            assertEquals("Property[dayOfWeek]", test.dayOfWeek().toString());
447            assertEquals(3, test.dayOfWeek().get());
448            assertEquals("Wednesday", test.dayOfWeek().getAsText());
449            assertEquals("mercredi", test.dayOfWeek().getAsText(Locale.FRENCH));
450            assertEquals("Wed", test.dayOfWeek().getAsShortText());
451            assertEquals("mer.", test.dayOfWeek().getAsShortText(Locale.FRENCH));
452            assertEquals(test.getChronology().days(), test.dayOfWeek().getDurationField());
453            assertEquals(test.getChronology().weeks(), test.dayOfWeek().getRangeDurationField());
454            assertEquals(9, test.dayOfWeek().getMaximumTextLength(null));
455            assertEquals(8, test.dayOfWeek().getMaximumTextLength(Locale.FRENCH));
456            assertEquals(3, test.dayOfWeek().getMaximumShortTextLength(null));
457            assertEquals(4, test.dayOfWeek().getMaximumShortTextLength(Locale.FRENCH));
458            assertEquals(1, test.dayOfWeek().getMinimumValue());
459            assertEquals(1, test.dayOfWeek().getMinimumValueOverall());
460            assertEquals(7, test.dayOfWeek().getMaximumValue());
461            assertEquals(7, test.dayOfWeek().getMaximumValueOverall());
462            assertEquals(false, test.dayOfWeek().isLeap());
463            assertEquals(0, test.dayOfWeek().getLeapAmount());
464            assertEquals(null, test.dayOfWeek().getLeapDurationField());
465        }
466    
467        public void testPropertyAddDayOfWeek() {
468            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
469            test.dayOfWeek().add(1);
470            assertEquals("2004-06-10T00:00:00.000+01:00", test.toString());
471        }
472    
473        public void testPropertyAddLongDayOfWeek() {
474            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
475            test.dayOfWeek().add(1L);
476            assertEquals("2004-06-10T00:00:00.000+01:00", test.toString());
477        }
478    
479        public void testPropertyAddWrapFieldDayOfWeek() {
480            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);  // Wed
481            test.dayOfWeek().addWrapField(5);
482            assertEquals("2004-06-07T00:00:00.000+01:00", test.toString());
483        }
484    
485        public void testPropertySetDayOfWeek() {
486            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
487            test.dayOfWeek().set(4);
488            assertEquals("2004-06-10T00:00:00.000+01:00", test.toString());
489        }
490    
491        public void testPropertySetTextDayOfWeek() {
492            MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
493            test.dayOfWeek().set("4");
494            assertEquals("2004-06-10T00:00:00.000+01:00", test.toString());
495            
496            test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
497            test.dayOfWeek().set("Mon");
498            assertEquals("2004-06-07T00:00:00.000+01:00", test.toString());
499            
500            test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
501            test.dayOfWeek().set("Tuesday");
502            assertEquals("2004-06-08T00:00:00.000+01:00", test.toString());
503            
504            test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
505            test.dayOfWeek().set("lundi", Locale.FRENCH);
506            assertEquals("2004-06-07T00:00:00.000+01:00", test.toString());
507        }
508    
509        //-----------------------------------------------------------------------
510        public void testPropertyGetHourOfDay() {
511            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
512            assertSame(test.getChronology().hourOfDay(), test.hourOfDay().getField());
513            assertEquals("hourOfDay", test.hourOfDay().getName());
514            assertEquals("Property[hourOfDay]", test.hourOfDay().toString());
515            assertEquals(13, test.hourOfDay().get());
516            assertEquals("13", test.hourOfDay().getAsText());
517            assertEquals("13", test.hourOfDay().getAsText(Locale.FRENCH));
518            assertEquals("13", test.hourOfDay().getAsShortText());
519            assertEquals("13", test.hourOfDay().getAsShortText(Locale.FRENCH));
520            assertEquals(test.getChronology().hours(), test.hourOfDay().getDurationField());
521            assertEquals(test.getChronology().days(), test.hourOfDay().getRangeDurationField());
522            assertEquals(2, test.hourOfDay().getMaximumTextLength(null));
523            assertEquals(2, test.hourOfDay().getMaximumShortTextLength(null));
524        }
525    
526        public void testPropertyRoundFloorHourOfDay() {
527            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 0);
528            test.hourOfDay().roundFloor();
529            assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
530        }
531    
532        public void testPropertyRoundCeilingHourOfDay() {
533            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 0);
534            test.hourOfDay().roundCeiling();
535            assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
536        }
537    
538        public void testPropertyRoundHalfFloorHourOfDay() {
539            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 0);
540            test.hourOfDay().roundHalfFloor();
541            assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
542            
543            test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 1);
544            test.hourOfDay().roundHalfFloor();
545            assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
546            
547            test = new MutableDateTime(2004, 6, 9, 13, 29, 59, 999);
548            test.hourOfDay().roundHalfFloor();
549            assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
550        }
551    
552        public void testPropertyRoundHalfCeilingHourOfDay() {
553            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 0);
554            test.hourOfDay().roundHalfCeiling();
555            assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
556            
557            test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 1);
558            test.hourOfDay().roundHalfCeiling();
559            assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
560            
561            test = new MutableDateTime(2004, 6, 9, 13, 29, 59, 999);
562            test.hourOfDay().roundHalfCeiling();
563            assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
564        }
565    
566        public void testPropertyRoundHalfEvenHourOfDay() {
567            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 0);
568            test.hourOfDay().roundHalfEven();
569            assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
570            
571            test = new MutableDateTime(2004, 6, 9, 14, 30, 0, 0);
572            test.hourOfDay().roundHalfEven();
573            assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
574            
575            test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 1);
576            test.hourOfDay().roundHalfEven();
577            assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
578            
579            test = new MutableDateTime(2004, 6, 9, 13, 29, 59, 999);
580            test.hourOfDay().roundHalfEven();
581            assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
582        }
583    
584        public void testPropertyRemainderHourOfDay() {
585            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 0);
586            assertEquals(30L * DateTimeConstants.MILLIS_PER_MINUTE, test.hourOfDay().remainder());
587        }
588    
589        //-----------------------------------------------------------------------
590        public void testPropertyGetMinuteOfHour() {
591            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
592            assertSame(test.getChronology().minuteOfHour(), test.minuteOfHour().getField());
593            assertEquals("minuteOfHour", test.minuteOfHour().getName());
594            assertEquals("Property[minuteOfHour]", test.minuteOfHour().toString());
595            assertEquals(23, test.minuteOfHour().get());
596            assertEquals("23", test.minuteOfHour().getAsText());
597            assertEquals("23", test.minuteOfHour().getAsText(Locale.FRENCH));
598            assertEquals("23", test.minuteOfHour().getAsShortText());
599            assertEquals("23", test.minuteOfHour().getAsShortText(Locale.FRENCH));
600            assertEquals(test.getChronology().minutes(), test.minuteOfHour().getDurationField());
601            assertEquals(test.getChronology().hours(), test.minuteOfHour().getRangeDurationField());
602            assertEquals(2, test.minuteOfHour().getMaximumTextLength(null));
603            assertEquals(2, test.minuteOfHour().getMaximumShortTextLength(null));
604        }
605    
606        //-----------------------------------------------------------------------
607        public void testPropertyGetMinuteOfDay() {
608            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
609            assertSame(test.getChronology().minuteOfDay(), test.minuteOfDay().getField());
610            assertEquals("minuteOfDay", test.minuteOfDay().getName());
611            assertEquals("Property[minuteOfDay]", test.minuteOfDay().toString());
612            assertEquals(803, test.minuteOfDay().get());
613            assertEquals("803", test.minuteOfDay().getAsText());
614            assertEquals("803", test.minuteOfDay().getAsText(Locale.FRENCH));
615            assertEquals("803", test.minuteOfDay().getAsShortText());
616            assertEquals("803", test.minuteOfDay().getAsShortText(Locale.FRENCH));
617            assertEquals(test.getChronology().minutes(), test.minuteOfDay().getDurationField());
618            assertEquals(test.getChronology().days(), test.minuteOfDay().getRangeDurationField());
619            assertEquals(4, test.minuteOfDay().getMaximumTextLength(null));
620            assertEquals(4, test.minuteOfDay().getMaximumShortTextLength(null));
621        }
622    
623        //-----------------------------------------------------------------------
624        public void testPropertyGetSecondOfMinute() {
625            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
626            assertSame(test.getChronology().secondOfMinute(), test.secondOfMinute().getField());
627            assertEquals("secondOfMinute", test.secondOfMinute().getName());
628            assertEquals("Property[secondOfMinute]", test.secondOfMinute().toString());
629            assertEquals(43, test.secondOfMinute().get());
630            assertEquals("43", test.secondOfMinute().getAsText());
631            assertEquals("43", test.secondOfMinute().getAsText(Locale.FRENCH));
632            assertEquals("43", test.secondOfMinute().getAsShortText());
633            assertEquals("43", test.secondOfMinute().getAsShortText(Locale.FRENCH));
634            assertEquals(test.getChronology().seconds(), test.secondOfMinute().getDurationField());
635            assertEquals(test.getChronology().minutes(), test.secondOfMinute().getRangeDurationField());
636            assertEquals(2, test.secondOfMinute().getMaximumTextLength(null));
637            assertEquals(2, test.secondOfMinute().getMaximumShortTextLength(null));
638        }
639    
640        //-----------------------------------------------------------------------
641        public void testPropertyGetSecondOfDay() {
642            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
643            assertSame(test.getChronology().secondOfDay(), test.secondOfDay().getField());
644            assertEquals("secondOfDay", test.secondOfDay().getName());
645            assertEquals("Property[secondOfDay]", test.secondOfDay().toString());
646            assertEquals(48223, test.secondOfDay().get());
647            assertEquals("48223", test.secondOfDay().getAsText());
648            assertEquals("48223", test.secondOfDay().getAsText(Locale.FRENCH));
649            assertEquals("48223", test.secondOfDay().getAsShortText());
650            assertEquals("48223", test.secondOfDay().getAsShortText(Locale.FRENCH));
651            assertEquals(test.getChronology().seconds(), test.secondOfDay().getDurationField());
652            assertEquals(test.getChronology().days(), test.secondOfDay().getRangeDurationField());
653            assertEquals(5, test.secondOfDay().getMaximumTextLength(null));
654            assertEquals(5, test.secondOfDay().getMaximumShortTextLength(null));
655        }
656    
657        //-----------------------------------------------------------------------
658        public void testPropertyGetMillisOfSecond() {
659            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
660            assertSame(test.getChronology().millisOfSecond(), test.millisOfSecond().getField());
661            assertEquals("millisOfSecond", test.millisOfSecond().getName());
662            assertEquals("Property[millisOfSecond]", test.millisOfSecond().toString());
663            assertEquals(53, test.millisOfSecond().get());
664            assertEquals("53", test.millisOfSecond().getAsText());
665            assertEquals("53", test.millisOfSecond().getAsText(Locale.FRENCH));
666            assertEquals("53", test.millisOfSecond().getAsShortText());
667            assertEquals("53", test.millisOfSecond().getAsShortText(Locale.FRENCH));
668            assertEquals(test.getChronology().millis(), test.millisOfSecond().getDurationField());
669            assertEquals(test.getChronology().seconds(), test.millisOfSecond().getRangeDurationField());
670            assertEquals(3, test.millisOfSecond().getMaximumTextLength(null));
671            assertEquals(3, test.millisOfSecond().getMaximumShortTextLength(null));
672        }
673    
674        //-----------------------------------------------------------------------
675        public void testPropertyGetMillisOfDay() {
676            MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
677            assertSame(test.getChronology().millisOfDay(), test.millisOfDay().getField());
678            assertEquals("millisOfDay", test.millisOfDay().getName());
679            assertEquals("Property[millisOfDay]", test.millisOfDay().toString());
680            assertEquals(48223053, test.millisOfDay().get());
681            assertEquals("48223053", test.millisOfDay().getAsText());
682            assertEquals("48223053", test.millisOfDay().getAsText(Locale.FRENCH));
683            assertEquals("48223053", test.millisOfDay().getAsShortText());
684            assertEquals("48223053", test.millisOfDay().getAsShortText(Locale.FRENCH));
685            assertEquals(test.getChronology().millis(), test.millisOfDay().getDurationField());
686            assertEquals(test.getChronology().days(), test.millisOfDay().getRangeDurationField());
687            assertEquals(8, test.millisOfDay().getMaximumTextLength(null));
688            assertEquals(8, test.millisOfDay().getMaximumShortTextLength(null));
689        }
690    
691        //-----------------------------------------------------------------------
692        public void testPropertyToIntervalYearOfEra() {
693          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
694          Interval testInterval = test.yearOfEra().toInterval();
695          assertEquals(new MutableDateTime(2004, 1, 1, 0, 0, 0, 0), testInterval.getStart());
696          assertEquals(new MutableDateTime(2005, 1, 1, 0, 0, 0, 0), testInterval.getEnd());
697          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
698        }
699    
700        public void testPropertyToIntervalYearOfCentury() {
701          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
702          Interval testInterval = test.yearOfCentury().toInterval();
703          assertEquals(new MutableDateTime(2004, 1, 1, 0, 0, 0, 0), testInterval.getStart());
704          assertEquals(new MutableDateTime(2005, 1, 1, 0, 0, 0, 0), testInterval.getEnd());
705          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
706        }
707    
708        public void testPropertyToIntervalYear() {
709          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
710          Interval testInterval = test.year().toInterval();
711          assertEquals(new MutableDateTime(2004, 1, 1, 0, 0, 0, 0), testInterval.getStart());
712          assertEquals(new MutableDateTime(2005, 1, 1, 0, 0, 0, 0), testInterval.getEnd());
713          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
714        }
715    
716        public void testPropertyToIntervalMonthOfYear() {
717          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
718          Interval testInterval = test.monthOfYear().toInterval();
719          assertEquals(new MutableDateTime(2004, 6, 1, 0, 0, 0, 0), testInterval.getStart());
720          assertEquals(new MutableDateTime(2004, 7, 1, 0, 0, 0, 0), testInterval.getEnd());
721          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
722        }
723    
724        public void testPropertyToIntervalDayOfMonth() {
725          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
726          Interval testInterval = test.dayOfMonth().toInterval();
727          assertEquals(new MutableDateTime(2004, 6, 9, 0, 0, 0, 0), testInterval.getStart());
728          assertEquals(new MutableDateTime(2004, 6, 10, 0, 0, 0, 0), testInterval.getEnd());
729          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
730    
731          MutableDateTime febTest = new MutableDateTime(2004, 2, 29, 13, 23, 43, 53);
732          Interval febTestInterval = febTest.dayOfMonth().toInterval();
733          assertEquals(new MutableDateTime(2004, 2, 29, 0, 0, 0, 0), febTestInterval.getStart());
734          assertEquals(new MutableDateTime(2004, 3, 1, 0, 0, 0, 0), febTestInterval.getEnd());
735          assertEquals(new MutableDateTime(2004, 2, 29, 13, 23, 43, 53), febTest);
736        }
737    
738        public void testPropertyToIntervalHourOfDay() {
739          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
740          Interval testInterval = test.hourOfDay().toInterval();
741          assertEquals(new MutableDateTime(2004, 6, 9, 13, 0, 0, 0), testInterval.getStart());
742          assertEquals(new MutableDateTime(2004, 6, 9, 14, 0, 0, 0), testInterval.getEnd());
743          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
744    
745          MutableDateTime midnightTest = new MutableDateTime(2004, 6, 9, 23, 23, 43, 53);
746          Interval midnightTestInterval = midnightTest.hourOfDay().toInterval();
747          assertEquals(new MutableDateTime(2004, 6, 9, 23, 0, 0, 0), midnightTestInterval.getStart());
748          assertEquals(new MutableDateTime(2004, 6, 10, 0, 0, 0, 0), midnightTestInterval.getEnd());
749          assertEquals(new MutableDateTime(2004, 6, 9, 23, 23, 43, 53), midnightTest);
750        }
751    
752        public void testPropertyToIntervalMinuteOfHour() {
753          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
754          Interval testInterval = test.minuteOfHour().toInterval();
755          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 0, 0), testInterval.getStart());
756          assertEquals(new MutableDateTime(2004, 6, 9, 13, 24, 0, 0), testInterval.getEnd());
757          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
758        }
759    
760        public void testPropertyToIntervalSecondOfMinute() {
761          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
762          Interval testInterval = test.secondOfMinute().toInterval();
763          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 0), testInterval.getStart());
764          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 44, 0), testInterval.getEnd());
765          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
766        }
767    
768        public void testPropertyToIntervalMillisOfSecond() {
769          MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23, 43, 53);
770          Interval testInterval = test.millisOfSecond().toInterval();
771          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), testInterval.getStart());
772          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 54), testInterval.getEnd());
773          assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53), test);
774        }
775    
776    }