Search in sources :

Example 1 with ZoneId

use of java.time.ZoneId in project dropwizard by dropwizard.

the class InstantArgumentTest method applyCalendar.

@Test
public void applyCalendar() throws Exception {
    final ZoneId systemDefault = ZoneId.systemDefault();
    // this test only asserts that a calendar was passed in. Not that the JDBC driver
    // will do the right thing and adjust the time.
    final ZonedDateTime zonedDateTime = ZonedDateTime.parse("2012-12-21T00:00:00.000Z");
    final ZonedDateTime expected = zonedDateTime.withZoneSameInstant(systemDefault);
    final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone(systemDefault));
    new InstantArgument(zonedDateTime.toInstant(), Optional.of(calendar)).apply(1, statement, context);
    Mockito.verify(statement).setTimestamp(1, Timestamp.from(expected.toInstant()), calendar);
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 2 with ZoneId

use of java.time.ZoneId in project jetty.project by eclipse.

the class RolloverFileOutputStreamTest method testMidnightRolloverCalc_Sydney_DST_End.

@Test
public void testMidnightRolloverCalc_Sydney_DST_End() {
    ZoneId zone = toZoneId("Australia/Sydney");
    ZonedDateTime initialDate = toDateTime("2016.04.02-11:22:33.0 AM AEDT", zone);
    ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate, zone);
    assertThat("Midnight", toString(midnight), is("2016.04.02-12:00:00.0 AM AEDT"));
    Object[][] expected = { { "2016.04.03-12:00:00.0 AM AEDT", 86_400_000L }, // The long day
    { "2016.04.04-12:00:00.0 AM AEST", 90_000_000L }, { "2016.04.05-12:00:00.0 AM AEST", 86_400_000L }, { "2016.04.06-12:00:00.0 AM AEST", 86_400_000L }, { "2016.04.07-12:00:00.0 AM AEST", 86_400_000L } };
    assertSequence(midnight, expected);
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 3 with ZoneId

use of java.time.ZoneId in project jetty.project by eclipse.

the class RolloverFileOutputStreamTest method testMidnightRolloverCalc_PST_DST_Start.

@Test
public void testMidnightRolloverCalc_PST_DST_Start() {
    ZoneId zone = toZoneId("PST");
    ZonedDateTime initialDate = toDateTime("2016.03.11-01:23:45.0 PM PST", zone);
    ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate, zone);
    assertThat("Midnight", toString(midnight), is("2016.03.11-12:00:00.0 AM PST"));
    Object[][] expected = { { "2016.03.12-12:00:00.0 AM PST", 86_400_000L }, { "2016.03.13-12:00:00.0 AM PST", 86_400_000L }, // the short day
    { "2016.03.14-12:00:00.0 AM PDT", 82_800_000L }, { "2016.03.15-12:00:00.0 AM PDT", 86_400_000L }, { "2016.03.16-12:00:00.0 AM PDT", 86_400_000L } };
    assertSequence(midnight, expected);
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 4 with ZoneId

use of java.time.ZoneId in project jetty.project by eclipse.

the class RolloverFileOutputStreamTest method testMidnightRolloverCalc_PST_DST_End.

@Test
public void testMidnightRolloverCalc_PST_DST_End() {
    ZoneId zone = toZoneId("PST");
    ZonedDateTime initialDate = toDateTime("2016.11.04-11:22:33.0 AM PDT", zone);
    ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate, zone);
    assertThat("Midnight", toString(midnight), is("2016.11.04-12:00:00.0 AM PDT"));
    Object[][] expected = { { "2016.11.05-12:00:00.0 AM PDT", 86_400_000L }, { "2016.11.06-12:00:00.0 AM PDT", 86_400_000L }, // the long day
    { "2016.11.07-12:00:00.0 AM PST", 90_000_000L }, { "2016.11.08-12:00:00.0 AM PST", 86_400_000L }, { "2016.11.09-12:00:00.0 AM PST", 86_400_000L } };
    assertSequence(midnight, expected);
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 5 with ZoneId

use of java.time.ZoneId in project jdk8u_jdk by JetBrains.

the class TCKJapaneseChronology method test_dateNow.

//-----------------------------------------------------------------------
@Test
public void test_dateNow() {
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now());
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(ZoneId.systemDefault()));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone()));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone().getZone()));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(ZoneId.systemDefault()));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone()));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone()));
    ZoneId zoneId = ZoneId.of("Europe/Paris");
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId)));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone()));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId)));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId).getZone()));
    assertEquals(JapaneseChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), JapaneseChronology.INSTANCE.dateNow(Clock.systemUTC()));
}
Also used : ZoneId(java.time.ZoneId) Test(org.testng.annotations.Test)

Aggregations

ZoneId (java.time.ZoneId)409 Test (org.junit.Test)136 ZonedDateTime (java.time.ZonedDateTime)103 LocalDateTime (java.time.LocalDateTime)64 LocalDate (java.time.LocalDate)54 Instant (java.time.Instant)44 Test (org.testng.annotations.Test)41 ZoneOffset (java.time.ZoneOffset)36 DateTimeFormatter (java.time.format.DateTimeFormatter)31 Date (java.util.Date)29 ArrayList (java.util.ArrayList)23 LocalTime (java.time.LocalTime)20 TemporalAccessor (java.time.temporal.TemporalAccessor)15 List (java.util.List)15 HashMap (java.util.HashMap)14 Clock (java.time.Clock)13 Collectors (java.util.stream.Collectors)13 DateTimeException (java.time.DateTimeException)11 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)11 Map (java.util.Map)11