Refine search
/** * Converts a MySQL {@code YEAR} value to a {@link Year} object. * * @param inputStream the binary stream containing the raw binlog event data for the value * @return the {@link Year} object * @throws IOException if there is an error reading from the binlog event data */ protected static Serializable deserializeYear(ByteArrayInputStream inputStream) throws IOException { return Year.of(1900 + inputStream.readInteger(1)); }
@Override public void serialize(Year year, JsonGenerator generator, SerializerProvider provider) throws IOException { if (useTimestamp(provider)) { generator.writeNumber(year.getValue()); } else { String str = (_formatter == null) ? year.toString() : year.format(_formatter); generator.writeString(str); } }
@Test(expected = IllegalArgumentException.class) public void remainderOnIncrementTypeExceedsMaximumYear() { Year from = Year.of(Year.MIN_VALUE); Year to = Year.of(Year.MAX_VALUE - 0); assertNotEquals(0, (to.getValue() - from.getValue()) % 10); // Maximum Year range is not divisible by 10 assertNotNull(new TemporalValueRange<>(from, to, 1, ChronoUnit.DECADES)); }
@SuppressWarnings("rawtypes") @Test public void testTimestampParsing() throws ParseException { JSONObject parsed = parser.parse(fireeyeMessage.getBytes()).get(0); JSONParser parser = new JSONParser(); Map json = (Map) parser.parse(parsed.toJSONString()); long expectedTimestamp = ZonedDateTime.of(Year.now(ZoneOffset.UTC).getValue(), 3, 19, 5, 24, 39, 0, ZoneOffset.UTC).toInstant().toEpochMilli(); Assert.assertEquals(expectedTimestamp, json.get("timestamp")); } }
return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault())); } catch (final DateTimeParseException e) { return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault())); } catch (final DateTimeParseException e) { final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); final OffsetTime ot = OffsetTime.from(ta); return GregorianCalendar.from(ot.atDate(y.atMonthDay(md)).atZoneSameInstant(ZoneId.systemDefault())); } catch (final DateTimeParseException e) { final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); final OffsetTime ot = OffsetTime.from(ta); return GregorianCalendar.from(ot.atDate(y.atMonthDay(md)).atZoneSameInstant(ZoneId.systemDefault())); } catch (final DateTimeParseException e) { final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault())); } catch (final DateTimeParseException e) { final Year y = Year.parse(str); return GregorianCalendar.from(y.atDay(1).atStartOfDay(ZoneId.systemDefault())); } catch (final DateTimeParseException e) {
assertTrue(immutability.test(Duration.ZERO)); assertTrue(immutability.test(Instant.now())); assertTrue(immutability.test(LocalDate.now())); assertTrue(immutability.test(LocalDateTime.now())); assertTrue(immutability.test(LocalTime.now())); assertTrue(immutability.test(ValueRange.of(0L, 10L))); assertTrue(immutability.test(WeekFields.ISO)); assertTrue(immutability.test(Year.now())); assertTrue(immutability.test(YearMonth.now())); assertTrue(immutability.test(ZoneOffset.UTC)); assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC).nextTransition(Instant.now()))); assertTrue(immutability.test(ZoneOffsetTransitionRule.of(Month.JANUARY, 1, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.STANDARD, ZoneOffset.UTC, ZoneOffset.ofHours(1), ZoneOffset.ofHours(2)))); assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC))); assertTrue(immutability.test(ZonedDateTime.now())); assertTrue(immutability.test(new JCIPImmutableObject()));
private static void javaTime(Map<Class, ParamSetter> ss) { reg(ss, Instant.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param))); reg(ss, OffsetDateTime.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param.toInstant()))); reg(ss, ZonedDateTime.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param.toInstant()))); reg(ss, LocalDate.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(param))); reg(ss, LocalTime.class, (param, ps, i) -> ps.setTime(i, java.sql.Time.valueOf(param))); reg(ss, LocalDateTime.class, (param, ps, i) -> ps.setTimestamp(i, java.sql.Timestamp.valueOf(param))); reg(ss, Year.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(LocalDate.of(param.getValue(), Month.JANUARY, 1)))); reg(ss, YearMonth.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(LocalDate.of(param.getYear(), param.getMonth(), 1)))); }
@Override public Instant get() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); Year year = Year.parse(input, formatter); return year.atDay(1).atStartOfDay(timeZone.toZoneId()).toInstant(); } };
public static Certificate newCert(String parentCertFile, String keyFile, String host) { try { Date before = Date.from(Instant.now()); Date after = Date.from(Year.now().plus(3, ChronoUnit.YEARS).atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant()); X509CertificateHolder parent = readPemFromFile(parentCertFile); PEMKeyPair pemKeyPair = readPemFromFile(keyFile); KeyPair keyPair = new JcaPEMKeyConverter() .setProvider(PROVIDER) .getKeyPair(pemKeyPair); X509v3CertificateBuilder x509 = new JcaX509v3CertificateBuilder( parent.getSubject(), new BigInteger(64, new SecureRandom()), before, after, new X500Name("CN=" + host), keyPair.getPublic()); ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption") .build(keyPair.getPrivate()); JcaX509CertificateConverter x509CertificateConverter = new JcaX509CertificateConverter() .setProvider(PROVIDER); return new Certificate( keyPair, x509CertificateConverter.getCertificate(x509.build(signer)), x509CertificateConverter.getCertificate(parent)); } catch (Exception e) { throw new IllegalStateException(e); } }
@Test public void testJavaYear() throws Exception { java.time.Year value = java.time.Year.now(); java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles"); newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.Year>(value), java.time.Year.class, new JavaZoneIdProperty(zoneId)); newFieldMapperAndMapToPS(NullGetter.<Object, java.time.Year>getter(), java.time.Year.class); verify(ps).setDate(1, new java.sql.Date(value.atMonthDay(MonthDay.of(Month.JANUARY, 1)).atStartOfDay(zoneId).toInstant().toEpochMilli())); verify(ps).setNull(2, Types.DATE); } //IFJAVA8_END
Validate.notNull(defaultZoneId, "ZoneId cannot be null"); if (target instanceof Instant) { return ZonedDateTime.ofInstant((Instant) target, defaultZoneId); } else if (target instanceof LocalDate) { return ZonedDateTime.of((LocalDate) target, LocalTime.MIDNIGHT, defaultZoneId); } else if (target instanceof LocalDateTime) { return ZonedDateTime.of((LocalDateTime) target, defaultZoneId); } else if (target instanceof LocalTime) { return ZonedDateTime.of(LocalDate.now(), (LocalTime) target, defaultZoneId); } else if (target instanceof OffsetDateTime) { return ((OffsetDateTime) target).toZonedDateTime(); } else if (target instanceof OffsetTime) { LocalTime localTime = ((OffsetTime) target).toLocalTime(); return ZonedDateTime.of(LocalDate.now(), localTime, defaultZoneId); } else if (target instanceof Year) { LocalDate localDate = ((Year) target).atDay(1); return ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, defaultZoneId); } else if (target instanceof YearMonth) { LocalDate localDate = ((YearMonth) target).atDay(1); return ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, defaultZoneId); } else if (target instanceof ZonedDateTime) {
addExtendedEntry(LocalDate.of(2016, 1, 1), "LocalDate", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(LocalDateTime.of(2016, 1, 1, 12, 30), "LocalDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(LocalTime.of(12, 30, 45), "LocalTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(Period.of(1, 6, 15), "Period", "The following example is a `Period` of one year, six months and fifteen days.", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(new Short("100"), "Short", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(Year.of(2016), "Year", "The following example is of the `Year` \"2016\".", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(YearMonth.of(2016, 6), "YearMonth", "The following example is a `YearMonth` of \"June 2016\"", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(ZonedDateTime.of(2016, 12, 23, 12, 12, 24, 36, ZoneId.of("GMT+2")), "ZonedDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(ZoneOffset.ofHoursMinutesSeconds(3, 6, 9), "ZoneOffset", "The following example is a `ZoneOffset` of three hours, six minutes, and nine seconds.", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addValues(SimpleDateFormat.class, new SimpleDateFormat("yMd"), new SimpleDateFormat("dMy"), new SimpleDateFormat("yMd")); addValues(TimeZone.class, TimeZone.getTimeZone("GMT+1"), TimeZone.getTimeZone("GMT+2"), TimeZone.getTimeZone("GMT+1")); addValues(Year.class, Year.of(2000), Year.of(2010), Year.of(2000)); addValues(YearMonth.class, YearMonth.of(2000, 1), YearMonth.of(2010, 12), YearMonth.of(2000, 1)); addValues(ZoneId.class, ZoneId.of("+1"), ZoneId.of("-10"), ZoneId.of("+1")); addValues(ZoneOffset.class, ZoneOffset.ofHours(1), ZoneOffset.ofHours(-1), ZoneOffset.ofHours(1)); addValues(ZonedDateTime.class, ZonedDateTime.parse("2017-12-13T10:15:30+01:00"), ZonedDateTime.parse("2016-11-12T09:14:29-01:00"), ZonedDateTime.parse("2017-12-13T10:15:30+01:00"));
temporalAccessor = ((LocalDate) temporalAccessor).plusDays(1L); } else if (temporalAccessor instanceof YearMonth) { temporalAccessor = ((YearMonth) temporalAccessor).atDay(1).plusMonths(1L); } else if (temporalAccessor instanceof Year) { temporalAccessor = ((Year) temporalAccessor).atDay(1).plusYears(1L);
LocalDate ldt = null; if (ta.isSupported(ChronoField.DAY_OF_MONTH)) { ldt = LocalDate.from(ta); } else if (ta.isSupported(ChronoField.MONTH_OF_YEAR)) { ldt = YearMonth.from(ta).atDay(1); } else if (ta.isSupported(ChronoField.YEAR)) { ldt = Year.from(ta).atDay(1); return ldt.atStartOfDay(TIME_ZONE_UTC);
temporalAccessor = ((Year) temporalAccessor).atDay(1); } else if (temporalAccessor instanceof YearMonth) { temporalAccessor = ((YearMonth) temporalAccessor).atDay(1); temporalAccessor = ((LocalDate) temporalAccessor).atStartOfDay();