Search in sources :

Example 1 with Partial

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

the class TestISODateTimeFormat_Fields method testForFields_calBased_YMD.

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
public void testForFields_calBased_YMD() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType.year(), DateTimeFieldType.monthOfYear(), DateTimeFieldType.dayOfMonth() };
    int[] values = new int[] { 2005, 6, 25 };
    List types = new ArrayList(Arrays.asList(fields));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, true, false);
    assertEquals("2005-06-25", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, true);
    assertEquals("20050625", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, false);
    assertEquals("20050625", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
}
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 2 with Partial

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

the class TestISODateTimeFormat_Fields method testForFields_weekBased_WD.

//-----------------------------------------------------------------------
public void testForFields_weekBased_WD() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType.weekOfWeekyear(), DateTimeFieldType.dayOfWeek() };
    int[] values = new int[] { 8, 5 };
    List types = new ArrayList(Arrays.asList(fields));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("-W08-5", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, true, false);
    assertEquals("-W08-5", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, true);
    assertEquals("-W085", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, false);
    assertEquals("-W085", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
}
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 3 with Partial

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

the class TestISODateTimeFormat_Fields method testForFields_ordinalBased_Y.

//-----------------------------------------------------------------------
public void testForFields_ordinalBased_Y() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType.year() };
    int[] values = new int[] { 2005 };
    List types = new ArrayList(Arrays.asList(fields));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("2005", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, true, false);
    assertEquals("2005", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, true);
    assertEquals("2005", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, false);
    assertEquals("2005", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
}
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 4 with Partial

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

the class TestISODateTimeFormat_Fields method testForFields_time_MS.

//-----------------------------------------------------------------------
public void testForFields_time_MS() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType.minuteOfHour(), DateTimeFieldType.secondOfMinute() };
    int[] values = new int[] { 20, 30 };
    List types = new ArrayList(Arrays.asList(fields));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("-20:30", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, true, false);
    assertEquals("-20:30", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, true);
    assertEquals("-2030", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, false);
    assertEquals("-2030", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
}
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 5 with Partial

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

the class TestISODateTimeFormat_Fields method testForFields_time_MSm.

//-----------------------------------------------------------------------
public void testForFields_time_MSm() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType.minuteOfHour(), DateTimeFieldType.secondOfMinute(), DateTimeFieldType.millisOfSecond() };
    int[] values = new int[] { 20, 30, 40 };
    List types = new ArrayList(Arrays.asList(fields));
    DateTimeFormatter f = ISODateTimeFormat.forFields(types, true, true);
    assertEquals("-20:30.040", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, true, false);
    assertEquals("-20:30.040", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, true);
    assertEquals("-2030.040", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
    types = new ArrayList(Arrays.asList(fields));
    f = ISODateTimeFormat.forFields(types, false, false);
    assertEquals("-2030.040", f.print(new Partial(fields, values)));
    assertEquals(0, types.size());
}
Also used : Partial(org.joda.time.Partial) DateTimeFieldType(org.joda.time.DateTimeFieldType) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

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