Search in sources :

Example 31 with Partial

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

the class TestISODateTimeFormat_Fields method testForFields_time_S.

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

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

the class TestISODateTimeFormat_Fields method testForFields_time_m.

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

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

the class TestISODateTimeFormat_Fields method testForFields_time_HS.

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

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

the class TestISODateTimeFormat_Fields method testForFields_weekBased_YWD.

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

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

the class TestISODateTimeFormat_Fields method testForFields_weekBased_Y.

//-----------------------------------------------------------------------
public void testForFields_weekBased_Y() {
    DateTimeFieldType[] fields = new DateTimeFieldType[] { DateTimeFieldType.weekyear() };
    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)

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