Java Code Examples for java.time.ZoneId#of()
The following examples show how to use
java.time.ZoneId#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: TCKHijrahChronology.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_dateNow(){ assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now()) ; assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now(ZoneId.systemDefault())) ; assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now(Clock.systemDefaultZone())) ; assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now(Clock.systemDefaultZone().getZone())) ; assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ; assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ; assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ; ZoneId zoneId = ZoneId.of("Europe/Paris"); assertEquals(HijrahChronology.INSTANCE.dateNow(zoneId), HijrahChronology.INSTANCE.dateNow(Clock.system(zoneId))) ; assertEquals(HijrahChronology.INSTANCE.dateNow(zoneId), HijrahChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ; assertEquals(HijrahChronology.INSTANCE.dateNow(zoneId), HijrahDate.now(Clock.system(zoneId))) ; assertEquals(HijrahChronology.INSTANCE.dateNow(zoneId), HijrahDate.now(Clock.system(zoneId).getZone())) ; assertEquals(HijrahChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), HijrahChronology.INSTANCE.dateNow(Clock.systemUTC())) ; }
Example 2
Source File: TCKMinguoChronology.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Test public void test_dateNow(){ assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now()) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(ZoneId.systemDefault())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(Clock.systemDefaultZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(Clock.systemDefaultZone().getZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ; ZoneId zoneId = ZoneId.of("Europe/Paris"); assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId))) ; assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoDate.now(Clock.system(zoneId))) ; assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoDate.now(Clock.system(zoneId).getZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), MinguoChronology.INSTANCE.dateNow(Clock.systemUTC())) ; }
Example 3
Source File: UseZonedDateTimeUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenLocalDateOrZoned_whenSettingStartOfDay_thenReturnMidnightInAllCases() { LocalDate given = LocalDate.parse("2018-06-23"); ZoneId zone = ZoneId.of("Europe/Paris"); ZonedDateTime zonedGiven = ZonedDateTime.of(given, LocalTime.NOON, zone); ZonedDateTime startOfOfDayWithMethod = zonedDateTime.getStartOfDay(given, zone); ZonedDateTime startOfOfDayWithShorthandMethod = zonedDateTime.getStartOfDayShorthand(given, zone); ZonedDateTime startOfOfDayFromZonedDateTime = zonedDateTime.getStartOfDayFromZonedDateTime(zonedGiven); ZonedDateTime startOfOfDayAtMinTime = zonedDateTime.getStartOfDayAtMinTime(zonedGiven); ZonedDateTime startOfOfDayAtMidnightTime = zonedDateTime.getStartOfDayAtMidnightTime(zonedGiven); assertThat(startOfOfDayWithMethod).isEqualTo(startOfOfDayWithShorthandMethod) .isEqualTo(startOfOfDayFromZonedDateTime) .isEqualTo(startOfOfDayAtMinTime) .isEqualTo(startOfOfDayAtMidnightTime); assertThat(startOfOfDayWithMethod.toLocalTime()).isEqualTo(LocalTime.MIDNIGHT); assertThat(startOfOfDayWithMethod.toLocalTime() .toString()).isEqualTo("00:00"); }
Example 4
Source File: TestZoneId.java From hottub with GNU General Public License v2.0 | 6 votes |
public void test_London_getOffsetInfo_gap() { ZoneId test = ZoneId.of("Europe/London"); final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 1, 0, 0, 0); ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(0), GAP); assertEquals(trans.isGap(), true); assertEquals(trans.isOverlap(), false); assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(0)); assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(1)); assertEquals(trans.getInstant(), dateTime.toInstant(ZoneOffset.UTC)); assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2008, 3, 30, 1, 0)); assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2008, 3, 30, 2, 0)); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(0)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(1)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(2)), false); assertEquals(trans.toString(), "Transition[Gap at 2008-03-30T01:00Z to +01:00]"); assertFalse(trans.equals(null)); assertFalse(trans.equals(ZoneOffset.ofHours(0))); assertTrue(trans.equals(trans)); final ZoneOffsetTransition otherTrans = test.getRules().getTransition(dateTime); assertTrue(trans.equals(otherTrans)); assertEquals(trans.hashCode(), otherTrans.hashCode()); }
Example 5
Source File: TestZoneId.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public void test_London_getOffsetInfo_gap() { ZoneId test = ZoneId.of("Europe/London"); final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 1, 0, 0, 0); ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(0), GAP); assertEquals(trans.isGap(), true); assertEquals(trans.isOverlap(), false); assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(0)); assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(1)); assertEquals(trans.getInstant(), dateTime.toInstant(ZoneOffset.UTC)); assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2008, 3, 30, 1, 0)); assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2008, 3, 30, 2, 0)); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(0)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(1)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(2)), false); assertEquals(trans.toString(), "Transition[Gap at 2008-03-30T01:00Z to +01:00]"); assertFalse(trans.equals(null)); assertFalse(trans.equals(ZoneOffset.ofHours(0))); assertTrue(trans.equals(trans)); final ZoneOffsetTransition otherTrans = test.getRules().getTransition(dateTime); assertTrue(trans.equals(otherTrans)); assertEquals(trans.hashCode(), otherTrans.hashCode()); }
Example 6
Source File: DateProcessorTest.java From sawmill with Apache License 2.0 | 6 votes |
@Test public void testOutputForamtUnix() { String field = "datetime"; String targetField = "@timestamp"; ZoneId zoneId = ZoneId.of("Europe/Paris"); String outputFormat = "UNIX"; ZonedDateTime zonedDateTime = LocalDateTime.now().atZone(zoneId); String iso8601Format = zonedDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss,SSS")); Doc doc = createDoc(field, iso8601Format); Map<String,Object> config = createConfig("field", field, "targetField", targetField, "formats", Arrays.asList("ISO8601"), "outputFormat", outputFormat, "timeZone", zoneId.toString()); DateProcessor dateProcessor = createProcessor(DateProcessor.class, config); assertThat(dateProcessor.process(doc).isSucceeded()).isTrue(); assertThat((String)doc.getField(targetField)).isEqualTo(zonedDateTime.format(DateProcessor.UNIX)); }
Example 7
Source File: TestZoneId.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void test_Paris_getOffsetInfo() { ZoneId test = ZoneId.of("Europe/Paris"); checkOffset(test.getRules(), createLDT(2008, 1, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 2, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 3, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 4, 1), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 5, 1), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 6, 1), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 7, 1), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 8, 1), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 9, 1), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 10, 1), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 11, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 12, 1), ZoneOffset.ofHours(1), 1); }
Example 8
Source File: TestZoneId.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void test_Paris_getOffset_fromDST() { ZoneId test = ZoneId.of("Europe/Paris"); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 24, ZoneOffset.UTC)), ZoneOffset.ofHours(2)); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 25, ZoneOffset.UTC)), ZoneOffset.ofHours(2)); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 26, ZoneOffset.UTC)), ZoneOffset.ofHours(2)); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 27, ZoneOffset.UTC)), ZoneOffset.ofHours(1)); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 28, ZoneOffset.UTC)), ZoneOffset.ofHours(1)); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 29, ZoneOffset.UTC)), ZoneOffset.ofHours(1)); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 30, ZoneOffset.UTC)), ZoneOffset.ofHours(1)); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 31, ZoneOffset.UTC)), ZoneOffset.ofHours(1)); // cutover at 01:00Z assertEquals(test.getRules().getOffset(createInstant(2008, 10, 26, 0, 59, 59, 999999999, ZoneOffset.UTC)), ZoneOffset.ofHours(2)); assertEquals(test.getRules().getOffset(createInstant(2008, 10, 26, 1, 0, 0, 0, ZoneOffset.UTC)), ZoneOffset.ofHours(1)); }
Example 9
Source File: TestZoneId.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_getOffsetInfo_fromDST() { ZoneId test = ZoneId.of("America/New_York"); checkOffset(test.getRules(), createLDT(2008, 11, 1), ZoneOffset.ofHours(-4), 1); checkOffset(test.getRules(), createLDT(2008, 11, 2), ZoneOffset.ofHours(-4), 1); checkOffset(test.getRules(), createLDT(2008, 11, 3), ZoneOffset.ofHours(-5), 1); checkOffset(test.getRules(), createLDT(2008, 11, 4), ZoneOffset.ofHours(-5), 1); checkOffset(test.getRules(), createLDT(2008, 11, 5), ZoneOffset.ofHours(-5), 1); checkOffset(test.getRules(), createLDT(2008, 11, 6), ZoneOffset.ofHours(-5), 1); checkOffset(test.getRules(), createLDT(2008, 11, 7), ZoneOffset.ofHours(-5), 1); // cutover at 02:00 local checkOffset(test.getRules(), LocalDateTime.of(2008, 11, 2, 0, 59, 59, 999999999), ZoneOffset.ofHours(-4), 1); checkOffset(test.getRules(), LocalDateTime.of(2008, 11, 2, 1, 30, 0, 0), ZoneOffset.ofHours(-4), OVERLAP); checkOffset(test.getRules(), LocalDateTime.of(2008, 11, 2, 2, 0, 0, 0), ZoneOffset.ofHours(-5), 1); }
Example 10
Source File: TCKMonthDay.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void now_ZoneId() { ZoneId zone = ZoneId.of("UTC+01:02:03"); MonthDay expected = MonthDay.now(Clock.system(zone)); MonthDay test = MonthDay.now(zone); for (int i = 0; i < 100; i++) { if (expected.equals(test)) { return; } expected = MonthDay.now(Clock.system(zone)); test = MonthDay.now(zone); } assertEquals(test, expected); }
Example 11
Source File: TestDateTimeColumnHandler.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testTimestampWithFieldAttribute() throws StageException { DateTimeColumnHandler handler = new DateTimeColumnHandler(ZoneId.of("GMT"), false); Field field = handler.getDateTimeStampField( "dt", "TO_TIMESTAMP('2018-04-10 02:15:10.654321')", Types.TIMESTAMP ); Assert.assertEquals(Field.Type.DATETIME, field.getType()); Assert.assertEquals("2018-04-10 02:15:10", dateFormat.format(field.getValueAsDatetime())); Assert.assertEquals("321000", field.getAttribute("nanoSeconds")); }
Example 12
Source File: TCKZoneId.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="offsetBasedInvalid", expectedExceptions=DateTimeException.class) public void factory_of_String_offsetBasedInvalid_noPrefix(String id) { if (id.equals("Z")) { throw new DateTimeException("Fake exception: Z alone is valid, not invalid"); } ZoneId.of(id); }
Example 13
Source File: TCKClock.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_mockInstantClock_withZone() { ZoneId london = ZoneId.of("Europe/London"); Clock changed = MOCK_INSTANT.withZone(london); assertEquals(MOCK_INSTANT.instant(), INSTANT); assertEquals(MOCK_INSTANT.millis(), INSTANT.toEpochMilli()); assertEquals(changed.getZone(), london); }
Example 14
Source File: TestZoneId.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void test_London_getOffsetInfo() { ZoneId test = ZoneId.of("Europe/London"); checkOffset(test.getRules(), createLDT(2008, 1, 1), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 2, 1), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 3, 1), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 4, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 5, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 6, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 7, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 8, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 9, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 10, 1), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 11, 1), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 12, 1), ZoneOffset.ofHours(0), 1); }
Example 15
Source File: TCKYearMonth.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void now_ZoneId() { ZoneId zone = ZoneId.of("UTC+01:02:03"); YearMonth expected = YearMonth.now(Clock.system(zone)); YearMonth test = YearMonth.now(zone); for (int i = 0; i < 100; i++) { if (expected.equals(test)) { return; } expected = YearMonth.now(Clock.system(zone)); test = YearMonth.now(zone); } assertEquals(test, expected); }
Example 16
Source File: TCKYearMonth.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void now_ZoneId() { ZoneId zone = ZoneId.of("UTC+01:02:03"); YearMonth expected = YearMonth.now(Clock.system(zone)); YearMonth test = YearMonth.now(zone); for (int i = 0; i < 100; i++) { if (expected.equals(test)) { return; } expected = YearMonth.now(Clock.system(zone)); test = YearMonth.now(zone); } assertEquals(test, expected); }
Example 17
Source File: TCKDateTimeFormatters.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
void setZone(String zoneId) { if (zoneId != null) { this.zoneId = ZoneId.of(zoneId); } }
Example 18
Source File: TCKZoneId.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="offsetBasedInvalid", expectedExceptions=DateTimeException.class) public void factory_of_String_offsetBasedInvalid_prefixUTC(String id) { ZoneId.of("UTC" + id); }
Example 19
Source File: TestZoneId.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void test_London() { ZoneId test = ZoneId.of("Europe/London"); assertEquals(test.getId(), "Europe/London"); assertEquals(test.getRules().isFixedOffset(), false); }
Example 20
Source File: TimeUtil.java From emissary with Apache License 2.0 | 2 votes |
/** * Get current date/time formatted as specified * * @param format the specification * @param timeZone tz to use, defaults to GMT * @throws DateTimeException if the ID format is invalid * @throws ZoneRulesException if checking availability and the zone ID cannot be found * @throws IllegalArgumentException if the pattern is invalid */ public static String getDate(final String format, final String timeZone) { ZoneId zoneId = timeZone == null ? GMT : ZoneId.of(timeZone); return getDate(ZonedDateTime.now(zoneId), format, zoneId); }