Search in sources :

Example 1 with YearMonthDay

use of org.joda.time.YearMonthDay in project joda-time by JodaOrg.

the class TestGregorianChronology method testMaximumValue.

public void testMaximumValue() {
    YearMonthDay ymd1 = new YearMonthDay(1999, DateTimeConstants.FEBRUARY, 1);
    DateMidnight dm1 = new DateMidnight(1999, DateTimeConstants.FEBRUARY, 1);
    Chronology chrono = GregorianChronology.getInstance();
    assertEquals(28, chrono.dayOfMonth().getMaximumValue(ymd1));
    assertEquals(28, chrono.dayOfMonth().getMaximumValue(dm1.getMillis()));
}
Also used : DateMidnight(org.joda.time.DateMidnight) YearMonthDay(org.joda.time.YearMonthDay) Chronology(org.joda.time.Chronology)

Example 2 with YearMonthDay

use of org.joda.time.YearMonthDay in project joda-time by JodaOrg.

the class TestGJChronology method testAdd.

private void testAdd(String start, DurationFieldType type, int amt, String end) {
    DateTime dtStart = new DateTime(start, GJChronology.getInstance(DateTimeZone.UTC));
    DateTime dtEnd = new DateTime(end, GJChronology.getInstance(DateTimeZone.UTC));
    assertEquals(dtEnd, dtStart.withFieldAdded(type, amt));
    assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt));
    DurationField field = type.getField(GJChronology.getInstance(DateTimeZone.UTC));
    int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis());
    assertEquals(amt, diff);
    if (type == DurationFieldType.years() || type == DurationFieldType.months() || type == DurationFieldType.days()) {
        YearMonthDay ymdStart = new YearMonthDay(start, GJChronology.getInstance(DateTimeZone.UTC));
        YearMonthDay ymdEnd = new YearMonthDay(end, GJChronology.getInstance(DateTimeZone.UTC));
        assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt));
        assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt));
    }
}
Also used : YearMonthDay(org.joda.time.YearMonthDay) DurationField(org.joda.time.DurationField) DateTime(org.joda.time.DateTime)

Example 3 with YearMonthDay

use of org.joda.time.YearMonthDay in project joda-time by JodaOrg.

the class TestISOChronology method testMaximumValue.

public void testMaximumValue() {
    DateMidnight dt = new DateMidnight(1570, 1, 1);
    while (dt.getYear() < 1590) {
        dt = dt.plusDays(1);
        YearMonthDay ymd = dt.toYearMonthDay();
        assertEquals(dt.year().getMaximumValue(), ymd.year().getMaximumValue());
        assertEquals(dt.monthOfYear().getMaximumValue(), ymd.monthOfYear().getMaximumValue());
        assertEquals(dt.dayOfMonth().getMaximumValue(), ymd.dayOfMonth().getMaximumValue());
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight) YearMonthDay(org.joda.time.YearMonthDay)

Example 4 with YearMonthDay

use of org.joda.time.YearMonthDay in project joda-time by JodaOrg.

the class TestReadablePartialConverter method testGetPartialValues.

//-----------------------------------------------------------------------
public void testGetPartialValues() throws Exception {
    TimeOfDay tod = new TimeOfDay();
    int[] expected = new int[] { 1, 2, 3, 4 };
    int[] actual = ReadablePartialConverter.INSTANCE.getPartialValues(tod, new TimeOfDay(1, 2, 3, 4), ISOChronology.getInstance(PARIS));
    assertEquals(true, Arrays.equals(expected, actual));
    try {
        ReadablePartialConverter.INSTANCE.getPartialValues(tod, new YearMonthDay(2005, 6, 9), JULIAN);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        ReadablePartialConverter.INSTANCE.getPartialValues(tod, new MockTOD(), JULIAN);
        fail();
    } catch (IllegalArgumentException ex) {
    }
}
Also used : TimeOfDay(org.joda.time.TimeOfDay) YearMonthDay(org.joda.time.YearMonthDay)

Example 5 with YearMonthDay

use of org.joda.time.YearMonthDay in project joda-time by JodaOrg.

the class TestISOChronology method testAdd.

private void testAdd(String start, DurationFieldType type, int amt, String 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()) {
        YearMonthDay ymdStart = new YearMonthDay(start, ISOChronology.getInstanceUTC());
        YearMonthDay ymdEnd = new YearMonthDay(end, ISOChronology.getInstanceUTC());
        assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt));
        assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt));
    }
}
Also used : YearMonthDay(org.joda.time.YearMonthDay) DurationField(org.joda.time.DurationField) DateTime(org.joda.time.DateTime)

Aggregations

YearMonthDay (org.joda.time.YearMonthDay)8 DateMidnight (org.joda.time.DateMidnight)3 DateTime (org.joda.time.DateTime)3 DurationField (org.joda.time.DurationField)2 Chronology (org.joda.time.Chronology)1 TimeOfDay (org.joda.time.TimeOfDay)1