org.threeten.bp.ZonedDateTime Java Examples
The following examples show how to use
org.threeten.bp.ZonedDateTime.
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: TestStandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void test_Paris_getStandardOffset() { ZoneRules test = europeParis(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21)); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } else { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } zdt = zdt.plusMonths(6); } }
Example #2
Source File: TestStandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void test_Dublin_getStandardOffset() { ZoneRules test = europeDublin(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.getYear() < 1881) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutes(0, -25)); } else if (zdt.getYear() >= 1881 && zdt.getYear() < 1917) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -25, -21)); } else if (zdt.getYear() >= 1917 && zdt.getYear() < 1969) { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO, zdt.toString()); } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) { // from 1968-02-18 to 1971-10-31, permanent UTC+1 assertEquals(test.getStandardOffset(instant), OFFSET_PONE); assertEquals(test.getOffset(instant), OFFSET_PONE, zdt.toString()); } else { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO, zdt.toString()); assertEquals(test.getOffset(instant), zdt.getMonth() == Month.JANUARY ? OFFSET_ZERO : OFFSET_PONE, zdt.toString()); } zdt = zdt.plusMonths(6); } }
Example #3
Source File: ExamplesTest.java From ThreeTenABP with Apache License 2.0 | 6 votes |
/** Assert that date-time info is retained after serialization and deserialization. */ @Test public void minificationAllowsSerializationZonedDateTime() throws Exception { ZonedDateTime expected = examplesActivity.getActivity().hereAndNow(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try (ObjectOutputStream os = new ObjectOutputStream(out)) { os.writeObject(expected); } byte[] bytes = out.toByteArray(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes)); ZonedDateTime actual = (ZonedDateTime) in.readObject(); // Difference is only reflected in toString and not just equals. assertEquals(expected.toString(), actual.toString()); }
Example #4
Source File: TestDateTimeParsing.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@DataProvider(name = "instantZones") Object[][] data_instantZones() { return new Object[][] { {LOCALFIELDS_ZONEID, "2014-06-30 01:02:03 Europe/Paris", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS)}, {LOCALFIELDS_ZONEID, "2014-06-30 01:02:03 +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)}, {LOCALFIELDS_OFFSETID, "2014-06-30 01:02:03 +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)}, {LOCALFIELDS_WITH_PARIS, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS)}, {LOCALFIELDS_WITH_0230, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)}, {INSTANT_WITH_PARIS, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(PARIS)}, {INSTANT_WITH_0230, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)}, {INSTANT_OFFSETID, "2014-06-30T01:02:03Z +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)}, {INSTANT_OFFSETSECONDS, "2014-06-30T01:02:03Z 9000", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)}, {INSTANTSECONDS_WITH_PARIS, "86402", Instant.ofEpochSecond(86402).atZone(PARIS)}, {INSTANTSECONDS_NOS_WITH_PARIS, "86402.123456789", Instant.ofEpochSecond(86402, 123456789).atZone(PARIS)}, {INSTANTSECONDS_OFFSETSECONDS, "86402 9000", Instant.ofEpochSecond(86402).atZone(OFFSET_0230)}, {INSTANT_OFFSETSECONDS_ZONE, "2016-10-30T00:30:00Z 7200 Europe/Paris", ZonedDateTime.ofStrict(LocalDateTime.of(2016, 10, 30, 2, 30), ZoneOffset.ofHours(2), PARIS)}, {INSTANT_OFFSETSECONDS_ZONE, "2016-10-30T01:30:00Z 3600 Europe/Paris", ZonedDateTime.ofStrict(LocalDateTime.of(2016, 10, 30, 2, 30), ZoneOffset.ofHours(1), PARIS)}, }; }
Example #5
Source File: SearchBar.java From openlauncher with Apache License 2.0 | 5 votes |
public void updateClock() { AppSettings appSettings = AppSettings.get(); if (_searchClock != null) { _searchClock.setTextColor(appSettings.getDesktopDateTextColor()); } ZonedDateTime now = ZonedDateTime.now(); _clockFormatter = getSearchBarClockFormat(Setup.appSettings().getDesktopDateMode()); String text = now.format(_clockFormatter); String[] lines = text.split("\n"); Spannable span = new SpannableString(text); span.setSpan(new RelativeSizeSpan(_searchClockSubTextFactor), lines[0].length() + 1, lines[0].length() + 1 + lines[1].length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); _searchClock.setText(span); }
Example #6
Source File: TestStandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void test_Paris_preTimeZones() { ZoneRules test = europeParis(); ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC); Instant instant = old.toInstant(); ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, 9, 21); assertEquals(test.getOffset(instant), offset); checkOffset(test, old.toLocalDateTime(), offset, 1); assertEquals(test.getStandardOffset(instant), offset); assertEquals(test.getDaylightSavings(instant), Duration.ZERO); assertEquals(test.isDaylightSavings(instant), false); }
Example #7
Source File: TestStandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void test_NewYork_getStandardOffset() { ZoneRules test = americaNewYork(); ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC); while (dateTime.getYear() < 2010) { Instant instant = dateTime.toInstant(); if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) { assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02")); } else { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5)); } dateTime = dateTime.plusMonths(6); } }
Example #8
Source File: TestStandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void test_NewYork_preTimeZones() { ZoneRules test = americaNewYork(); ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC); Instant instant = old.toInstant(); ZoneOffset offset = ZoneOffset.of("-04:56:02"); assertEquals(test.getOffset(instant), offset); checkOffset(test, old.toLocalDateTime(), offset, 1); assertEquals(test.getStandardOffset(instant), offset); assertEquals(test.getDaylightSavings(instant), Duration.ZERO); assertEquals(test.isDaylightSavings(instant), false); }
Example #9
Source File: RemoteAttestationCipher.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public static void verifyIasSignature(KeyStore trustStore, String certificates, String signatureBody, String signature, Quote quote) throws SignatureException { if (certificates == null || certificates.isEmpty()) { throw new SignatureException("No certificates."); } try { SigningCertificate signingCertificate = new SigningCertificate(certificates, trustStore); signingCertificate.verifySignature(signatureBody, signature); SignatureBodyEntity signatureBodyEntity = JsonUtil.fromJson(signatureBody, SignatureBodyEntity.class); if (signatureBodyEntity.getVersion() != SIGNATURE_BODY_VERSION) { throw new SignatureException("Unexpected signed quote version " + signatureBodyEntity.getVersion()); } if (!MessageDigest.isEqual(ByteUtil.trim(signatureBodyEntity.getIsvEnclaveQuoteBody(), 432), ByteUtil.trim(quote.getQuoteBytes(), 432))) { throw new SignatureException("Signed quote is not the same as RA quote: " + Hex.toStringCondensed(signatureBodyEntity.getIsvEnclaveQuoteBody()) + " vs " + Hex.toStringCondensed(quote.getQuoteBytes())); } if (!"OK".equals(signatureBodyEntity.getIsvEnclaveQuoteStatus())) { throw new SignatureException("Quote status is: " + signatureBodyEntity.getIsvEnclaveQuoteStatus()); } if (Instant.from(ZonedDateTime.of(LocalDateTime.from(DateTimeFormatter.ofPattern("yyy-MM-dd'T'HH:mm:ss.SSSSSS").parse(signatureBodyEntity.getTimestamp())), ZoneId.of("UTC"))) .plus(Period.ofDays(1)) .isBefore(Instant.now())) { throw new SignatureException("Signature is expired"); } } catch (CertificateException | CertPathValidatorException | IOException e) { throw new SignatureException(e); } }
Example #10
Source File: TestStandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void test_London_previousTransition_rulesBased() { ZoneRules test = europeLondon(); List<ZoneOffsetTransitionRule> rules = test.getTransitionRules(); List<ZoneOffsetTransition> trans = test.getTransitions(); ZoneOffsetTransition last = trans.get(trans.size() - 1); assertEquals(test.previousTransition(last.getInstant().plusSeconds(1)), last); assertEquals(test.previousTransition(last.getInstant().plusNanos(1)), last); // Jan 1st of year between transitions and rules ZonedDateTime odt = ZonedDateTime.ofInstant(last.getInstant(), last.getOffsetAfter()); odt = odt.withDayOfYear(1).plusYears(1).with(LocalTime.MIDNIGHT); assertEquals(test.previousTransition(odt.toInstant()), last); // later years for (int year = 1998; year < 2010; year++) { ZoneOffsetTransition a = rules.get(0).createTransition(year); ZoneOffsetTransition b = rules.get(1).createTransition(year); ZoneOffsetTransition c = rules.get(0).createTransition(year + 1); assertEquals(test.previousTransition(c.getInstant()), b); assertEquals(test.previousTransition(b.getInstant().plusSeconds(1)), b); assertEquals(test.previousTransition(b.getInstant().plusNanos(1)), b); assertEquals(test.previousTransition(b.getInstant()), a); assertEquals(test.previousTransition(a.getInstant().plusSeconds(1)), a); assertEquals(test.previousTransition(a.getInstant().plusNanos(1)), a); } }
Example #11
Source File: AbstractTestPrinterParser.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@BeforeMethod public void setUp() { printEmptyContext = new DateTimePrintContext(EMPTY, Locale.ENGLISH, DecimalStyle.STANDARD); ZonedDateTime zdt = LocalDateTime.of(2011, 6, 30, 12, 30, 40, 0).atZone(ZoneId.of("Europe/Paris")); printContext = new DateTimePrintContext(zdt, Locale.ENGLISH, DecimalStyle.STANDARD); parseContext = new DateTimeParseContext(Locale.ENGLISH, DecimalStyle.STANDARD, IsoChronology.INSTANCE); buf = new StringBuilder(); }
Example #12
Source File: TestStandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void test_London_getStandardOffset() { ZoneRules test = europeLondon(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.getYear() < 1848) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15)); } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } zdt = zdt.plusMonths(6); } }
Example #13
Source File: TestDateTimeParsing.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@DataProvider(name = "instantNoZone") Object[][] data_instantNoZone() { return new Object[][] { {INSTANT, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).toInstant()}, {INSTANTSECONDS, "86402", Instant.ofEpochSecond(86402)}, {INSTANTSECONDS_NOS, "86402.123456789", Instant.ofEpochSecond(86402, 123456789)}, }; }
Example #14
Source File: TestChronoZonedDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test( dataProvider="calendars") public void test_ChronoZonedDateTimeSerialization(Chronology chrono) throws Exception { ZonedDateTime ref = LocalDate.of(2000, 1, 5).atTime(12, 1, 2, 3).atZone(ZoneId.of("GMT+01:23")); ChronoZonedDateTime<?> orginal = chrono.date(ref).atTime(ref.toLocalTime()).atZone(ref.getZone()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(orginal); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); ChronoZonedDateTime<?> ser = (ChronoZonedDateTime<?>) in.readObject(); assertEquals(ser, orginal, "deserialized date is wrong"); }
Example #15
Source File: TestStandardZoneRules.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void test_London_preTimeZones() { ZoneRules test = europeLondon(); ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC); Instant instant = old.toInstant(); ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, -1, -15); assertEquals(test.getOffset(instant), offset); checkOffset(test, old.toLocalDateTime(), offset, 1); assertEquals(test.getStandardOffset(instant), offset); assertEquals(test.getDaylightSavings(instant), Duration.ZERO); assertEquals(test.isDaylightSavings(instant), false); }
Example #16
Source File: TestDateTimeParsing.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void test_parse_tzdbGmtZone() { String dateString = "2015,7,21,0,0,0,GMT+02:00"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy,M,d,H,m,s,z", Locale.US); ZonedDateTime parsed = ZonedDateTime.parse(dateString, formatter); assertEquals(parsed, ZonedDateTime.of(2015, 7, 21, 0, 0, 0, 0, ZoneId.of("Etc/GMT-2"))); }
Example #17
Source File: TestDateTimeParsing.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "instantZones") public void test_parse_instantZones_supported(DateTimeFormatter formatter, String text, ZonedDateTime expected) { TemporalAccessor actual = formatter.parse(text); assertEquals(actual.isSupported(INSTANT_SECONDS), true); assertEquals(actual.isSupported(EPOCH_DAY), true); assertEquals(actual.isSupported(SECOND_OF_DAY), true); assertEquals(actual.isSupported(NANO_OF_SECOND), true); assertEquals(actual.isSupported(MICRO_OF_SECOND), true); assertEquals(actual.isSupported(MILLI_OF_SECOND), true); }
Example #18
Source File: TestDateTimeFormatter.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void test_parse_allZones() throws Exception { for (String zoneStr : ZoneId.getAvailableZoneIds()) { ZoneId zone = ZoneId.of(zoneStr); ZonedDateTime base = ZonedDateTime.of(2014, 12, 31, 12, 0, 0, 0, zone); ZonedDateTime test = ZonedDateTime.parse(base.toString()); assertEquals(test, base); } }
Example #19
Source File: JacksonConfiguration.java From openapi-generator with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(ThreeTenModule.class) ThreeTenModule threeTenModule() { ThreeTenModule module = new ThreeTenModule(); module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); return module; }
Example #20
Source File: CloudSnippets.java From google-cloud-java with Apache License 2.0 | 5 votes |
/** Example of running a query with timestamp query parameters. */ public void runQueryWithTimestampParameters() throws InterruptedException { // [START bigquery_query_params_timestamps] // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); ZonedDateTime timestamp = LocalDateTime.of(2016, 12, 7, 8, 0, 0).atZone(ZoneOffset.UTC); String query = "SELECT TIMESTAMP_ADD(@ts_value, INTERVAL 1 HOUR);"; // Note: Standard SQL is required to use query parameters. QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query) .addNamedParameter( "ts_value", QueryParameterValue.timestamp( // Timestamp takes microseconds since 1970-01-01T00:00:00 UTC timestamp.toInstant().toEpochMilli() * 1000)) .build(); // Print the results. DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT.withZone(ZoneOffset.UTC); for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) { System.out.printf( "%s\n", formatter.format( Instant.ofEpochMilli( // Timestamp values are returned in microseconds since 1970-01-01T00:00:00 // UTC, // but org.joda.time.DateTime constructor accepts times in milliseconds. row.get(0).getTimestampValue() / 1000) .atOffset(ZoneOffset.UTC))); System.out.printf("\n"); } // [END bigquery_query_params_timestamps] }
Example #21
Source File: ZonedDateTimeConverterTest.java From ThreeTen-Backport-Gson-Adapter with Apache License 2.0 | 5 votes |
@Test public void testDeserialization() { String json = "\"2010-08-20T10:43:46+08:00[Asia/Shanghai]\""; ZonedDateTime zonedDateTime = gson.fromJson(json, ZonedDateTime.class); assertEquals(zonedDateTime, ZonedDateTime.parse("2010-08-20T10:43:46+08:00[Asia/Shanghai]")); }
Example #22
Source File: ZonedDateTimeConverterTest.java From ThreeTen-Backport-Gson-Adapter with Apache License 2.0 | 5 votes |
@Test public void testSerialization() { ZonedDateTime zonedDateTime = ZonedDateTime.parse("2010-08-20T10:43:46+08:00[Asia/Shanghai]"); String json = gson.toJson(zonedDateTime); assertEquals(json, "\"2010-08-20T10:43:46+08:00[Asia/Shanghai]\""); }
Example #23
Source File: OpenAPIUiConfiguration.java From openapi-generator with Apache License 2.0 | 5 votes |
@Bean public Jackson2ObjectMapperBuilder builder() { ThreeTenModule module = new ThreeTenModule(); module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); return new Jackson2ObjectMapperBuilder() .indentOutput(true) .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .modulesToInstall(module, new JsonNullableModule()) .dateFormat(new RFC3339DateFormat()); }
Example #24
Source File: JacksonConfiguration.java From openapi-generator with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(ThreeTenModule.class) ThreeTenModule threeTenModule() { ThreeTenModule module = new ThreeTenModule(); module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); return module; }
Example #25
Source File: ContactDiscoveryCipher.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
public void verifyIasSignature(KeyStore trustStore, String certificates, String signatureBody, String signature, Quote quote) throws SignatureException { if (certificates == null || certificates.isEmpty()) { throw new SignatureException("No certificates."); } try { SigningCertificate signingCertificate = new SigningCertificate(certificates, trustStore); signingCertificate.verifySignature(signatureBody, signature); SignatureBodyEntity signatureBodyEntity = JsonUtil.fromJson(signatureBody, SignatureBodyEntity.class); if (signatureBodyEntity.getVersion() != SIGNATURE_BODY_VERSION) { throw new SignatureException("Unexpected signed quote version " + signatureBodyEntity.getVersion()); } if (!MessageDigest.isEqual(ByteUtil.trim(signatureBodyEntity.getIsvEnclaveQuoteBody(), 432), ByteUtil.trim(quote.getQuoteBytes(), 432))) { throw new SignatureException("Signed quote is not the same as RA quote: " + Hex.toStringCondensed(signatureBodyEntity.getIsvEnclaveQuoteBody()) + " vs " + Hex.toStringCondensed(quote.getQuoteBytes())); } if (!"OK".equals(signatureBodyEntity.getIsvEnclaveQuoteStatus())) { throw new SignatureException("Quote status is: " + signatureBodyEntity.getIsvEnclaveQuoteStatus()); } if (Instant.from(ZonedDateTime.of(LocalDateTime.from(DateTimeFormatter.ofPattern("yyy-MM-dd'T'HH:mm:ss.SSSSSS").parse(signatureBodyEntity.getTimestamp())), ZoneId.of("UTC"))) .plus(Period.ofDays(1)) .isBefore(Instant.now())) { throw new SignatureException("Signature is expired"); } } catch (CertificateException | CertPathValidatorException | IOException e) { throw new SignatureException(e); } }
Example #26
Source File: TestDateTimeFormatters.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@DataProvider(name="weekDate") Iterator<Object[]> weekDate() { return new Iterator<Object[]>() { private ZonedDateTime date = ZonedDateTime.of(LocalDateTime.of(2003, 12, 29, 11, 5, 30), ZoneId.of("Europe/Paris")); private ZonedDateTime endDate = date.withYear(2005).withMonth(1).withDayOfMonth(2); private int week = 1; private int day = 1; public boolean hasNext() { return !date.isAfter(endDate); } public Object[] next() { StringBuilder sb = new StringBuilder("2004-W"); if (week < 10) { sb.append('0'); } sb.append(week).append('-').append(day).append(date.getOffset()); Object[] ret = new Object[] {date, sb.toString()}; date = date.plusDays(1); day += 1; if (day == 8) { day = 1; week++; } return ret; } public void remove() { throw new UnsupportedOperationException(); } }; }
Example #27
Source File: ZonedDateTimeConverter.java From ThreeTen-Backport-Gson-Adapter with Apache License 2.0 | 4 votes |
@Override public ZonedDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return FORMATTER.parse(json.getAsString(), ZonedDateTime.FROM); }
Example #28
Source File: ZonedDateTimeConverter.java From ThreeTen-Backport-Gson-Adapter with Apache License 2.0 | 4 votes |
public JsonElement serialize(ZonedDateTime src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(FORMATTER.format(src)); }
Example #29
Source File: Examples.java From ThreeTenABP with Apache License 2.0 | 4 votes |
public ZonedDateTime hereAndNow() { return ZonedDateTime.ofInstant(now(), ZoneId.systemDefault()); }
Example #30
Source File: ThreeTenGsonAdapter.java From ThreeTen-Backport-Gson-Adapter with Apache License 2.0 | 4 votes |
public static GsonBuilder registerZonedDateTime(GsonBuilder gsonBuilder) { return gsonBuilder.registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeConverter()); }