Search in sources :

Example 1 with Time

use of org.apache.pivot.util.Time in project pivot by apache.

the class CalendarDateTest method test2.

@Test
public void test2() {
    // PIVOT-1010: test interaction with LocalDate, etc. (new Java 8 classes)
    LocalDate ld1 = LocalDate.of(1941, 12, 7);
    CalendarDate cd1 = new CalendarDate(ld1);
    CalendarDate cd1a = CalendarDate.decode(d1);
    LocalDate ld1a = cd1a.toLocalDate();
    assertEquals(cd1, cd1a);
    assertEquals(ld1, ld1a);
    Time t1 = Time.decode("07:48:00");
    LocalDateTime dt1 = LocalDateTime.of(1941, 12, 7, 7, 48, 0);
    LocalDateTime dt1a = cd1.toLocalDateTime(t1);
    assertEquals(dt1, dt1a);
}
Also used : LocalDateTime(java.time.LocalDateTime) CalendarDate(org.apache.pivot.util.CalendarDate) Time(org.apache.pivot.util.Time) LocalDateTime(java.time.LocalDateTime) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 2 with Time

use of org.apache.pivot.util.Time in project pivot by apache.

the class TimeTest method localTimeTest.

@Test
public void localTimeTest() {
    LocalTime localTime = LocalTime.of(7, 48);
    Time t1 = new Time(localTime);
    Time t1a = Time.decode("07:48:00.000");
    assertEquals(t1, t1a);
    assertEquals(t1.toString(), "07:48:00");
    // Test rounding of nanoseconds to milliseconds
    LocalTime lt1 = LocalTime.of(7, 48, 10, 499999);
    LocalTime lt2 = LocalTime.of(7, 48, 10, 500000);
    Time t2 = new Time(lt1);
    Time t2a = new Time(7, 48, 10, 0);
    Time t3 = new Time(lt2);
    Time t3a = new Time(7, 48, 10, 1);
    assertEquals(t2, t2a);
    assertEquals(t3, t3a);
    assertEquals(t2.toString(), "07:48:10");
    assertEquals(t3.toString(), "07:48:10.001");
}
Also used : LocalTime(java.time.LocalTime) Time(org.apache.pivot.util.Time) LocalTime(java.time.LocalTime) Test(org.junit.Test)

Example 3 with Time

use of org.apache.pivot.util.Time in project pivot by apache.

the class TimeTest method basicTest.

@Test
public void basicTest() {
    Time time = new Time();
    System.out.println(time);
    time = new Time(time.toMilliseconds());
    System.out.println(time);
    time = Time.decode(time.toString());
    System.out.println(time);
    time = new Time(0, 0, 0);
    int i1 = time.subtract(new Time(0, 0, 1));
    System.out.println(i1);
    assertEquals(i1, -1000);
    int i2 = time.subtract(new Time(23, 59, 59, 999));
    System.out.println(i2);
    assertEquals(i2, -(Time.MILLISECONDS_PER_DAY - 1));
    Time time0 = new Time(0, 0, 0);
    time = time0;
    Time time1 = time.add(1);
    System.out.println(time1);
    assertEquals(time1.toString(), "00:00:00.001");
    Time time2 = time.add(Time.MILLISECONDS_PER_DAY + 1);
    System.out.println(time2);
    assertEquals(time1, time2);
    assertEquals(time2.toString(), "00:00:00.001");
    Time time3 = time.add(-1);
    System.out.println(time3);
    assertEquals(time3.toString(), "23:59:59.999");
    Time time4 = time.add(-Time.MILLISECONDS_PER_DAY - 1);
    System.out.println(time4);
    assertEquals(time4.toString(), "23:59:59.999");
    Time time5 = time.add(1000);
    Time time5a = new Time(0, 0, 1);
    System.out.println(time5);
    assertEquals(time5, time5a);
    assertEquals(time5.toString(), "00:00:01");
    Time time6 = time.add(-1000);
    Time time6a = new Time(23, 59, 59);
    System.out.println(time6);
    assertEquals(time6, time6a);
    assertEquals(time6.toString(), "23:59:59");
    time = Time.decode("00:00:00");
    System.out.println(time);
    assertEquals(time, time0);
    time = Time.decode("00:00:00.000");
    System.out.println(time);
    assertEquals(time, time0);
    try {
        time = Time.decode("00:00");
    } catch (IllegalArgumentException exception) {
        System.out.println(exception);
        assertEquals(exception.toString(), "java.lang.IllegalArgumentException: Invalid time format: 00:00");
    }
    try {
        time = Time.decode("00:00:00.00");
    } catch (IllegalArgumentException exception) {
        System.out.println(exception);
        assertEquals(exception.toString(), "java.lang.IllegalArgumentException: Invalid time format: 00:00:00.00");
    }
}
Also used : Time(org.apache.pivot.util.Time) LocalTime(java.time.LocalTime) Test(org.junit.Test)

Aggregations

Time (org.apache.pivot.util.Time)3 Test (org.junit.Test)3 LocalTime (java.time.LocalTime)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 CalendarDate (org.apache.pivot.util.CalendarDate)1