// ----------------------------------------------------------------------- public void testProperty() { DateTime test = new DateTime(); assertEquals(test.year(), test.property(DateTimeFieldType.year())); assertEquals(test.dayOfWeek(), test.property(DateTimeFieldType.dayOfWeek())); assertEquals(test.secondOfMinute(), test.property(DateTimeFieldType.secondOfMinute())); assertEquals(test.millisOfSecond(), test.property(DateTimeFieldType.millisOfSecond())); DateTimeFieldType bad = new DateTimeFieldType("bad") { /** */ private static final long serialVersionUID = -7639693014651231134L; public DurationFieldType getDurationType() { return DurationFieldType.weeks(); } public DurationFieldType getRangeDurationType() { return null; } public DateTimeField getField(Chronology chronology) { return UnsupportedDateTimeField.getInstance( this, UnsupportedDurationField.getInstance(getDurationType())); } }; try { test.property(bad); fail(); } catch (IllegalArgumentException ex) { } try { test.property(null); fail(); } catch (IllegalArgumentException ex) { } }
// ----------------------------------------------------------------------- public void testToString() { DateTime test = new DateTime(TEST_TIME_NOW); assertEquals("2002-06-09T01:00:00.000+01:00", test.toString()); test = new DateTime(TEST_TIME_NOW, PARIS); assertEquals("2002-06-09T02:00:00.000+02:00", test.toString()); }
// ----------------------------------------------------------------------- public void testWithFieldAdded1() { DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime result = test.withFieldAdded(DurationFieldType.years(), 6); assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), test); assertEquals(new DateTime(2010, 6, 9, 0, 0, 0, 0), result); }
// ----------------------------------------------------------------------- public void testWithField1() { DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime result = test.withField(DateTimeFieldType.year(), 2006); assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), test); assertEquals(new DateTime(2006, 6, 9, 0, 0, 0, 0), result); }
public void testToMutableDateTimeISO() { DateTime test = new DateTime(TEST_TIME1, PARIS); MutableDateTime result = test.toMutableDateTimeISO(); assertSame(MutableDateTime.class, result.getClass()); assertSame(ISOChronology.class, result.getChronology().getClass()); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_PARIS, result.getChronology()); }
// GWT result depends on java.util.Locale / java.util.TimeZone public void testToString_String_Locale() { DateTime test = new DateTime(TEST_TIME_NOW); // assertEquals("Sun 9/6", test.toString("EEE d/M", Locale.ENGLISH)); // assertEquals("dim. 9/6", test.toString("EEE d/M", Locale.FRENCH)); // assertEquals("2002-06-09T01:00:00.000+01:00", test.toString(null, Locale.ENGLISH)); assertEquals("Sun 9/6", test.toString("EEE d/M", null)); assertEquals("2002-06-09T01:00:00.000+01:00", test.toString(null, null)); }
public void testWithFieldAdded3() { DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); try { test.withFieldAdded(null, 6); fail(); } catch (IllegalArgumentException ex) { } }
public void testPlusYears_int() { DateTime test = new DateTime(2002, 5, 3, 1, 2, 3, 4, BUDDHIST_DEFAULT); DateTime result = test.plusYears(1); DateTime expected = new DateTime(2003, 5, 3, 1, 2, 3, 4, BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.plusYears(0); assertSame(test, result); }
public void testMinus_RP() { DateTime test = new DateTime(2002, 5, 3, 1, 2, 3, 4, BUDDHIST_DEFAULT); DateTime result = test.minus(new Period(1, 1, 1, 1, 1, 1, 1, 1)); DateTime expected = new DateTime(2001, 3, 26, 0, 1, 2, 3, BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.minus((ReadablePeriod) null); assertSame(test, result); }
public void testMinusMillis_int() { DateTime test = new DateTime(2002, 5, 3, 1, 2, 3, 4, BUDDHIST_DEFAULT); DateTime result = test.minusMillis(1); DateTime expected = new DateTime(2002, 5, 3, 1, 2, 3, 3, BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.minusMillis(0); assertSame(test, result); }
public void testPlus_RD() { DateTime test = new DateTime(TEST_TIME1, BUDDHIST_DEFAULT); DateTime result = test.plus(new Duration(123456789L)); DateTime expected = new DateTime(TEST_TIME1 + 123456789L, BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.plus((ReadableDuration) null); assertSame(test, result); }
public void testPlus_RP() { DateTime test = new DateTime(2002, 5, 3, 1, 2, 3, 4, BUDDHIST_DEFAULT); DateTime result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8)); DateTime expected = new DateTime(2003, 7, 28, 6, 8, 10, 12, BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.plus((ReadablePeriod) null); assertSame(test, result); }
public void testWithFields_RPartial() { DateTime test = new DateTime(2004, 5, 6, 7, 8, 9, 0); DateTime result = test.withFields(new LocalDate(2003, 4, 5)); DateTime expected = new DateTime(2003, 4, 5, 7, 8, 9, 0); assertEquals(expected, result); test = new DateTime(TEST_TIME1); result = test.withFields(null); assertSame(test, result); }
// ----------------------------------------------------------------------- public void testWithDate_int_int_int() { DateTime test = new DateTime(2002, 4, 5, 1, 2, 3, 4, ISO_UTC); DateTime result = test.withDate(2003, 5, 6); DateTime expected = new DateTime(2003, 5, 6, 1, 2, 3, 4, ISO_UTC); assertEquals(expected, result); test = new DateTime(TEST_TIME1); try { test.withDate(2003, 13, 1); fail(); } catch (IllegalArgumentException ex) { } }
// ----------------------------------------------------------------------- public void testWithDurationAdded_long_int() { DateTime test = new DateTime(TEST_TIME1, BUDDHIST_DEFAULT); DateTime result = test.withDurationAdded(123456789L, 1); DateTime expected = new DateTime(TEST_TIME1 + 123456789L, BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.withDurationAdded(123456789L, 0); assertSame(test, result); result = test.withDurationAdded(123456789L, 2); expected = new DateTime(TEST_TIME1 + (2L * 123456789L), BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.withDurationAdded(123456789L, -3); expected = new DateTime(TEST_TIME1 - (3L * 123456789L), BUDDHIST_DEFAULT); assertEquals(expected, result); }
// ----------------------------------------------------------------------- private void check( DateTime test, int year, int month, int day, int hour, int min, int sec, int mil) { assertEquals(year, test.getYear()); assertEquals(month, test.getMonthOfYear()); assertEquals(day, test.getDayOfMonth()); assertEquals(hour, test.getHourOfDay()); assertEquals(min, test.getMinuteOfHour()); assertEquals(sec, test.getSecondOfMinute()); assertEquals(mil, test.getMillisOfSecond()); }
public void testToMutableDateTime_Chronology() { DateTime test = new DateTime(TEST_TIME1); MutableDateTime result = test.toMutableDateTime(ISO_DEFAULT); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_DEFAULT, result.getChronology()); test = new DateTime(TEST_TIME1); result = test.toMutableDateTime(GREGORIAN_PARIS); assertEquals(test.getMillis(), result.getMillis()); assertEquals(GREGORIAN_PARIS, result.getChronology()); test = new DateTime(TEST_TIME1, GREGORIAN_PARIS); result = test.toMutableDateTime((Chronology) null); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_DEFAULT, result.getChronology()); test = new DateTime(TEST_TIME1); result = test.toMutableDateTime((Chronology) null); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_DEFAULT, result.getChronology()); }
public void testToMutableDateTime_DateTimeZone() { DateTime test = new DateTime(TEST_TIME1); MutableDateTime result = test.toMutableDateTime(LONDON); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_DEFAULT, result.getChronology()); test = new DateTime(TEST_TIME1); result = test.toMutableDateTime(PARIS); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_PARIS, result.getChronology()); test = new DateTime(TEST_TIME1, PARIS); result = test.toMutableDateTime((DateTimeZone) null); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_DEFAULT, result.getChronology()); test = new DateTime(TEST_TIME1); result = test.toMutableDateTime((DateTimeZone) null); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_DEFAULT, result.getChronology()); }
public void testWithTime_int_int_int() { DateTime test = new DateTime(TEST_TIME1 - 12345L, BUDDHIST_UTC); DateTime result = test.withTime(12, 24, 0, 0); assertEquals(TEST_TIME1, result.getMillis()); assertEquals(BUDDHIST_UTC, result.getChronology()); test = new DateTime(TEST_TIME1); try { test.withTime(25, 1, 1, 1); fail(); } catch (IllegalArgumentException ex) { } }
private void testAdd(Date start, DurationFieldType type, int amt, Date end) { DateTime dtStart = new DateTime(start, ISOChronology.getInstanceUTC()); DateTime dtEnd = new DateTime(end, ISOChronology.getInstanceUTC()); assertEquals(dtEnd, dtStart.withFieldAdded(type, amt)); assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt)); DurationField field = type.getField(ISOChronology.getInstanceUTC()); int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis()); assertEquals(amt, diff); if (type == DurationFieldType.years() || type == DurationFieldType.months() || type == DurationFieldType.days()) { LocalDate ymdStart = new LocalDate(start, ISOChronology.getInstanceUTC()); LocalDate ymdEnd = new LocalDate(end, ISOChronology.getInstanceUTC()); assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt)); assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt)); } }
// ----------------------------------------------------------------------- public void testWithDurationAdded_RP_int() { DateTime test = new DateTime(2002, 5, 3, 1, 2, 3, 4, BUDDHIST_DEFAULT); DateTime result = test.withPeriodAdded(new Period(1, 2, 3, 4, 5, 6, 7, 8), 1); DateTime expected = new DateTime(2003, 7, 28, 6, 8, 10, 12, BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.withPeriodAdded(null, 1); assertSame(test, result); result = test.withPeriodAdded(new Period(1, 2, 3, 4, 5, 6, 7, 8), 0); assertSame(test, result); result = test.withPeriodAdded(new Period(1, 2, 0, 4, 5, 6, 7, 8), 3); expected = new DateTime(2005, 11, 15, 16, 20, 24, 28, BUDDHIST_DEFAULT); assertEquals(expected, result); result = test.withPeriodAdded(new Period(1, 2, 0, 1, 1, 2, 3, 4), -1); expected = new DateTime(2001, 3, 2, 0, 0, 0, 0, BUDDHIST_DEFAULT); assertEquals(expected, result); }
public void testWithZone_DateTimeZone() { DateTime test = new DateTime(TEST_TIME1); DateTime result = test.withZone(PARIS); assertEquals(test.getMillis(), result.getMillis()); assertEquals(ISO_PARIS, result.getChronology()); test = new DateTime(TEST_TIME1, GREGORIAN_PARIS); result = test.withZone(null); assertEquals(test.getMillis(), result.getMillis()); assertEquals(GREGORIAN_DEFAULT, result.getChronology()); test = new DateTime(TEST_TIME1); result = test.withZone(null); assertSame(test, result); }
public void testToDateTime_DateTimeZone() { DateTime test = new DateTime(TEST_TIME1); DateTime result = test.toDateTime(LONDON); assertSame(test, result); test = new DateTime(TEST_TIME1); result = test.toDateTime(PARIS); assertEquals(test.getMillis(), result.getMillis()); assertEquals(PARIS, result.getZone()); test = new DateTime(TEST_TIME1, PARIS); result = test.toDateTime((DateTimeZone) null); assertEquals(test.getMillis(), result.getMillis()); assertEquals(LONDON, result.getZone()); test = new DateTime(TEST_TIME1); result = test.toDateTime((DateTimeZone) null); assertSame(test, result); }
public void testToDate() { DateTime test = new DateTime(TEST_TIME1); Date result = test.toDate(); assertEquals(test.getMillis(), result.getTime()); }
// ----------------------------------------------------------------------- public void testPlus_long() { DateTime test = new DateTime(TEST_TIME1, BUDDHIST_DEFAULT); DateTime result = test.plus(123456789L); DateTime expected = new DateTime(TEST_TIME1 + 123456789L, BUDDHIST_DEFAULT); assertEquals(expected, result); }
// ----------------------------------------------------------------------- public void testToDateMidnight() { DateTime base = new DateTime(TEST_TIME1, COPTIC_DEFAULT); DateMidnight test = base.toDateMidnight(); DateMidnight expected = new DateMidnight(base, COPTIC_DEFAULT); assertEquals(expected, test); }
public void testWithFieldAdded4() { DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime result = test.withFieldAdded(DurationFieldType.years(), 0); assertSame(test, result); }
public void testToLocalTime() { DateTime base = new DateTime(TEST_TIME1, COPTIC_DEFAULT); LocalTime test = base.toLocalTime(); assertEquals(new LocalTime(TEST_TIME1, COPTIC_DEFAULT), test); }
// ----------------------------------------------------------------------- public void testWithMillis_long() { DateTime test = new DateTime(TEST_TIME1); DateTime result = test.withMillis(TEST_TIME2); assertEquals(TEST_TIME2, result.getMillis()); assertEquals(test.getChronology(), result.getChronology()); test = new DateTime(TEST_TIME1, GREGORIAN_PARIS); result = test.withMillis(TEST_TIME2); assertEquals(TEST_TIME2, result.getMillis()); assertEquals(test.getChronology(), result.getChronology()); test = new DateTime(TEST_TIME1); result = test.withMillis(TEST_TIME1); assertSame(test, result); }
public void testWithZoneRetainFields_DateTimeZone() { DateTime test = new DateTime(TEST_TIME1); DateTime result = test.withZoneRetainFields(PARIS); assertEquals(test.getMillis() - DateTimeConstants.MILLIS_PER_HOUR, result.getMillis()); assertEquals(ISO_PARIS, result.getChronology()); test = new DateTime(TEST_TIME1); result = test.withZoneRetainFields(LONDON); assertSame(test, result); test = new DateTime(TEST_TIME1); result = test.withZoneRetainFields(null); assertSame(test, result); test = new DateTime(TEST_TIME1, GREGORIAN_PARIS); result = test.withZoneRetainFields(null); assertEquals(test.getMillis() + DateTimeConstants.MILLIS_PER_HOUR, result.getMillis()); assertEquals(GREGORIAN_DEFAULT, result.getChronology()); test = new DateTime(TEST_TIME1, new MockNullZoneChronology()); result = test.withZoneRetainFields(LONDON); assertSame(test, result); }