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
035: .forID("Europe/London");
036:
037: long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
038: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
039: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
040: + 365 + 365 + 366 + 365;
041: long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
042: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
043: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
044: + 365 + 365 + 366 + 365 + 365;
045:
046: // 2002-06-09
047: private long TEST_TIME_NOW = (y2002days + 31L + 28L + 31L + 30L
048: + 31L + 9L - 1L)
049: * DateTimeConstants.MILLIS_PER_DAY;
050:
051: // 2002-04-05 Fri
052: private long TEST_TIME1 = (y2002days + 31L + 28L + 31L + 5L - 1L)
053: * DateTimeConstants.MILLIS_PER_DAY + 12L
054: * DateTimeConstants.MILLIS_PER_HOUR + 24L
055: * DateTimeConstants.MILLIS_PER_MINUTE;
056:
057: // 2003-05-06 Tue
058: private long TEST_TIME2 = (y2003days + 31L + 28L + 31L + 30L + 6L - 1L)
059: * DateTimeConstants.MILLIS_PER_DAY
060: + 14L
061: * DateTimeConstants.MILLIS_PER_HOUR
062: + 28L
063: * DateTimeConstants.MILLIS_PER_MINUTE;
064:
065: private DateTimeZone zone = null;
066: private Locale locale = null;
067:
068: public static void main(String[] args) {
069: junit.textui.TestRunner.run(suite());
070: }
071:
072: public static TestSuite suite() {
073: return new TestSuite(TestMutableDateTime_Properties.class);
074: }
075:
076: public TestMutableDateTime_Properties(String name) {
077: super (name);
078: }
079:
080: protected void setUp() throws Exception {
081: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
082: zone = DateTimeZone.getDefault();
083: locale = Locale.getDefault();
084: DateTimeZone.setDefault(LONDON);
085: Locale.setDefault(Locale.UK);
086: }
087:
088: protected void tearDown() throws Exception {
089: DateTimeUtils.setCurrentMillisSystem();
090: DateTimeZone.setDefault(zone);
091: Locale.setDefault(locale);
092: zone = null;
093: }
094:
095: //-----------------------------------------------------------------------
096: public void testTest() {
097: assertEquals("2002-06-09T00:00:00.000Z", new Instant(
098: TEST_TIME_NOW).toString());
099: assertEquals("2002-04-05T12:24:00.000Z",
100: new Instant(TEST_TIME1).toString());
101: assertEquals("2003-05-06T14:28:00.000Z",
102: new Instant(TEST_TIME2).toString());
103: }
104:
105: //-----------------------------------------------------------------------
106: public void testPropertyGetEra() {
107: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
108: 0);
109: assertSame(test.getChronology().era(), test.era().getField());
110: assertEquals("era", test.era().getName());
111: assertEquals("Property[era]", test.era().toString());
112: assertSame(test, test.era().getMutableDateTime());
113: assertEquals(1, test.era().get());
114: assertEquals("AD", test.era().getAsText());
115: assertEquals("ap. J.-C.", test.era().getAsText(Locale.FRENCH));
116: assertEquals("AD", test.era().getAsShortText());
117: assertEquals("ap. J.-C.", test.era().getAsShortText(
118: Locale.FRENCH));
119: assertEquals(test.getChronology().eras(), test.era()
120: .getDurationField());
121: assertEquals(null, test.era().getRangeDurationField());
122: assertEquals(2, test.era().getMaximumTextLength(null));
123: assertEquals(9, test.era().getMaximumTextLength(Locale.FRENCH));
124: assertEquals(2, test.era().getMaximumShortTextLength(null));
125: assertEquals(9, test.era().getMaximumShortTextLength(
126: Locale.FRENCH));
127: }
128:
129: //-----------------------------------------------------------------------
130: public void testPropertyGetYearOfEra() {
131: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
132: 0);
133: assertSame(test.getChronology().yearOfEra(), test.yearOfEra()
134: .getField());
135: assertEquals("yearOfEra", test.yearOfEra().getName());
136: assertEquals("Property[yearOfEra]", test.yearOfEra().toString());
137: assertEquals(2004, test.yearOfEra().get());
138: assertEquals("2004", test.yearOfEra().getAsText());
139: assertEquals("2004", test.yearOfEra().getAsText(Locale.FRENCH));
140: assertEquals("2004", test.yearOfEra().getAsShortText());
141: assertEquals("2004", test.yearOfEra().getAsShortText(
142: Locale.FRENCH));
143: assertEquals(test.getChronology().years(), test.yearOfEra()
144: .getDurationField());
145: assertEquals(null, test.yearOfEra().getRangeDurationField());
146: assertEquals(9, test.yearOfEra().getMaximumTextLength(null));
147: assertEquals(9, test.yearOfEra()
148: .getMaximumShortTextLength(null));
149: }
150:
151: //-----------------------------------------------------------------------
152: public void testPropertyGetCenturyOfEra() {
153: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
154: 0);
155: assertSame(test.getChronology().centuryOfEra(), test
156: .centuryOfEra().getField());
157: assertEquals("centuryOfEra", test.centuryOfEra().getName());
158: assertEquals("Property[centuryOfEra]", test.centuryOfEra()
159: .toString());
160: assertEquals(20, test.centuryOfEra().get());
161: assertEquals("20", test.centuryOfEra().getAsText());
162: assertEquals("20", test.centuryOfEra().getAsText(Locale.FRENCH));
163: assertEquals("20", test.centuryOfEra().getAsShortText());
164: assertEquals("20", test.centuryOfEra().getAsShortText(
165: Locale.FRENCH));
166: assertEquals(test.getChronology().centuries(), test
167: .centuryOfEra().getDurationField());
168: assertEquals(null, test.centuryOfEra().getRangeDurationField());
169: assertEquals(7, test.centuryOfEra().getMaximumTextLength(null));
170: assertEquals(7, test.centuryOfEra().getMaximumShortTextLength(
171: null));
172: }
173:
174: //-----------------------------------------------------------------------
175: public void testPropertyGetYearOfCentury() {
176: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
177: 0);
178: assertSame(test.getChronology().yearOfCentury(), test
179: .yearOfCentury().getField());
180: assertEquals("yearOfCentury", test.yearOfCentury().getName());
181: assertEquals("Property[yearOfCentury]", test.yearOfCentury()
182: .toString());
183: assertEquals(4, test.yearOfCentury().get());
184: assertEquals("4", test.yearOfCentury().getAsText());
185: assertEquals("4", test.yearOfCentury().getAsText(Locale.FRENCH));
186: assertEquals("4", test.yearOfCentury().getAsShortText());
187: assertEquals("4", test.yearOfCentury().getAsShortText(
188: Locale.FRENCH));
189: assertEquals(test.getChronology().years(), test.yearOfCentury()
190: .getDurationField());
191: assertEquals(test.getChronology().centuries(), test
192: .yearOfCentury().getRangeDurationField());
193: assertEquals(2, test.yearOfCentury().getMaximumTextLength(null));
194: assertEquals(2, test.yearOfCentury().getMaximumShortTextLength(
195: null));
196: }
197:
198: //-----------------------------------------------------------------------
199: public void testPropertyGetWeekyear() {
200: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
201: 0);
202: assertSame(test.getChronology().weekyear(), test.weekyear()
203: .getField());
204: assertEquals("weekyear", test.weekyear().getName());
205: assertEquals("Property[weekyear]", test.weekyear().toString());
206: assertEquals(2004, test.weekyear().get());
207: assertEquals("2004", test.weekyear().getAsText());
208: assertEquals("2004", test.weekyear().getAsText(Locale.FRENCH));
209: assertEquals("2004", test.weekyear().getAsShortText());
210: assertEquals("2004", test.weekyear().getAsShortText(
211: Locale.FRENCH));
212: assertEquals(test.getChronology().weekyears(), test.weekyear()
213: .getDurationField());
214: assertEquals(null, test.weekyear().getRangeDurationField());
215: assertEquals(9, test.weekyear().getMaximumTextLength(null));
216: assertEquals(9, test.weekyear().getMaximumShortTextLength(null));
217: }
218:
219: //-----------------------------------------------------------------------
220: public void testPropertyGetYear() {
221: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
222: 0);
223: assertSame(test.getChronology().year(), test.year().getField());
224: assertEquals("year", test.year().getName());
225: assertEquals("Property[year]", test.year().toString());
226: assertEquals(2004, test.year().get());
227: assertEquals("2004", test.year().getAsText());
228: assertEquals("2004", test.year().getAsText(Locale.FRENCH));
229: assertEquals("2004", test.year().getAsShortText());
230: assertEquals("2004", test.year().getAsShortText(Locale.FRENCH));
231: assertEquals(test.getChronology().years(), test.year()
232: .getDurationField());
233: assertEquals(null, test.year().getRangeDurationField());
234: assertEquals(9, test.year().getMaximumTextLength(null));
235: assertEquals(9, test.year().getMaximumShortTextLength(null));
236: assertEquals(-292275054, test.year().getMinimumValue());
237: assertEquals(-292275054, test.year().getMinimumValueOverall());
238: assertEquals(292278993, test.year().getMaximumValue());
239: assertEquals(292278993, test.year().getMaximumValueOverall());
240: }
241:
242: public void testPropertyAddYear() {
243: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
244: 0);
245: test.year().add(9);
246: assertEquals("2013-06-09T00:00:00.000+01:00", test.toString());
247: }
248:
249: public void testPropertyAddWrapFieldYear() {
250: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
251: 0);
252: test.year().addWrapField(9);
253: assertEquals("2013-06-09T00:00:00.000+01:00", test.toString());
254: }
255:
256: public void testPropertySetYear() {
257: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
258: 0);
259: test.year().set(1960);
260: assertEquals("1960-06-09T00:00:00.000+01:00", test.toString());
261: }
262:
263: public void testPropertySetTextYear() {
264: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
265: 0);
266: test.year().set("1960");
267: assertEquals("1960-06-09T00:00:00.000+01:00", test.toString());
268: }
269:
270: //-----------------------------------------------------------------------
271: public void testPropertyGetMonthOfYear() {
272: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
273: 0);
274: assertSame(test.getChronology().monthOfYear(), test
275: .monthOfYear().getField());
276: assertEquals("monthOfYear", test.monthOfYear().getName());
277: assertEquals("Property[monthOfYear]", test.monthOfYear()
278: .toString());
279: assertEquals(6, test.monthOfYear().get());
280: assertEquals("June", test.monthOfYear().getAsText());
281: assertEquals("juin", test.monthOfYear()
282: .getAsText(Locale.FRENCH));
283: assertEquals("Jun", test.monthOfYear().getAsShortText());
284: assertEquals("juin", test.monthOfYear().getAsShortText(
285: Locale.FRENCH));
286: assertEquals(test.getChronology().months(), test.monthOfYear()
287: .getDurationField());
288: assertEquals(test.getChronology().years(), test.monthOfYear()
289: .getRangeDurationField());
290: assertEquals(9, test.monthOfYear().getMaximumTextLength(null));
291: assertEquals(3, test.monthOfYear().getMaximumShortTextLength(
292: null));
293: test = new MutableDateTime(2004, 7, 9, 0, 0, 0, 0);
294: assertEquals("juillet", test.monthOfYear().getAsText(
295: Locale.FRENCH));
296: assertEquals("juil.", test.monthOfYear().getAsShortText(
297: Locale.FRENCH));
298: assertEquals(1, test.monthOfYear().getMinimumValue());
299: assertEquals(1, test.monthOfYear().getMinimumValueOverall());
300: assertEquals(12, test.monthOfYear().getMaximumValue());
301: assertEquals(12, test.monthOfYear().getMaximumValueOverall());
302: assertEquals(1, test.monthOfYear().getMinimumValue());
303: assertEquals(1, test.monthOfYear().getMinimumValueOverall());
304: assertEquals(12, test.monthOfYear().getMaximumValue());
305: assertEquals(12, test.monthOfYear().getMaximumValueOverall());
306: }
307:
308: public void testPropertyAddMonthOfYear() {
309: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
310: 0);
311: test.monthOfYear().add(6);
312: assertEquals("2004-12-09T00:00:00.000Z", test.toString());
313: }
314:
315: public void testPropertyAddWrapFieldMonthOfYear() {
316: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
317: 0);
318: test.monthOfYear().addWrapField(8);
319: assertEquals("2004-02-09T00:00:00.000Z", test.toString());
320: }
321:
322: public void testPropertySetMonthOfYear() {
323: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
324: 0);
325: test.monthOfYear().set(12);
326: assertEquals("2004-12-09T00:00:00.000Z", test.toString());
327: }
328:
329: public void testPropertySetTextMonthOfYear() {
330: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
331: 0);
332: test.monthOfYear().set("12");
333: assertEquals("2004-12-09T00:00:00.000Z", test.toString());
334:
335: test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
336: test.monthOfYear().set("December");
337: assertEquals("2004-12-09T00:00:00.000Z", test.toString());
338:
339: test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
340: test.monthOfYear().set("Dec");
341: assertEquals("2004-12-09T00:00:00.000Z", test.toString());
342: }
343:
344: //-----------------------------------------------------------------------
345: public void testPropertyGetDayOfMonth() {
346: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
347: 0);
348: assertSame(test.getChronology().dayOfMonth(), test.dayOfMonth()
349: .getField());
350: assertEquals("dayOfMonth", test.dayOfMonth().getName());
351: assertEquals("Property[dayOfMonth]", test.dayOfMonth()
352: .toString());
353: assertEquals(9, test.dayOfMonth().get());
354: assertEquals("9", test.dayOfMonth().getAsText());
355: assertEquals("9", test.dayOfMonth().getAsText(Locale.FRENCH));
356: assertEquals("9", test.dayOfMonth().getAsShortText());
357: assertEquals("9", test.dayOfMonth().getAsShortText(
358: Locale.FRENCH));
359: assertEquals(test.getChronology().days(), test.dayOfMonth()
360: .getDurationField());
361: assertEquals(test.getChronology().months(), test.dayOfMonth()
362: .getRangeDurationField());
363: assertEquals(2, test.dayOfMonth().getMaximumTextLength(null));
364: assertEquals(2, test.dayOfMonth().getMaximumShortTextLength(
365: null));
366: assertEquals(1, test.dayOfMonth().getMinimumValue());
367: assertEquals(1, test.dayOfMonth().getMinimumValueOverall());
368: assertEquals(30, test.dayOfMonth().getMaximumValue());
369: assertEquals(31, test.dayOfMonth().getMaximumValueOverall());
370: assertEquals(false, test.dayOfMonth().isLeap());
371: assertEquals(0, test.dayOfMonth().getLeapAmount());
372: assertEquals(null, test.dayOfMonth().getLeapDurationField());
373: }
374:
375: public void testPropertyAddDayOfMonth() {
376: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
377: 0);
378: test.dayOfMonth().add(9);
379: assertEquals("2004-06-18T00:00:00.000+01:00", test.toString());
380: }
381:
382: public void testPropertyAddWrapFieldDayOfMonth() {
383: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
384: 0);
385: test.dayOfMonth().addWrapField(22);
386: assertEquals("2004-06-01T00:00:00.000+01:00", test.toString());
387: }
388:
389: public void testPropertySetDayOfMonth() {
390: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
391: 0);
392: test.dayOfMonth().set(12);
393: assertEquals("2004-06-12T00:00:00.000+01:00", test.toString());
394: }
395:
396: public void testPropertySetTextDayOfMonth() {
397: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
398: 0);
399: test.dayOfMonth().set("12");
400: assertEquals("2004-06-12T00:00:00.000+01:00", test.toString());
401: }
402:
403: //-----------------------------------------------------------------------
404: public void testPropertyGetDayOfYear() {
405: // 31+29+31+30+31+9 = 161
406: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
407: 0);
408: assertSame(test.getChronology().dayOfYear(), test.dayOfYear()
409: .getField());
410: assertEquals("dayOfYear", test.dayOfYear().getName());
411: assertEquals("Property[dayOfYear]", test.dayOfYear().toString());
412: assertEquals(161, test.dayOfYear().get());
413: assertEquals("161", test.dayOfYear().getAsText());
414: assertEquals("161", test.dayOfYear().getAsText(Locale.FRENCH));
415: assertEquals("161", test.dayOfYear().getAsShortText());
416: assertEquals("161", test.dayOfYear().getAsShortText(
417: Locale.FRENCH));
418: assertEquals(test.getChronology().days(), test.dayOfYear()
419: .getDurationField());
420: assertEquals(test.getChronology().years(), test.dayOfYear()
421: .getRangeDurationField());
422: assertEquals(3, test.dayOfYear().getMaximumTextLength(null));
423: assertEquals(3, test.dayOfYear()
424: .getMaximumShortTextLength(null));
425: assertEquals(false, test.dayOfYear().isLeap());
426: assertEquals(0, test.dayOfYear().getLeapAmount());
427: assertEquals(null, test.dayOfYear().getLeapDurationField());
428: }
429:
430: public void testPropertyAddDayOfYear() {
431: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
432: 0);
433: test.dayOfYear().add(9);
434: assertEquals("2004-06-18T00:00:00.000+01:00", test.toString());
435: }
436:
437: public void testPropertyAddWrapFieldDayOfYear() {
438: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
439: 0);
440: test.dayOfYear().addWrapField(206);
441: assertEquals("2004-01-01T00:00:00.000Z", test.toString());
442: }
443:
444: public void testPropertySetDayOfYear() {
445: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
446: 0);
447: test.dayOfYear().set(12);
448: assertEquals("2004-01-12T00:00:00.000Z", test.toString());
449: }
450:
451: public void testPropertySetTextDayOfYear() {
452: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
453: 0);
454: test.dayOfYear().set("12");
455: assertEquals("2004-01-12T00:00:00.000Z", test.toString());
456: }
457:
458: //-----------------------------------------------------------------------
459: public void testPropertyGetWeekOfWeekyear() {
460: // 2002-01-01 = Thu
461: // 2002-12-31 = Thu (+364 days)
462: // 2003-12-30 = Thu (+364 days)
463: // 2004-01-03 = Mon W1
464: // 2004-01-31 = Mon (+28 days) W5
465: // 2004-02-28 = Mon (+28 days) W9
466: // 2004-03-27 = Mon (+28 days) W13
467: // 2004-04-24 = Mon (+28 days) W17
468: // 2004-05-23 = Mon (+28 days) W21
469: // 2004-06-05 = Mon (+14 days) W23
470: // 2004-06-09 = Fri
471: // 2004-12-25 = Mon W52
472: // 2005-01-01 = Mon W1
473: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
474: 0);
475: assertSame(test.getChronology().weekOfWeekyear(), test
476: .weekOfWeekyear().getField());
477: assertEquals("weekOfWeekyear", test.weekOfWeekyear().getName());
478: assertEquals("Property[weekOfWeekyear]", test.weekOfWeekyear()
479: .toString());
480: assertEquals(24, test.weekOfWeekyear().get());
481: assertEquals("24", test.weekOfWeekyear().getAsText());
482: assertEquals("24", test.weekOfWeekyear().getAsText(
483: Locale.FRENCH));
484: assertEquals("24", test.weekOfWeekyear().getAsShortText());
485: assertEquals("24", test.weekOfWeekyear().getAsShortText(
486: Locale.FRENCH));
487: assertEquals(test.getChronology().weeks(), test
488: .weekOfWeekyear().getDurationField());
489: assertEquals(test.getChronology().weekyears(), test
490: .weekOfWeekyear().getRangeDurationField());
491: assertEquals(2, test.weekOfWeekyear()
492: .getMaximumTextLength(null));
493: assertEquals(2, test.weekOfWeekyear()
494: .getMaximumShortTextLength(null));
495: assertEquals(false, test.weekOfWeekyear().isLeap());
496: assertEquals(0, test.weekOfWeekyear().getLeapAmount());
497: assertEquals(null, test.weekOfWeekyear().getLeapDurationField());
498: }
499:
500: public void testPropertyAddWeekOfWeekyear() {
501: MutableDateTime test = new MutableDateTime(2004, 6, 7, 0, 0, 0,
502: 0);
503: test.weekOfWeekyear().add(1);
504: assertEquals("2004-06-14T00:00:00.000+01:00", test.toString());
505: }
506:
507: public void testPropertyAddWrapFieldWeekOfWeekyear() {
508: MutableDateTime test = new MutableDateTime(2004, 6, 7, 0, 0, 0,
509: 0);
510: test.weekOfWeekyear().addWrapField(30);
511: assertEquals("2003-12-29T00:00:00.000Z", test.toString());
512: }
513:
514: public void testPropertySetWeekOfWeekyear() {
515: MutableDateTime test = new MutableDateTime(2004, 6, 7, 0, 0, 0,
516: 0);
517: test.weekOfWeekyear().set(4);
518: assertEquals("2004-01-19T00:00:00.000Z", test.toString());
519: }
520:
521: public void testPropertySetTextWeekOfWeekyear() {
522: MutableDateTime test = new MutableDateTime(2004, 6, 7, 0, 0, 0,
523: 0);
524: test.weekOfWeekyear().set("4");
525: assertEquals("2004-01-19T00:00:00.000Z", test.toString());
526: }
527:
528: //-----------------------------------------------------------------------
529: public void testPropertyGetDayOfWeek() {
530: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
531: 0);
532: assertSame(test.getChronology().dayOfWeek(), test.dayOfWeek()
533: .getField());
534: assertEquals("dayOfWeek", test.dayOfWeek().getName());
535: assertEquals("Property[dayOfWeek]", test.dayOfWeek().toString());
536: assertEquals(3, test.dayOfWeek().get());
537: assertEquals("Wednesday", test.dayOfWeek().getAsText());
538: assertEquals("mercredi", test.dayOfWeek().getAsText(
539: Locale.FRENCH));
540: assertEquals("Wed", test.dayOfWeek().getAsShortText());
541: assertEquals("mer.", test.dayOfWeek().getAsShortText(
542: Locale.FRENCH));
543: assertEquals(test.getChronology().days(), test.dayOfWeek()
544: .getDurationField());
545: assertEquals(test.getChronology().weeks(), test.dayOfWeek()
546: .getRangeDurationField());
547: assertEquals(9, test.dayOfWeek().getMaximumTextLength(null));
548: assertEquals(8, test.dayOfWeek().getMaximumTextLength(
549: Locale.FRENCH));
550: assertEquals(3, test.dayOfWeek()
551: .getMaximumShortTextLength(null));
552: assertEquals(4, test.dayOfWeek().getMaximumShortTextLength(
553: Locale.FRENCH));
554: assertEquals(1, test.dayOfWeek().getMinimumValue());
555: assertEquals(1, test.dayOfWeek().getMinimumValueOverall());
556: assertEquals(7, test.dayOfWeek().getMaximumValue());
557: assertEquals(7, test.dayOfWeek().getMaximumValueOverall());
558: assertEquals(false, test.dayOfWeek().isLeap());
559: assertEquals(0, test.dayOfWeek().getLeapAmount());
560: assertEquals(null, test.dayOfWeek().getLeapDurationField());
561: }
562:
563: public void testPropertyAddDayOfWeek() {
564: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
565: 0);
566: test.dayOfWeek().add(1);
567: assertEquals("2004-06-10T00:00:00.000+01:00", test.toString());
568: }
569:
570: public void testPropertyAddLongDayOfWeek() {
571: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
572: 0);
573: test.dayOfWeek().add(1L);
574: assertEquals("2004-06-10T00:00:00.000+01:00", test.toString());
575: }
576:
577: public void testPropertyAddWrapFieldDayOfWeek() {
578: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
579: 0); // Wed
580: test.dayOfWeek().addWrapField(5);
581: assertEquals("2004-06-07T00:00:00.000+01:00", test.toString());
582: }
583:
584: public void testPropertySetDayOfWeek() {
585: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
586: 0);
587: test.dayOfWeek().set(4);
588: assertEquals("2004-06-10T00:00:00.000+01:00", test.toString());
589: }
590:
591: public void testPropertySetTextDayOfWeek() {
592: MutableDateTime test = new MutableDateTime(2004, 6, 9, 0, 0, 0,
593: 0);
594: test.dayOfWeek().set("4");
595: assertEquals("2004-06-10T00:00:00.000+01:00", test.toString());
596:
597: test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
598: test.dayOfWeek().set("Mon");
599: assertEquals("2004-06-07T00:00:00.000+01:00", test.toString());
600:
601: test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
602: test.dayOfWeek().set("Tuesday");
603: assertEquals("2004-06-08T00:00:00.000+01:00", test.toString());
604:
605: test = new MutableDateTime(2004, 6, 9, 0, 0, 0, 0);
606: test.dayOfWeek().set("lundi", Locale.FRENCH);
607: assertEquals("2004-06-07T00:00:00.000+01:00", test.toString());
608: }
609:
610: //-----------------------------------------------------------------------
611: public void testPropertyGetHourOfDay() {
612: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
613: 43, 53);
614: assertSame(test.getChronology().hourOfDay(), test.hourOfDay()
615: .getField());
616: assertEquals("hourOfDay", test.hourOfDay().getName());
617: assertEquals("Property[hourOfDay]", test.hourOfDay().toString());
618: assertEquals(13, test.hourOfDay().get());
619: assertEquals("13", test.hourOfDay().getAsText());
620: assertEquals("13", test.hourOfDay().getAsText(Locale.FRENCH));
621: assertEquals("13", test.hourOfDay().getAsShortText());
622: assertEquals("13", test.hourOfDay().getAsShortText(
623: Locale.FRENCH));
624: assertEquals(test.getChronology().hours(), test.hourOfDay()
625: .getDurationField());
626: assertEquals(test.getChronology().days(), test.hourOfDay()
627: .getRangeDurationField());
628: assertEquals(2, test.hourOfDay().getMaximumTextLength(null));
629: assertEquals(2, test.hourOfDay()
630: .getMaximumShortTextLength(null));
631: }
632:
633: public void testPropertyRoundFloorHourOfDay() {
634: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30,
635: 0, 0);
636: test.hourOfDay().roundFloor();
637: assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
638: }
639:
640: public void testPropertyRoundCeilingHourOfDay() {
641: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30,
642: 0, 0);
643: test.hourOfDay().roundCeiling();
644: assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
645: }
646:
647: public void testPropertyRoundHalfFloorHourOfDay() {
648: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30,
649: 0, 0);
650: test.hourOfDay().roundHalfFloor();
651: assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
652:
653: test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 1);
654: test.hourOfDay().roundHalfFloor();
655: assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
656:
657: test = new MutableDateTime(2004, 6, 9, 13, 29, 59, 999);
658: test.hourOfDay().roundHalfFloor();
659: assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
660: }
661:
662: public void testPropertyRoundHalfCeilingHourOfDay() {
663: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30,
664: 0, 0);
665: test.hourOfDay().roundHalfCeiling();
666: assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
667:
668: test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 1);
669: test.hourOfDay().roundHalfCeiling();
670: assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
671:
672: test = new MutableDateTime(2004, 6, 9, 13, 29, 59, 999);
673: test.hourOfDay().roundHalfCeiling();
674: assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
675: }
676:
677: public void testPropertyRoundHalfEvenHourOfDay() {
678: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30,
679: 0, 0);
680: test.hourOfDay().roundHalfEven();
681: assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
682:
683: test = new MutableDateTime(2004, 6, 9, 14, 30, 0, 0);
684: test.hourOfDay().roundHalfEven();
685: assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
686:
687: test = new MutableDateTime(2004, 6, 9, 13, 30, 0, 1);
688: test.hourOfDay().roundHalfEven();
689: assertEquals("2004-06-09T14:00:00.000+01:00", test.toString());
690:
691: test = new MutableDateTime(2004, 6, 9, 13, 29, 59, 999);
692: test.hourOfDay().roundHalfEven();
693: assertEquals("2004-06-09T13:00:00.000+01:00", test.toString());
694: }
695:
696: public void testPropertyRemainderHourOfDay() {
697: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 30,
698: 0, 0);
699: assertEquals(30L * DateTimeConstants.MILLIS_PER_MINUTE, test
700: .hourOfDay().remainder());
701: }
702:
703: //-----------------------------------------------------------------------
704: public void testPropertyGetMinuteOfHour() {
705: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
706: 43, 53);
707: assertSame(test.getChronology().minuteOfHour(), test
708: .minuteOfHour().getField());
709: assertEquals("minuteOfHour", test.minuteOfHour().getName());
710: assertEquals("Property[minuteOfHour]", test.minuteOfHour()
711: .toString());
712: assertEquals(23, test.minuteOfHour().get());
713: assertEquals("23", test.minuteOfHour().getAsText());
714: assertEquals("23", test.minuteOfHour().getAsText(Locale.FRENCH));
715: assertEquals("23", test.minuteOfHour().getAsShortText());
716: assertEquals("23", test.minuteOfHour().getAsShortText(
717: Locale.FRENCH));
718: assertEquals(test.getChronology().minutes(), test
719: .minuteOfHour().getDurationField());
720: assertEquals(test.getChronology().hours(), test.minuteOfHour()
721: .getRangeDurationField());
722: assertEquals(2, test.minuteOfHour().getMaximumTextLength(null));
723: assertEquals(2, test.minuteOfHour().getMaximumShortTextLength(
724: null));
725: }
726:
727: //-----------------------------------------------------------------------
728: public void testPropertyGetMinuteOfDay() {
729: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
730: 43, 53);
731: assertSame(test.getChronology().minuteOfDay(), test
732: .minuteOfDay().getField());
733: assertEquals("minuteOfDay", test.minuteOfDay().getName());
734: assertEquals("Property[minuteOfDay]", test.minuteOfDay()
735: .toString());
736: assertEquals(803, test.minuteOfDay().get());
737: assertEquals("803", test.minuteOfDay().getAsText());
738: assertEquals("803", test.minuteOfDay().getAsText(Locale.FRENCH));
739: assertEquals("803", test.minuteOfDay().getAsShortText());
740: assertEquals("803", test.minuteOfDay().getAsShortText(
741: Locale.FRENCH));
742: assertEquals(test.getChronology().minutes(), test.minuteOfDay()
743: .getDurationField());
744: assertEquals(test.getChronology().days(), test.minuteOfDay()
745: .getRangeDurationField());
746: assertEquals(4, test.minuteOfDay().getMaximumTextLength(null));
747: assertEquals(4, test.minuteOfDay().getMaximumShortTextLength(
748: null));
749: }
750:
751: //-----------------------------------------------------------------------
752: public void testPropertyGetSecondOfMinute() {
753: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
754: 43, 53);
755: assertSame(test.getChronology().secondOfMinute(), test
756: .secondOfMinute().getField());
757: assertEquals("secondOfMinute", test.secondOfMinute().getName());
758: assertEquals("Property[secondOfMinute]", test.secondOfMinute()
759: .toString());
760: assertEquals(43, test.secondOfMinute().get());
761: assertEquals("43", test.secondOfMinute().getAsText());
762: assertEquals("43", test.secondOfMinute().getAsText(
763: Locale.FRENCH));
764: assertEquals("43", test.secondOfMinute().getAsShortText());
765: assertEquals("43", test.secondOfMinute().getAsShortText(
766: Locale.FRENCH));
767: assertEquals(test.getChronology().seconds(), test
768: .secondOfMinute().getDurationField());
769: assertEquals(test.getChronology().minutes(), test
770: .secondOfMinute().getRangeDurationField());
771: assertEquals(2, test.secondOfMinute()
772: .getMaximumTextLength(null));
773: assertEquals(2, test.secondOfMinute()
774: .getMaximumShortTextLength(null));
775: }
776:
777: //-----------------------------------------------------------------------
778: public void testPropertyGetSecondOfDay() {
779: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
780: 43, 53);
781: assertSame(test.getChronology().secondOfDay(), test
782: .secondOfDay().getField());
783: assertEquals("secondOfDay", test.secondOfDay().getName());
784: assertEquals("Property[secondOfDay]", test.secondOfDay()
785: .toString());
786: assertEquals(48223, test.secondOfDay().get());
787: assertEquals("48223", test.secondOfDay().getAsText());
788: assertEquals("48223", test.secondOfDay().getAsText(
789: Locale.FRENCH));
790: assertEquals("48223", test.secondOfDay().getAsShortText());
791: assertEquals("48223", test.secondOfDay().getAsShortText(
792: Locale.FRENCH));
793: assertEquals(test.getChronology().seconds(), test.secondOfDay()
794: .getDurationField());
795: assertEquals(test.getChronology().days(), test.secondOfDay()
796: .getRangeDurationField());
797: assertEquals(5, test.secondOfDay().getMaximumTextLength(null));
798: assertEquals(5, test.secondOfDay().getMaximumShortTextLength(
799: null));
800: }
801:
802: //-----------------------------------------------------------------------
803: public void testPropertyGetMillisOfSecond() {
804: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
805: 43, 53);
806: assertSame(test.getChronology().millisOfSecond(), test
807: .millisOfSecond().getField());
808: assertEquals("millisOfSecond", test.millisOfSecond().getName());
809: assertEquals("Property[millisOfSecond]", test.millisOfSecond()
810: .toString());
811: assertEquals(53, test.millisOfSecond().get());
812: assertEquals("53", test.millisOfSecond().getAsText());
813: assertEquals("53", test.millisOfSecond().getAsText(
814: Locale.FRENCH));
815: assertEquals("53", test.millisOfSecond().getAsShortText());
816: assertEquals("53", test.millisOfSecond().getAsShortText(
817: Locale.FRENCH));
818: assertEquals(test.getChronology().millis(), test
819: .millisOfSecond().getDurationField());
820: assertEquals(test.getChronology().seconds(), test
821: .millisOfSecond().getRangeDurationField());
822: assertEquals(3, test.millisOfSecond()
823: .getMaximumTextLength(null));
824: assertEquals(3, test.millisOfSecond()
825: .getMaximumShortTextLength(null));
826: }
827:
828: //-----------------------------------------------------------------------
829: public void testPropertyGetMillisOfDay() {
830: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
831: 43, 53);
832: assertSame(test.getChronology().millisOfDay(), test
833: .millisOfDay().getField());
834: assertEquals("millisOfDay", test.millisOfDay().getName());
835: assertEquals("Property[millisOfDay]", test.millisOfDay()
836: .toString());
837: assertEquals(48223053, test.millisOfDay().get());
838: assertEquals("48223053", test.millisOfDay().getAsText());
839: assertEquals("48223053", test.millisOfDay().getAsText(
840: Locale.FRENCH));
841: assertEquals("48223053", test.millisOfDay().getAsShortText());
842: assertEquals("48223053", test.millisOfDay().getAsShortText(
843: Locale.FRENCH));
844: assertEquals(test.getChronology().millis(), test.millisOfDay()
845: .getDurationField());
846: assertEquals(test.getChronology().days(), test.millisOfDay()
847: .getRangeDurationField());
848: assertEquals(8, test.millisOfDay().getMaximumTextLength(null));
849: assertEquals(8, test.millisOfDay().getMaximumShortTextLength(
850: null));
851: }
852:
853: //-----------------------------------------------------------------------
854: public void testPropertyToIntervalYearOfEra() {
855: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
856: 43, 53);
857: Interval testInterval = test.yearOfEra().toInterval();
858: assertEquals(new MutableDateTime(2004, 1, 1, 0, 0, 0, 0),
859: testInterval.getStart());
860: assertEquals(new MutableDateTime(2005, 1, 1, 0, 0, 0, 0),
861: testInterval.getEnd());
862: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
863: test);
864: }
865:
866: public void testPropertyToIntervalYearOfCentury() {
867: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
868: 43, 53);
869: Interval testInterval = test.yearOfCentury().toInterval();
870: assertEquals(new MutableDateTime(2004, 1, 1, 0, 0, 0, 0),
871: testInterval.getStart());
872: assertEquals(new MutableDateTime(2005, 1, 1, 0, 0, 0, 0),
873: testInterval.getEnd());
874: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
875: test);
876: }
877:
878: public void testPropertyToIntervalYear() {
879: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
880: 43, 53);
881: Interval testInterval = test.year().toInterval();
882: assertEquals(new MutableDateTime(2004, 1, 1, 0, 0, 0, 0),
883: testInterval.getStart());
884: assertEquals(new MutableDateTime(2005, 1, 1, 0, 0, 0, 0),
885: testInterval.getEnd());
886: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
887: test);
888: }
889:
890: public void testPropertyToIntervalMonthOfYear() {
891: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
892: 43, 53);
893: Interval testInterval = test.monthOfYear().toInterval();
894: assertEquals(new MutableDateTime(2004, 6, 1, 0, 0, 0, 0),
895: testInterval.getStart());
896: assertEquals(new MutableDateTime(2004, 7, 1, 0, 0, 0, 0),
897: testInterval.getEnd());
898: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
899: test);
900: }
901:
902: public void testPropertyToIntervalDayOfMonth() {
903: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
904: 43, 53);
905: Interval testInterval = test.dayOfMonth().toInterval();
906: assertEquals(new MutableDateTime(2004, 6, 9, 0, 0, 0, 0),
907: testInterval.getStart());
908: assertEquals(new MutableDateTime(2004, 6, 10, 0, 0, 0, 0),
909: testInterval.getEnd());
910: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
911: test);
912:
913: MutableDateTime febTest = new MutableDateTime(2004, 2, 29, 13,
914: 23, 43, 53);
915: Interval febTestInterval = febTest.dayOfMonth().toInterval();
916: assertEquals(new MutableDateTime(2004, 2, 29, 0, 0, 0, 0),
917: febTestInterval.getStart());
918: assertEquals(new MutableDateTime(2004, 3, 1, 0, 0, 0, 0),
919: febTestInterval.getEnd());
920: assertEquals(new MutableDateTime(2004, 2, 29, 13, 23, 43, 53),
921: febTest);
922: }
923:
924: public void testPropertyToIntervalHourOfDay() {
925: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
926: 43, 53);
927: Interval testInterval = test.hourOfDay().toInterval();
928: assertEquals(new MutableDateTime(2004, 6, 9, 13, 0, 0, 0),
929: testInterval.getStart());
930: assertEquals(new MutableDateTime(2004, 6, 9, 14, 0, 0, 0),
931: testInterval.getEnd());
932: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
933: test);
934:
935: MutableDateTime midnightTest = new MutableDateTime(2004, 6, 9,
936: 23, 23, 43, 53);
937: Interval midnightTestInterval = midnightTest.hourOfDay()
938: .toInterval();
939: assertEquals(new MutableDateTime(2004, 6, 9, 23, 0, 0, 0),
940: midnightTestInterval.getStart());
941: assertEquals(new MutableDateTime(2004, 6, 10, 0, 0, 0, 0),
942: midnightTestInterval.getEnd());
943: assertEquals(new MutableDateTime(2004, 6, 9, 23, 23, 43, 53),
944: midnightTest);
945: }
946:
947: public void testPropertyToIntervalMinuteOfHour() {
948: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
949: 43, 53);
950: Interval testInterval = test.minuteOfHour().toInterval();
951: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 0, 0),
952: testInterval.getStart());
953: assertEquals(new MutableDateTime(2004, 6, 9, 13, 24, 0, 0),
954: testInterval.getEnd());
955: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
956: test);
957: }
958:
959: public void testPropertyToIntervalSecondOfMinute() {
960: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
961: 43, 53);
962: Interval testInterval = test.secondOfMinute().toInterval();
963: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 0),
964: testInterval.getStart());
965: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 44, 0),
966: testInterval.getEnd());
967: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
968: test);
969: }
970:
971: public void testPropertyToIntervalMillisOfSecond() {
972: MutableDateTime test = new MutableDateTime(2004, 6, 9, 13, 23,
973: 43, 53);
974: Interval testInterval = test.millisOfSecond().toInterval();
975: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
976: testInterval.getStart());
977: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 54),
978: testInterval.getEnd());
979: assertEquals(new MutableDateTime(2004, 6, 9, 13, 23, 43, 53),
980: test);
981: }
982:
983: }
|