Search in sources :

Example 41 with Partial

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

the class TestISODateTimeFormat_Fields method testForFields_datetime_YH.

//-----------------------------------------------------------------------
public void testForFields_datetime_YH() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType.year(), DateTimeFieldType.hourOfDay() };
    int[] values = new int[] { 2005, 12 };
    List types = new ArrayList(Arrays.asList(fields));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, false);
    assertEquals("2005T12", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, false);
    assertEquals("2005T12", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    try {
        ISODateTimeFormat.forFields(types, true, true);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    types = new ArrayList(Arrays.asList(fields));
    try {
        ISODateTimeFormat.forFields(types, false, true);
        fail();
    } catch (IllegalArgumentException ex) {
    }
}
Also used : Partial(org.joda.time.Partial) DateTimeFieldType(org.joda.time.DateTimeFieldType) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 42 with Partial

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

the class TestISODateTimeFormat method testFormat_time_partial.

public void testFormat_time_partial() {
    Partial dt = new Partial(new DateTimeFieldType[] { DateTimeFieldType.hourOfDay(), DateTimeFieldType.minuteOfHour(), DateTimeFieldType.secondOfMinute(), DateTimeFieldType.millisOfSecond() }, new int[] { 10, 20, 30, 40 });
    assertEquals("10:20:30.040", ISODateTimeFormat.time().print(dt));
}
Also used : Partial(org.joda.time.Partial)

Example 43 with Partial

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

the class TestISODateTimeFormat method testFormat_date_partial.

public void testFormat_date_partial() {
    Partial dt = new Partial(new DateTimeFieldType[] { DateTimeFieldType.year(), DateTimeFieldType.monthOfYear(), DateTimeFieldType.dayOfMonth() }, new int[] { 2004, 6, 9 });
    assertEquals("2004-06-09", ISODateTimeFormat.date().print(dt));
}
Also used : Partial(org.joda.time.Partial)

Aggregations

Partial (org.joda.time.Partial)43 ArrayList (java.util.ArrayList)38 List (java.util.List)38 DateTimeFieldType (org.joda.time.DateTimeFieldType)38 Test (org.junit.Test)1