Search in sources :

Example 66 with Clock

use of java.time.Clock in project jackrabbit by apache.

the class ISO8601Test method testFormatUTCShort.

public void testFormatUTCShort() {
    Calendar c = Calendar.getInstance();
    c.setTimeZone(TimeZone.getTimeZone("UTC"));
    Clock clock;
    c.setTimeInMillis(0);
    clock = Clock.fixed(Instant.ofEpochMilli(0), ZoneId.of("Z"));
    assertEquals("1970-01-01T00:00:00Z", ISO8601.SHORT.format(c));
    assertEquals("1970-01-01T00:00:00Z", ISO8601.SHORT.format(clock));
    assertEquals("1970-01-01T00:00:00Z", ISO8601.SHORT.format(0));
    assertEquals("1970-01-01T00:00:00Z", ISO8601.SHORT.format(new Date(0)));
    assertEquals("1970-01-01T00:00:00Z", ISO8601.SHORT.format(0, 0));
    assertEquals("1970-01-01T00:00:00Z", ISO8601.SHORT.format(new Date(0), 0));
    c.setTimeInMillis(123456789012L);
    clock = Clock.fixed(Instant.ofEpochMilli(123456789012L), ZoneId.of("Z"));
    assertEquals("1973-11-29T21:33:09Z", ISO8601.SHORT.format(c));
    assertEquals("1973-11-29T21:33:09Z", ISO8601.SHORT.format(clock));
    assertEquals("1973-11-29T21:33:09Z", ISO8601.SHORT.format(123456789012L));
    assertEquals("1973-11-29T21:33:09Z", ISO8601.SHORT.format(new Date(123456789012L)));
    assertEquals("1973-11-29T21:33:09Z", ISO8601.SHORT.format(123456789012L, 0));
    assertEquals("1973-11-29T21:33:09Z", ISO8601.SHORT.format(new Date(123456789012L), 0));
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Clock(java.time.Clock) Date(java.util.Date)

Example 67 with Clock

use of java.time.Clock in project jackrabbit by apache.

the class ISO8601Test method testFormatCustomTz.

public void testFormatCustomTz() {
    Calendar c = Calendar.getInstance();
    c.setTimeZone(customPlus);
    Clock clock;
    c.setTimeInMillis(0);
    clock = Clock.fixed(Instant.ofEpochMilli(0), customPlusZI);
    assertEquals("1970-01-01T01:23:00.000+01:23", ISO8601.format(c));
    assertEquals("1970-01-01T01:23:00.000+01:23", ISO8601.format(clock));
    assertEquals("1970-01-01T01:23:00.000+01:23", ISO8601.format(0, customPlus.getRawOffset() / 1000));
    assertEquals("1970-01-01T01:23:00.000+01:23", ISO8601.format(new Date(0), customPlus.getRawOffset() / 1000));
    c.setTimeInMillis(123456789012L);
    clock = Clock.fixed(Instant.ofEpochMilli(123456789012L), customPlusZI);
    assertEquals("1973-11-29T22:56:09.012+01:23", ISO8601.format(c));
    assertEquals("1973-11-29T22:56:09.012+01:23", ISO8601.format(clock));
    assertEquals("1973-11-29T22:56:09.012+01:23", ISO8601.format(123456789012L, customPlus.getRawOffset() / 1000));
    assertEquals("1973-11-29T22:56:09.012+01:23", ISO8601.format(new Date(123456789012L), customPlus.getRawOffset() / 1000));
    c.setTimeZone(customMinus);
    c.setTimeInMillis(0);
    clock = Clock.fixed(Instant.ofEpochMilli(0), customMinusZI);
    assertEquals("1969-12-31T21:58:00.000-02:02", ISO8601.format(c));
    assertEquals("1969-12-31T21:58:00.000-02:02", ISO8601.format(clock));
    assertEquals("1969-12-31T21:58:00.000-02:02", ISO8601.format(0, customMinus.getRawOffset() / 1000));
    assertEquals("1969-12-31T21:58:00.000-02:02", ISO8601.format(new Date(0), customMinus.getRawOffset() / 1000));
    c.setTimeInMillis(123456789012L);
    clock = Clock.fixed(Instant.ofEpochMilli(123456789012L), customMinusZI);
    assertEquals("1973-11-29T19:31:09.012-02:02", ISO8601.format(c));
    assertEquals("1973-11-29T19:31:09.012-02:02", ISO8601.format(clock));
    assertEquals("1973-11-29T19:31:09.012-02:02", ISO8601.format(123456789012L, customMinus.getRawOffset() / 1000));
    assertEquals("1973-11-29T19:31:09.012-02:02", ISO8601.format(new Date(123456789012L), customMinus.getRawOffset() / 1000));
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Clock(java.time.Clock) Date(java.util.Date)

Example 68 with Clock

use of java.time.Clock in project j2objc by google.

the class TCKClock_Fixed method test_withZone.

// -------------------------------------------------------------------------
public void test_withZone() {
    Clock test = Clock.fixed(INSTANT, PARIS);
    Clock changed = test.withZone(MOSCOW);
    assertEquals(test.getZone(), PARIS);
    assertEquals(changed.getZone(), MOSCOW);
}
Also used : Clock(java.time.Clock)

Example 69 with Clock

use of java.time.Clock in project j2objc by google.

the class TCKClock_Fixed method test_hashCode.

public void test_hashCode() {
    Clock a = Clock.fixed(INSTANT, ZoneOffset.UTC);
    Clock b = Clock.fixed(INSTANT, ZoneOffset.UTC);
    assertEquals(a.hashCode(), a.hashCode());
    assertEquals(a.hashCode(), b.hashCode());
    Clock c = Clock.fixed(INSTANT, PARIS);
    assertEquals(a.hashCode() == c.hashCode(), false);
    Clock d = Clock.fixed(INSTANT.minusNanos(1), ZoneOffset.UTC);
    assertEquals(a.hashCode() == d.hashCode(), false);
}
Also used : Clock(java.time.Clock)

Example 70 with Clock

use of java.time.Clock in project j2objc by google.

the class TCKClock_Fixed method test_withZone_equal.

public void test_withZone_equal() {
    Clock test = Clock.fixed(INSTANT, PARIS);
    Clock changed = test.withZone(PARIS);
    assertEquals(changed.getZone(), PARIS);
}
Also used : Clock(java.time.Clock)

Aggregations

Clock (java.time.Clock)209 Test (org.junit.Test)62 Instant (java.time.Instant)51 Test (org.testng.annotations.Test)43 LocalTime (java.time.LocalTime)15 ZonedDateTime (java.time.ZonedDateTime)12 LocalDateTime (java.time.LocalDateTime)11 ZoneId (java.time.ZoneId)11 LocalDate (java.time.LocalDate)10 OffsetDateTime (java.time.OffsetDateTime)8 Test (org.junit.jupiter.api.Test)7 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)6 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)6 IOException (java.io.IOException)6 SessionTest (com.yahoo.vespa.config.server.session.SessionTest)5 OffsetTime (java.time.OffsetTime)5 ZoneOffset (java.time.ZoneOffset)5 Chronology (java.time.chrono.Chronology)5 IsoChronology (java.time.chrono.IsoChronology)5 Date (java.util.Date)4