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));
}
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));
}
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);
}
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);
}
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);
}
Aggregations