private void checkSavedZonedDateTimeIsEqual(ZonedDateTime startdate) { final Session s = openSession(); try { final ZonedDateTimeEvent zonedDateTimeEvent = s.get( ZonedDateTimeEvent.class, 1L ); assertThat( zonedDateTimeEvent.startDate.isEqual( startdate ), is( true ) ); } finally { s.close(); } }
@Test public void firstZonedDateTime() { ZonedDateTime date = ZonedDateTime.of(2017, 6, 22, 22, 22, 0, 0, ZoneId.of("GMT")); headers.setZonedDateTime(HttpHeaders.DATE, date); assertThat(headers.getFirst(HttpHeaders.DATE), is("Thu, 22 Jun 2017 22:22:00 GMT")); assertTrue(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date)); headers.clear(); ZonedDateTime otherDate = ZonedDateTime.of(2010, 12, 18, 10, 20, 0, 0, ZoneId.of("GMT")); headers.add(HttpHeaders.DATE, RFC_1123_DATE_TIME.format(date)); headers.add(HttpHeaders.DATE, RFC_1123_DATE_TIME.format(otherDate)); assertTrue(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date)); // obsolete RFC 850 format headers.clear(); headers.set(HttpHeaders.DATE, "Thursday, 22-Jun-17 22:22:00 GMT"); assertTrue(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date)); // ANSI C's asctime() format headers.clear(); headers.set(HttpHeaders.DATE, "Thu Jun 22 22:22:00 2017"); assertTrue(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date)); }
@Test public void zonedDateTimeLosesZone() { ZonedDateTime dt = ZonedDateTime.now().withZoneSameInstant(ZoneId.of("America/Denver")); h.execute("insert into stuff(ts) values (?)", dt); assertThat(h.createQuery("select ts from stuff").mapTo(ZonedDateTime.class).findOnly().isEqual(dt)).isTrue(); }
public boolean isEqual(JodaCompatibleZonedDateTime o) { return dt.isEqual(o.getZonedDateTime()); }
@Test public void testConfigureTimeZoneOffset() { Map<String, Object> parserConfig = new HashMap<>(); parserConfig.put("deviceTimeZone", "UTC-05:00"); Syslog5424Parser testParser = new Syslog5424Parser(); testParser.configure(parserConfig); testParser.init(); ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone()); ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5)); assertTrue(deviceTime.isEqual(referenceTime)); }
@Test public void testConfigureTimeZoneText() { Map<String, Object> parserConfig = new HashMap<>(); parserConfig.put("deviceTimeZone", "America/New_York"); Syslog5424Parser testParser = new Syslog5424Parser(); testParser.configure(parserConfig); testParser.init(); ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone()); ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5)); assertTrue(deviceTime.isEqual(referenceTime)); }
@Test public void testConfigureTimeZoneText() { Map<String, Object> parserConfig = new HashMap<>(); parserConfig.put("deviceTimeZone", "America/New_York"); BasicAsaParser testParser = new BasicAsaParser(); testParser.configure(parserConfig); testParser.init(); ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone()); ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5)); assertTrue(deviceTime.isEqual(referenceTime)); }
@Test public void testConfigureTimeZoneOffset() { Map<String, Object> parserConfig = new HashMap<>(); parserConfig.put("deviceTimeZone", "UTC-05:00"); Syslog3164Parser testParser = new Syslog3164Parser(); testParser.configure(parserConfig); testParser.init(); ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone()); ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5)); assertTrue(deviceTime.isEqual(referenceTime)); }
@Test public void testConfigureTimeZoneText() { Map<String, Object> parserConfig = new HashMap<>(); parserConfig.put("deviceTimeZone", "America/New_York"); Syslog3164Parser testParser = new Syslog3164Parser(); testParser.configure(parserConfig); testParser.init(); ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone()); ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5)); assertTrue(deviceTime.isEqual(referenceTime)); }
@Test public void testConfigureTimeZoneOffset() { Map<String, Object> parserConfig = new HashMap<>(); parserConfig.put("deviceTimeZone", "UTC-05:00"); BasicAsaParser testParser = new BasicAsaParser(); testParser.configure(parserConfig); testParser.init(); ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone()); ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5)); assertTrue(deviceTime.isEqual(referenceTime)); }
@Override protected boolean relation(final ZonedDateTime d1, final ZonedDateTime d2) { Objects.requireNonNull(d1); Objects.requireNonNull(d2); return d1.isEqual(d2); } }
@Override public boolean equals(Object other) { if (other == null || getClass() != other.getClass()) { return false; } ContinuationToken continuationToken = (ContinuationToken) other; return Objects.equals(username, continuationToken.username) && expirationDate.isEqual(continuationToken.expirationDate) && Objects.equals(signature, continuationToken.signature); }
ZoneId zid = ZoneId.of("America/New_York"); ZoneOffset offset = ZoneOffset.from(LocalDateTime.now().atZone(zid)); ZonedDateTime zdt0 = ZonedDateTime.of(2014, 8, 24, 21, 10, 1, 777000002, offset); ZonedDateTime zdt1 = ZonedDateTime.of(2014, 8, 24, 21, 10, 1, 777000002, zid); System.out.println("isEqual:" + zdt0.isEqual(zdt1)); System.out.println("equals: " + zdt0.equals(zdt1));
@Override public boolean isSameAs( DateTime other ) { return other == this || instance.isEqual(other.toZonedDateTime()); }
@Override public Collection<? extends CasEvent> getEventsOfType(final String type, final ZonedDateTime dateTime) { return getEventsOfType(type) .stream() .filter(e -> e.getCreationZonedDateTime().isEqual(dateTime) || e.getCreationZonedDateTime().isAfter(dateTime)) .collect(Collectors.toSet()); }
@Override public Collection<? extends CasEvent> getEventsOfTypeForPrincipal(final String type, final String principal, final ZonedDateTime dateTime) { return getEventsOfTypeForPrincipal(type, principal) .stream() .filter(e -> e.getCreationZonedDateTime().isEqual(dateTime) || e.getCreationZonedDateTime().isAfter(dateTime)) .collect(Collectors.toSet()); }
@Override public Collection<? extends CasEvent> load(final ZonedDateTime dateTime) { return load().stream() .filter(e -> e.getCreationZonedDateTime().isEqual(dateTime) || e.getCreationZonedDateTime().isAfter(dateTime)) .collect(Collectors.toSet()); }
@Override public Collection<? extends CasEvent> getEventsForPrincipal(final String id, final ZonedDateTime dateTime) { return getEventsForPrincipal(id) .stream() .filter(e -> e.getCreationZonedDateTime().isEqual(dateTime) || e.getCreationZonedDateTime().isAfter(dateTime)) .collect(Collectors.toSet()); }
private void parseCompareDate(ZonedDateTime expected, String date, String dateFormat) { ZonedDateTime parsed = AbstractSiteMap.convertToZonedDateTime(date); if (dateFormat != null) { DateTimeFormatter fmt = DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT).withZone(ZoneId.systemDefault()); assertEquals("Failed to parse W3C date format:", fmt.format(expected), fmt.format(parsed)); } else { assertTrue("Failed to parse W3C date format: " + expected + " <> " + parsed, expected.isEqual(parsed)); } }
@Test public void testFullDateFormat() { // test example date with time zone offset // from https://www.w3.org/TR/NOTE-datetime // the (re)formatted date should be identical ZonedDateTime date1 = SiteMap.convertToZonedDateTime("1994-11-05T13:15:30Z"); ZonedDateTime date2 = SiteMap.convertToZonedDateTime("1994-11-05T08:15:30-05:00"); assertTrue("Failed to parse date with time zone", date1.isEqual(date2)); String datestr1 = SiteMap.W3C_FULLDATE_FORMATTER_UTC.format(date1); String datestr2 = SiteMap.W3C_FULLDATE_FORMATTER_UTC.format(date2); assertEquals("Failed to format date", datestr1, datestr2); }