Java Code Examples for java.time.ZonedDateTime#of()
The following examples show how to use
java.time.ZonedDateTime#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKLocalTime.java From hottub with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="adjustInto") Object[][] data_adjustInto() { return new Object[][]{ {LocalTime.of(23, 5), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 0, 0), null}, {LocalTime.of(23, 5, 20), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 0), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), LocalTime.of(23, 59, 59, 999999999), null}, {LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null}, {LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), LocalTime.of(12, 0, 0), null}, {LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null}, {LocalTime.of(23, 5), LocalDateTime.of(2210, 2, 2, 1, 1), LocalDateTime.of(2210, 2, 2, 23, 5), null}, {LocalTime.of(23, 5), OffsetTime.of(1, 1, 0, 0, OFFSET_PTWO), OffsetTime.of(23, 5, 0, 0, OFFSET_PTWO), null}, {LocalTime.of(23, 5), OffsetDateTime.of(2210, 2, 2, 1, 1, 0, 0, OFFSET_PTWO), OffsetDateTime.of(2210, 2, 2, 23, 5, 0, 0, OFFSET_PTWO), null}, {LocalTime.of(23, 5), ZonedDateTime.of(2210, 2, 2, 1, 1, 0, 0, ZONE_PARIS), ZonedDateTime.of(2210, 2, 2, 23, 5, 0, 0, ZONE_PARIS), null}, {LocalTime.of(23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class}, {LocalTime.of(23, 5), null, null, NullPointerException.class}, }; }
Example 2
Source File: TCKInstant.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="adjustInto") Object[][] data_adjustInto() { return new Object[][]{ {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null}, {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null}, {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null}, {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null}, {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null}, {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null}, {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class}, }; }
Example 3
Source File: SolrSearchServerTest.java From vind with Apache License 2.0 | 5 votes |
@Test public void testIndex() throws Exception { FieldDescriptor<String> title = new FieldDescriptorBuilder<>().setFullText(true).buildTextField("title"); SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder<>().setFacet(true).buildDateField("created"); MultiValueFieldDescriptor.NumericFieldDescriptor<Integer> category = new FieldDescriptorBuilder<>().setFacet(true).buildMultivaluedNumericField("category", Integer.class); final DocumentFactoryBuilder docFactoryBuilder = new DocumentFactoryBuilder("asset"); DocumentFactory documents = docFactoryBuilder.addField(title).addField(created).addField(category).build(); final ZonedDateTime creationDate = ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()); Document d1 = documents.createDoc("1") .setValue(title, "Hello World") .setValue(created, creationDate) .setValues(category, Arrays.asList(1, 2)); Document d2 = documents.createDoc("2") .setValue(title, "Hello Austria") .setValue(created, creationDate) .setValue(category, 4); server.index(d1); ArgumentCaptor<ArrayList<SolrInputDocument>> argument = ArgumentCaptor.forClass((Class)ArrayList.class); verify(solrClient).add(argument.capture()); ArrayList<SolrInputDocument> docs = argument.getValue(); SolrInputDocument doc = docs.get(0); assertThat(doc.get(SolrUtils.Fieldname.ID), solrInputField(SolrUtils.Fieldname.ID, "1")); assertThat(doc.get(SolrUtils.Fieldname.TYPE), solrInputField(SolrUtils.Fieldname.TYPE, "asset")); assertThat(doc.get("dynamic_multi_int_category"), solrInputField("dynamic_multi_int_category", Matchers.containsInAnyOrder(1,2))); assertThat(doc.get("dynamic_single_string_title"), solrInputField("dynamic_single_string_title", "Hello World")); assertThat(doc.get("dynamic_single_date_created"), solrInputField("dynamic_single_date_created", Date.from(creationDate.toInstant()))); server.commit(); SearchResult result = server.execute(Search .fulltext("hello") .filter(or(category.between(3, 5), created.before(ZonedDateTime.now()))) , documents); }
Example 4
Source File: ObjectMapperConfigTest.java From microservices-testing-examples with MIT License | 5 votes |
@Test public void iso8601Timestamps() throws IOException { TimestampedDto dto = new TimestampedDto(); dto.timestamp = ZonedDateTime.of(2019, 12, 1, 16, 30, 0, 0, UTC); assertThat(objectMapper.writeValueAsString(dto), equalTo("{\"timestamp\":\"2019-12-01T16:30:00Z\"}")); }
Example 5
Source File: TCKZonedDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_minusSeconds_seconds() { LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0); ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100); ZonedDateTime test = base.minusSeconds(1); assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100)); }
Example 6
Source File: TCKZonedDateTime.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void test_toEpochSecond_afterEpoch() { LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1); for (int i = 0; i < 100000; i++) { ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS); assertEquals(a.toEpochSecond(), i); ldt = ldt.plusSeconds(1); } }
Example 7
Source File: TCKZonedDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="sampleTimes") public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneId zone) { LocalDate localDate = LocalDate.of(y, o, d); LocalTime localTime = LocalTime.of(h, m, s, n); LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime); ZoneOffset offset = zone.getRules().getOffset(localDateTime); ZonedDateTime a = ZonedDateTime.of(localDateTime, zone); assertEquals(a.getYear(), localDate.getYear()); assertEquals(a.getMonth(), localDate.getMonth()); assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth()); assertEquals(a.getDayOfYear(), localDate.getDayOfYear()); assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek()); assertEquals(a.getHour(), localTime.getHour()); assertEquals(a.getMinute(), localTime.getMinute()); assertEquals(a.getSecond(), localTime.getSecond()); assertEquals(a.getNano(), localTime.getNano()); assertEquals(a.toLocalDate(), localDate); assertEquals(a.toLocalTime(), localTime); assertEquals(a.toLocalDateTime(), localDateTime); if (zone instanceof ZoneOffset) { assertEquals(a.toString(), localDateTime.toString() + offset.toString()); } else { assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]"); } }
Example 8
Source File: TCKDateTimeParseResolver.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions = DateTimeParseException.class) public void test_fieldResolvesToChronoZonedDateTime_overrideZone_wrongZone() { ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS); DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter(); f = f.withZone(ZoneId.of("Europe/London")); f.parse("1234567890"); }
Example 9
Source File: TCKZonedDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_toEpochSecond_beforeEpoch() { LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1); for (int i = 0; i < 100000; i++) { ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS); assertEquals(a.toEpochSecond(), -i); ldt = ldt.minusSeconds(1); } }
Example 10
Source File: TCKZonedDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_compareTo_hourDifference() { ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 10, 0, 0, 0, ZONE_0100); ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 0, 0, 0, ZONE_0200); // a is before b despite being same time-line time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); }
Example 11
Source File: TCKZonedDateTime.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_minusMonths_zero() { LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0); ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100); ZonedDateTime test = base.minusMonths(0); assertEquals(test, base); }
Example 12
Source File: TCKZonedDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="sampleTimes") public void test_equals_false_minute_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) { m = (m == 59 ? 58 : m); ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100); ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m + 1, s, n), ZONE_0100); assertEquals(a.equals(b), false); }
Example 13
Source File: TestDateUtil.java From sailfish-core with Apache License 2.0 | 5 votes |
@Test public void name() { DateTimeFormatter formatter = DateTimeUtility.createFormatter("yyyyMMdd-HH:mm:ss.SSS"); LocalDateTime localDateTime = DateTimeUtility.nowLocalDateTime(); System.out.println(localDateTime); ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.systemDefault()); System.out.println(LocalDateTime.parse("20170215-15:47:22.928", formatter)); System.out.println(ZonedDateTime.parse("20170215-15:47:22.928", formatter)); System.out.println(zonedDateTime); System.out.println(zonedDateTime.format(formatter)); System.out.println(zonedDateTime.withZoneSameInstant(ZoneId.of("UTC"))); System.out.println(zonedDateTime.format(formatter)); }
Example 14
Source File: ExecutionTimeQuartzIntegrationTest.java From cron-utils with Apache License 2.0 | 5 votes |
/** * Issue #153 * https://github.com/jmrozanec/cron-utils/issues/153 * Reported case: executionTime.nextExecution fails to find when current month does not have desired day */ @Test public void mustJumpToNextMonthIfCurrentMonthDoesNotHaveDesiredDay() { final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("0 0 8 31 * ?"));//8:00 on every 31th of Month final ZonedDateTime start = ZonedDateTime.of(2017, 04, 10, 0, 0, 0, 0, ZoneId.systemDefault()); final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(start); if (nextExecution.isPresent()) { final ZonedDateTime next = nextExecution.get(); final ZonedDateTime expected = ZonedDateTime.of(2017, 05, 31, 8, 0, 0, 0, ZoneId.systemDefault()); assertEquals(expected, next); } else { fail(NEXT_EXECUTION_NOT_PRESENT_ERROR); } }
Example 15
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@DataProvider(name="formatWithZoneWithChronology") Object[][] data_format_withZone_withChronology() { YearMonth ym = YearMonth.of(2008, 6); LocalDate ld = LocalDate.of(2008, 6, 30); LocalTime lt = LocalTime.of(11, 30); LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 11, 30); OffsetTime ot = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE); OffsetDateTime odt = OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PONE); ZonedDateTime zdt = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS); ChronoZonedDateTime<ThaiBuddhistDate> thaiZdt = ThaiBuddhistChronology.INSTANCE.zonedDateTime(zdt); Instant instant = Instant.ofEpochSecond(3600); return new Object[][] { {null, null, DayOfWeek.MONDAY, "::::"}, {null, null, ym, "2008::::ISO"}, {null, null, ld, "2008::::ISO"}, {null, null, lt, ":11:::"}, {null, null, ldt, "2008:11:::ISO"}, {null, null, ot, ":11:+01:00::"}, {null, null, odt, "2008:11:+01:00::ISO"}, {null, null, zdt, "2008:11:+02:00:Europe/Paris:ISO"}, {null, null, instant, "::::"}, {IsoChronology.INSTANCE, null, DayOfWeek.MONDAY, "::::ISO"}, {IsoChronology.INSTANCE, null, ym, "2008::::ISO"}, {IsoChronology.INSTANCE, null, ld, "2008::::ISO"}, {IsoChronology.INSTANCE, null, lt, ":11:::ISO"}, {IsoChronology.INSTANCE, null, ldt, "2008:11:::ISO"}, {IsoChronology.INSTANCE, null, ot, ":11:+01:00::ISO"}, {IsoChronology.INSTANCE, null, odt, "2008:11:+01:00::ISO"}, {IsoChronology.INSTANCE, null, zdt, "2008:11:+02:00:Europe/Paris:ISO"}, {IsoChronology.INSTANCE, null, instant, "::::ISO"}, {null, ZONE_PARIS, DayOfWeek.MONDAY, ":::Europe/Paris:"}, {null, ZONE_PARIS, ym, "2008:::Europe/Paris:ISO"}, {null, ZONE_PARIS, ld, "2008:::Europe/Paris:ISO"}, {null, ZONE_PARIS, lt, ":11::Europe/Paris:"}, {null, ZONE_PARIS, ldt, "2008:11::Europe/Paris:ISO"}, {null, ZONE_PARIS, ot, ":11:+01:00:Europe/Paris:"}, {null, ZONE_PARIS, odt, "2008:12:+02:00:Europe/Paris:ISO"}, {null, ZONE_PARIS, zdt, "2008:11:+02:00:Europe/Paris:ISO"}, {null, ZONE_PARIS, instant, "1970:02:+01:00:Europe/Paris:ISO"}, {null, OFFSET_PTHREE, DayOfWeek.MONDAY, ":::+03:00:"}, {null, OFFSET_PTHREE, ym, "2008:::+03:00:ISO"}, {null, OFFSET_PTHREE, ld, "2008:::+03:00:ISO"}, {null, OFFSET_PTHREE, lt, ":11::+03:00:"}, {null, OFFSET_PTHREE, ldt, "2008:11::+03:00:ISO"}, {null, OFFSET_PTHREE, ot, null}, // offset and zone clash {null, OFFSET_PTHREE, odt, "2008:13:+03:00:+03:00:ISO"}, {null, OFFSET_PTHREE, zdt, "2008:12:+03:00:+03:00:ISO"}, {null, OFFSET_PTHREE, instant, "1970:04:+03:00:+03:00:ISO"}, {ThaiBuddhistChronology.INSTANCE, null, DayOfWeek.MONDAY, null}, // not a complete date {ThaiBuddhistChronology.INSTANCE, null, ym, null}, // not a complete date {ThaiBuddhistChronology.INSTANCE, null, ld, "2551::::ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, null, lt, ":11:::ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, null, ldt, "2551:11:::ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, null, ot, ":11:+01:00::ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, null, odt, "2551:11:+01:00::ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, null, zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, null, instant, "::::ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, null, DayOfWeek.MONDAY, null}, // not a complete date {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ym, null}, // not a complete date {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ld, "2551:::Europe/Paris:ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, lt, ":11::Europe/Paris:ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ldt, "2551:11::Europe/Paris:ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, ot, ":11:+01:00:Europe/Paris:ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, odt, "2551:12:+02:00:Europe/Paris:ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, instant, "2513:02:+01:00:Europe/Paris:ThaiBuddhist"}, {null, ZONE_PARIS, thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"}, {ThaiBuddhistChronology.INSTANCE, ZONE_PARIS, thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"}, {IsoChronology.INSTANCE, ZONE_PARIS, thaiZdt, "2008:11:+02:00:Europe/Paris:ISO"}, }; }
Example 16
Source File: TCKZonedDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_of_LocalDateTime_nullDateTime() { ZonedDateTime.of((LocalDateTime) null, ZONE_PARIS); }
Example 17
Source File: TCKZonedDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Test public void test_with_adjuster_Offset_timeAdjust() { ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(2012, 7, 31, 0, 0), ZONE_PARIS); ZonedDateTime test = base.with(ZoneOffset.ofHours(1)); check(test, 2012, 7, 31, 0, 0, 0, 0, OFFSET_0200, ZONE_PARIS); // invalid offset ignored }
Example 18
Source File: TCKZonedDateTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Test public void factory_of_LocalDateLocalTime() { ZonedDateTime test = ZonedDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500), ZONE_PARIS); check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS); }
Example 19
Source File: TCKZonedDateTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_of_LocalDateTime_nullZone() { LocalDateTime base = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500); ZonedDateTime.of(base, null); }
Example 20
Source File: TCKZonedDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void test_isBefore_null() { ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100); a.isBefore(null); }