java.time.ZoneId Java Examples
The following examples show how to use
java.time.ZoneId.
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: TCKZoneId.java From j2objc with Apache License 2.0 | 6 votes |
@Test public void test_equals() { ZoneId test1 = ZoneId.of("Europe/London"); ZoneId test2 = ZoneId.of("Europe/Paris"); ZoneId test2b = ZoneId.of("Europe/Paris"); assertEquals(test1.equals(test2), false); assertEquals(test2.equals(test1), false); assertEquals(test1.equals(test1), true); assertEquals(test2.equals(test2), true); assertEquals(test2.equals(test2b), true); assertEquals(test1.hashCode() == test1.hashCode(), true); assertEquals(test2.hashCode() == test2.hashCode(), true); assertEquals(test2.hashCode() == test2b.hashCode(), true); }
Example #2
Source File: DefaultSystemStatusUtilityTest.java From blackduck-alert with Apache License 2.0 | 6 votes |
@Test public void startupOccurred() { SystemStatusRepository systemStatusRepository = new MockSystemStatusRepository(Boolean.FALSE); DefaultSystemStatusUtility systemStatusUtility = new DefaultSystemStatusUtility(systemStatusRepository); systemStatusUtility.startupOccurred(); //createCurrentDateTimestamp can't be modified, so the expected values for getStartupTime must be estimated LocalDateTime estimatedDate = LocalDateTime.now(); SystemStatusEntity testSystemStatus = systemStatusRepository.findAll().get(0); LocalDateTime systemStatusLocalDateTime = testSystemStatus.getStartupTime() .toInstant() .atZone(ZoneId.systemDefault()) .toLocalDateTime(); assertFalse(testSystemStatus.isInitialConfigurationPerformed()); assertNotNull(testSystemStatus.getStartupTime()); assertEquals(estimatedDate.getHour(), systemStatusLocalDateTime.getHour()); assertEquals(estimatedDate.getMinute(), systemStatusLocalDateTime.getMinute()); }
Example #3
Source File: JavaTimeConverterServiceTest.java From SimpleFlatMapper with MIT License | 6 votes |
@Test public void testObjectToOffsetDateTime() throws Exception { ZoneId zoneId = ZONE_ID; OffsetDateTime offsetDateTime = OffsetDateTime.now(zoneId); testObjectToOffsetDateTime(null, null); testObjectToOffsetDateTime(offsetDateTime, offsetDateTime); testObjectToOffsetDateTime(offsetDateTime.toLocalDateTime(), offsetDateTime); testObjectToOffsetDateTime(offsetDateTime.toInstant(), offsetDateTime); testObjectToOffsetDateTime(offsetDateTime.atZoneSameInstant(zoneId), offsetDateTime); testObjectToOffsetDateTime(offsetDateTime.atZoneSameInstant(zoneId), offsetDateTime); testObjectToOffsetDateTime(offsetDateTime.toLocalDate(), offsetDateTime.truncatedTo(ChronoUnit.DAYS)); testObjectToOffsetDateTime(Date.from(offsetDateTime.toInstant()), offsetDateTime.truncatedTo(ChronoUnit.MILLIS)); try { testObjectToOffsetDateTime("a string", offsetDateTime); fail(); } catch (IllegalArgumentException e) { // expected } }
Example #4
Source File: TestZoneId.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void test_NewYork_getOffsetInfo_gap() { ZoneId test = ZoneId.of("America/New_York"); final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 9, 2, 0, 0, 0); ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(-5), GAP); assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-5)); assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-4)); assertEquals(trans.getInstant(), createInstant(2008, 3, 9, 2, 0, 0, 0, ZoneOffset.ofHours(-5))); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-6)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-3)), false); assertEquals(trans.toString(), "Transition[Gap at 2008-03-09T02:00-05:00 to -04:00]"); assertFalse(trans.equals(null)); assertFalse(trans.equals(ZoneOffset.ofHours(-5))); 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 jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public void test_NewYork_getOffsetInfo_gap() { ZoneId test = ZoneId.of("America/New_York"); final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 9, 2, 0, 0, 0); ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(-5), GAP); assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-5)); assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-4)); assertEquals(trans.getInstant(), createInstant(2008, 3, 9, 2, 0, 0, 0, ZoneOffset.ofHours(-5))); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-6)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-3)), false); assertEquals(trans.toString(), "Transition[Gap at 2008-03-09T02:00-05:00 to -04:00]"); assertFalse(trans.equals(null)); assertFalse(trans.equals(ZoneOffset.ofHours(-5))); assertTrue(trans.equals(trans)); final ZoneOffsetTransition otherTrans = test.getRules().getTransition(dateTime); assertTrue(trans.equals(otherTrans)); assertEquals(trans.hashCode(), otherTrans.hashCode()); }
Example #6
Source File: I18nConfigOptionsProvider.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
private @Nullable Collection<ParameterOption> processParamType(String param, @Nullable Locale locale, Locale translation) { switch (param) { case "language": return getAvailable(locale, l -> new ParameterOption(l.getLanguage(), l.getDisplayLanguage(translation))); case "region": return getAvailable(locale, l -> new ParameterOption(l.getCountry(), l.getDisplayCountry(translation))); case "variant": return getAvailable(locale, l -> new ParameterOption(l.getVariant(), l.getDisplayVariant(translation))); case "timezone": Comparator<TimeZone> byOffset = (t1, t2) -> { return t1.getRawOffset() - t2.getRawOffset(); }; Comparator<TimeZone> byID = (t1, t2) -> { return t1.getID().compareTo(t2.getID()); }; return ZoneId.getAvailableZoneIds().stream().map(TimeZone::getTimeZone) .sorted(byOffset.thenComparing(byID)).map(tz -> { return new ParameterOption(tz.getID(), getTimeZoneRepresentation(tz)); }).collect(Collectors.toList()); default: return null; } }
Example #7
Source File: Bug8024141.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { ZoneId gmt = ZoneId.of("GMT"); String gmtName = gmt.getDisplayName(FULL, ENGLISH); String gmtAbbr = gmt.getDisplayName(SHORT, ENGLISH); for (String zone : ZONES) { ZoneId id = ZoneId.of(zone); String name = id.getDisplayName(FULL, ENGLISH); String abbr = id.getDisplayName(SHORT, ENGLISH); if (!name.equals(gmtName) || !abbr.equals(gmtAbbr)) { throw new RuntimeException("inconsistent name/abbr for " + zone + ":\n" + "name=" + name + ", abbr=" + abbr); } } }
Example #8
Source File: AckSenderService.java From springboot-learn with MIT License | 6 votes |
/** * 消息发送 */ public void send() { final String content = "现在时间是" + LocalDateTime.now(ZoneId.systemDefault()); //设置返回回调 rabbitTemplate.setReturnCallback(this); //设置确认回调 rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> { if (ack) { System.out.println("消息发送成功!"); } else { System.out.println("消息发送失败," + cause + correlationData.toString()); } }); rabbitTemplate.convertAndSend("ackQueue", content); }
Example #9
Source File: TCKZoneIdPrinterParser.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="parseSuccess") public void test_parseSuccess_prefix(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) { builder.appendZoneId(); pos.setIndex(3); String prefixText = "XXX" + text; TemporalAccessor parsed = builder.toFormatter().parseUnresolved(prefixText, pos); assertEquals(pos.getErrorIndex(), expectedErrorIndex >= 0 ? expectedErrorIndex + 3 : expectedErrorIndex, "Incorrect error index parsing: " + prefixText); assertEquals(pos.getIndex(), expectedIndex + 3, "Incorrect index parsing: " + prefixText); if (expected != null) { assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + prefixText); assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + prefixText); assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + prefixText); } else { assertEquals(parsed, null); } }
Example #10
Source File: TCKZoneRules.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void test_Apia_jumpOverInternationalDateLine_M10_to_P14() { // transition occurred at 2011-12-30T00:00-10:00 ZoneRules test = pacificApia(); Instant instantBefore = LocalDate.of(2011, 12, 27).atStartOfDay(ZoneOffset.UTC).toInstant(); ZoneOffsetTransition trans = test.nextTransition(instantBefore); assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2011, 12, 30, 0, 0)); assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2011, 12, 31, 0, 0)); assertEquals(trans.isGap(), true); assertEquals(trans.isOverlap(), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-10)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(+14)), false); assertEquals(trans.getDuration(), Duration.ofHours(24)); assertEquals(trans.getInstant(), LocalDateTime.of(2011, 12, 31, 0, 0).toInstant(ZoneOffset.ofHours(+14))); ZonedDateTime zdt = ZonedDateTime.of(2011, 12, 29, 23, 0, 0, 0, ZoneId.of("Pacific/Apia")); assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(2011, 12, 31, 1, 0)); }
Example #11
Source File: MockNodeRepository.java From vespa with Apache License 2.0 | 6 votes |
/** * Constructor * * @param flavors flavors to have in node repo */ public MockNodeRepository(MockCurator curator, NodeFlavors flavors) { super(flavors, new EmptyProvisionServiceProvider().getHostResourcesCalculator(), curator, Clock.fixed(Instant.ofEpochMilli(123), ZoneId.of("Z")), Zone.defaultZone(), new MockNameResolver().mockAnyLookup(), DockerImage.fromString("docker-registry.domain.tld:8080/dist/vespa"), true, false, 0); this.flavors = flavors; curator.setZooKeeperEnsembleConnectionSpec("cfg1:1234,cfg2:1234,cfg3:1234"); populate(); }
Example #12
Source File: IndexNameHelperTest.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@Test public void dateInCurrentWeek() throws Exception { LocalDateTime expectedSpanStart = LocalDateTime.of(2018, 9, 9, 0, 0, 0); LocalDateTime expectedSpanEnd = LocalDateTime.of(2018, 9, 16, 0, 0, 0); LocalDateTime oldSpanTime = LocalDateTime.of(2018, 9, 13, 0, 0, 0); LocalDateTime newSpanTime = LocalDateTime.of(2018, 9, 14, 0, 0, 0); IndexNameHelper inh = new IndexNameHelper("test_index", "w", 1); assertNull(inh.getCurrentDateSpanStart()); assertNull(inh.getCurrentDateSpanEnd()); assertEquals("test_index_2018-09-09", inh.getIndexName(oldSpanTime.atZone(ZoneId.systemDefault()).toInstant())); assertEquals(expectedSpanStart.atZone(ZoneId.systemDefault()).toInstant(), inh.getCurrentDateSpanStart()); assertEquals(expectedSpanEnd.atZone(ZoneId.systemDefault()).toInstant(), inh.getCurrentDateSpanEnd()); assertEquals("test_index_2018-09-09", inh.getIndexName(newSpanTime.atZone(ZoneId.systemDefault()).toInstant())); assertEquals(expectedSpanStart.atZone(ZoneId.systemDefault()).toInstant(), inh.getCurrentDateSpanStart()); assertEquals(expectedSpanEnd.atZone(ZoneId.systemDefault()).toInstant(), inh.getCurrentDateSpanEnd()); }
Example #13
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 #14
Source File: HUEditorRowAttributes.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 5 votes |
private final Object convertFromJson(final I_M_Attribute attribute, final Object jsonValue) { if (jsonValue == null) { return null; } final String attributeValueType = attributesStorage.getAttributeValueType(attribute); if (X_M_Attribute.ATTRIBUTEVALUETYPE_Date.equals(attributeValueType)) { final LocalDate localDate = DateTimeConverters.fromObjectToLocalDate(jsonValue.toString()); if (localDate == null) { return null; } // convert the LocalDate to ZonedDateTime using session's time zone, // because later on the date is converted to Timestamp using system's default time zone. // And we want to have a valid date for session's timezone. final ZoneId zoneId = UserSession.getTimeZoneOrSystemDefault(); return localDate.atStartOfDay(zoneId); } else { return jsonValue; } }
Example #15
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 #16
Source File: TestZoneId.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions = ZoneRulesException.class) public void test_systemDefault_unableToConvert_unknownId() { TimeZone current = TimeZone.getDefault(); try { TimeZone.setDefault(new SimpleTimeZone(127, "SomethingWeird")); ZoneId.systemDefault(); } finally { TimeZone.setDefault(current); } }
Example #17
Source File: OffsetDateTimeCodec.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
@Override public OffsetDateTime decode(ByteBuf value, FieldInformation info, Class<?> target, boolean binary, CodecContext context) { LocalDateTime origin = LocalDateTimeCodec.decodeOrigin(value, binary, context); if (origin == null) { return null; } ZoneId zone = context.getServerZoneId(); return OffsetDateTime.of(origin, zone instanceof ZoneOffset ? (ZoneOffset) zone : zone.getRules().getOffset(origin)); }
Example #18
Source File: LocalTimeExample.java From interview with MIT License | 5 votes |
public static void main(String[] args) { // Current Time LocalTime time = LocalTime.now(); System.out.println("Current Time=" + time); // Creating LocalTime by providing input arguments LocalTime specificTime = LocalTime.of(12, 20, 25, 40); System.out.println("Specific Time of Day=" + specificTime); // Try creating time by providing invalid inputs // LocalTime invalidTime = LocalTime.of(25,20); // Exception in thread "main" java.time.DateTimeException: // Invalid value for HourOfDay (valid values 0 - 23): 25 // Current date in "Asia/Kolkata", you can get it from ZoneId javadoc LocalTime timeKolkata = LocalTime.now(ZoneId.of("Asia/Kolkata")); System.out.println("Current Time in IST=" + timeKolkata); LocalTime timeShanghai = LocalTime.now(ZoneId.of("Asia/Shanghai")); System.out.println("Current Time in CTT(Shanghai)=" + timeShanghai); // java.time.zone.ZoneRulesException: Unknown time-zone ID: IST // LocalTime todayIST = LocalTime.now(ZoneId.of("IST")); // Getting date from the base date i.e 01/01/1970 LocalTime specificSecondTime = LocalTime.ofSecondOfDay(10000); System.out.println("10000th second time= " + specificSecondTime); }
Example #19
Source File: WriteBehindCacheWriterTest.java From caffeine with Apache License 2.0 | 5 votes |
@Test public void givenMultipleCacheUpdatesOnSameKey_writeBehindIsCalledWithMostRecentTime() { AtomicBoolean writerCalled = new AtomicBoolean(false); AtomicInteger numberOfEntries = new AtomicInteger(0); AtomicReference<ZonedDateTime> timeInWriteBehind = new AtomicReference<>(); // Given this cache... Cache<Long, ZonedDateTime> cache = Caffeine.newBuilder() .writer(new WriteBehindCacheWriter.Builder<Long, ZonedDateTime>() .bufferTime(1, TimeUnit.SECONDS) .coalesce(BinaryOperator.maxBy(ZonedDateTime::compareTo)) .writeAction(entries -> { // We might get here before the cache has been written to, // so just wait for the next time we are called if (entries.isEmpty()) { return; } numberOfEntries.set(entries.size()); ZonedDateTime zonedDateTime = entries.values().iterator().next(); timeInWriteBehind.set(zonedDateTime); writerCalled.set(true); }).build()) .build(); // When these cache updates happen ... cache.put(1L, ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 0, ZoneId.systemDefault())); cache.put(1L, ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 100, ZoneId.systemDefault())); cache.put(1L, ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 300, ZoneId.systemDefault())); ZonedDateTime mostRecentTime = ZonedDateTime.of( 2016, 6, 26, 8, 0, 0, 500, ZoneId.systemDefault()); cache.put(1L, mostRecentTime); // Then the write behind action gets 1 entry to write with the most recent time Awaitility.await().untilTrue(writerCalled); Assert.assertEquals(1, numberOfEntries.intValue()); Assert.assertEquals(mostRecentTime, timeInWriteBehind.get()); }
Example #20
Source File: TCKIsoChronology.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void test_era_epochSecond_2() { assertEquals(IsoChronology.INSTANCE.epochSecond(IsoEra.CE, 2008, 3, 3, 1, 2, 2, OFFSET_P0100), ZonedDateTime.of(2008, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond()); assertEquals(IsoChronology.INSTANCE.epochSecond(IsoEra.CE, 1969, 3, 3, 1, 2, 2, OFFSET_P0100), ZonedDateTime.of(1969, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond()); }
Example #21
Source File: TimeSeriesManagerTest.java From ta4j-origins with MIT License | 5 votes |
@Test public void runOnSeriesSlices(){ ZonedDateTime dateTime = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()); TimeSeries series = new MockTimeSeries(new double[]{1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d, 10d}, new ZonedDateTime[]{dateTime.withYear(2000), dateTime.withYear(2000), dateTime.withYear(2001), dateTime.withYear(2001), dateTime.withYear(2002), dateTime.withYear(2002), dateTime.withYear(2002), dateTime.withYear(2003), dateTime.withYear(2004), dateTime.withYear(2005)}); manager.setTimeSeries(series); Strategy aStrategy = new BaseStrategy(new FixedRule(0, 3, 5, 7), new FixedRule(2, 4, 6, 9)); List<Trade> trades = manager.run(aStrategy, 0, 1).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(0, series.getTick(0).getClosePrice(), Decimal.NaN),trades.get(0).getEntry()); assertEquals(Order.sellAt(2, series.getTick(2).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); trades = manager.run(aStrategy, 2, 3).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(3, series.getTick(3).getClosePrice(), Decimal.NaN), trades.get(0).getEntry()); assertEquals(Order.sellAt(4, series.getTick(4).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); trades = manager.run(aStrategy, 4, 6).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(5, series.getTick(5).getClosePrice(), Decimal.NaN), trades.get(0).getEntry()); assertEquals(Order.sellAt(6, series.getTick(6).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); trades = manager.run(aStrategy, 7, 7).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(7, series.getTick(7).getClosePrice(), Decimal.NaN), trades.get(0).getEntry()); assertEquals(Order.sellAt(9, series.getTick(9).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); trades = manager.run(aStrategy, 8, 8).getTrades(); assertTrue(trades.isEmpty()); trades = manager.run(aStrategy, 9, 9).getTrades(); assertTrue(trades.isEmpty()); }
Example #22
Source File: TestZoneId.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void test_London_getOffsetInfo_toDST() { ZoneId test = ZoneId.of("Europe/London"); checkOffset(test.getRules(), createLDT(2008, 3, 24), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 3, 25), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 3, 26), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 3, 27), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 3, 28), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 3, 29), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 3, 30), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 3, 31), ZoneOffset.ofHours(1), 1); // cutover at 01:00Z checkOffset(test.getRules(), LocalDateTime.of(2008, 3, 30, 0, 59, 59, 999999999), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), LocalDateTime.of(2008, 3, 30, 1, 30, 0, 0), ZoneOffset.ofHours(0), GAP); checkOffset(test.getRules(), LocalDateTime.of(2008, 3, 30, 2, 0, 0, 0), ZoneOffset.ofHours(1), 1); }
Example #23
Source File: TimeZoneMap.java From digdag with Apache License 2.0 | 5 votes |
public ZoneId get(long id) throws ResourceNotFoundException { ZoneId proj = map.get(id); if (proj == null) { throw new ResourceNotFoundException("timezone of workflow definition id=" + id); } return proj; }
Example #24
Source File: AuditResource.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 5 votes |
/** * GET /audits : get a page of AuditEvents between the fromDate and toDate. * * @param fromDate the start of the time period of AuditEvents to get * @param toDate the end of the time period of AuditEvents to get * @param pageable the pagination information * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body */ @GetMapping(params = {"fromDate", "toDate"}) public ResponseEntity<List<AuditEvent>> getByDates( @RequestParam(value = "fromDate") LocalDate fromDate, @RequestParam(value = "toDate") LocalDate toDate, Pageable pageable) { Page<AuditEvent> page = auditEventService.findByDates( fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant(), toDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant(), pageable); HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits"); return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); }
Example #25
Source File: QuotaResponseBuilderImplTest.java From cloudstack with Apache License 2.0 | 5 votes |
@Test public void testStartOfNextDayWithoutParameters() { Date nextDate = quotaResponseBuilder.startOfNextDay(); LocalDateTime tomorrowAtStartOfTheDay = LocalDate.now().atStartOfDay().plusDays(1); Date expectedNextDate = Date.from(tomorrowAtStartOfTheDay.atZone(ZoneId.systemDefault()).toInstant()); Assert.assertEquals(expectedNextDate, nextDate); }
Example #26
Source File: TCKZoneIdSerialization.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void test_serialization_format() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baos) ) { dos.writeByte(7); dos.writeUTF("Europe/London"); } byte[] bytes = baos.toByteArray(); assertSerializedBySer(ZoneId.of("Europe/London"), bytes); }
Example #27
Source File: TestZoneId.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_getOffset_fromDST() { ZoneId test = ZoneId.of("America/New_York"); ZoneOffset offset = ZoneOffset.ofHours(-4); assertEquals(test.getRules().getOffset(createInstant(2008, 11, 1, offset)), ZoneOffset.ofHours(-4)); assertEquals(test.getRules().getOffset(createInstant(2008, 11, 2, offset)), ZoneOffset.ofHours(-4)); assertEquals(test.getRules().getOffset(createInstant(2008, 11, 3, offset)), ZoneOffset.ofHours(-5)); assertEquals(test.getRules().getOffset(createInstant(2008, 11, 4, offset)), ZoneOffset.ofHours(-5)); assertEquals(test.getRules().getOffset(createInstant(2008, 11, 5, offset)), ZoneOffset.ofHours(-5)); assertEquals(test.getRules().getOffset(createInstant(2008, 11, 6, offset)), ZoneOffset.ofHours(-5)); assertEquals(test.getRules().getOffset(createInstant(2008, 11, 7, offset)), ZoneOffset.ofHours(-5)); // cutover at 02:00 local assertEquals(test.getRules().getOffset(createInstant(2008, 11, 2, 1, 59, 59, 999999999, offset)), ZoneOffset.ofHours(-4)); assertEquals(test.getRules().getOffset(createInstant(2008, 11, 2, 2, 0, 0, 0, offset)), ZoneOffset.ofHours(-5)); }
Example #28
Source File: TestZonedDateTimeSerialization.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@Test public void testDeserializationAsInt03NanosecondsWithTimeZone() throws Exception { ZonedDateTime date = ZonedDateTime.now(Z3); date = date.minus(date.getNano(), ChronoUnit.NANOS); ObjectMapper mapper = newMapper(TimeZone.getDefault()); ZonedDateTime value = mapper.readerFor(ZonedDateTime.class) .with(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS) .readValue(Long.toString(date.toEpochSecond())); assertIsEqual(date, value); assertEquals("The time zone is not correct.", ZoneId.systemDefault(), value.getZone()); }
Example #29
Source File: EdmTimeOfDay.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException { LocalTime time; try { time = LocalTime.parse(value); } catch (DateTimeParseException ex) { throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } // appropriate types if (returnType.isAssignableFrom(LocalTime.class)) { return (T) time; } else if (returnType.isAssignableFrom(java.sql.Time.class)) { return (T) java.sql.Time.valueOf(time); } // inappropriate types, which need to be supported for backward compatibility ZonedDateTime zdt = LocalDateTime.of(EPOCH, time).atZone(ZoneId.systemDefault()); if (returnType.isAssignableFrom(Calendar.class)) { return (T) GregorianCalendar.from(zdt); } else if (returnType.isAssignableFrom(Long.class)) { return (T) Long.valueOf(zdt.toInstant().toEpochMilli()); } else if (returnType.isAssignableFrom(java.sql.Date.class)) { throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } else if (returnType.isAssignableFrom(Timestamp.class)) { return (T) Timestamp.from(zdt.toInstant()); } else if (returnType.isAssignableFrom(java.util.Date.class)) { return (T) java.util.Date.from(zdt.toInstant()); } else { throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } }
Example #30
Source File: StripeManagerTest.java From alf.io with GNU General Public License v3.0 | 5 votes |
@BeforeEach public void setUp() { transactionRepository = mock(TransactionRepository.class); configurationManager = mock(ConfigurationManager.class); ticketRepository = mock(TicketRepository.class); event = mock(Event.class); when(event.getZoneId()).thenReturn(ZoneId.systemDefault()); customerName = mock(CustomerName.class); configurationRepository = mock(ConfigurationRepository.class); when(customerName.getFullName()).thenReturn("ciccio"); when(configurationManager.getFor(eq(PLATFORM_MODE_ENABLED), any())).thenReturn(new ConfigurationManager.MaybeConfiguration(PLATFORM_MODE_ENABLED)); }