final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); final OffsetTime ot = OffsetTime.from(ta); final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); final OffsetTime ot = OffsetTime.from(ta); final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault()));
@Override public Year queryFrom(TemporalAccessor temporal) { return Year.from(temporal); } };
public static Year from(TemporalAccessor temporal) { return Year.from(temporal); }
@Override public Year convert(Object o, Context context) throws Exception { if (o == null) { return null; } if (o instanceof Date) { final ZonedDateTime dateTime = Instant.ofEpochMilli(((Date) o).getTime()).atZone(zone); return Year.of(dateTime.getYear()); } if (o instanceof Integer || o instanceof Long) { return Year.of(((Number)o).intValue()); } if (o instanceof TemporalAccessor) { return Year.from((TemporalAccessor) o); } throw new IllegalArgumentException("Cannot convert " + o + " to Year"); } }
@Override public Year convert(Object o, Context context) throws Exception { if (o == null) { return null; } if (o instanceof Date) { final ZonedDateTime dateTime = Instant.ofEpochMilli(((Date) o).getTime()).atZone(zone); return Year.of(dateTime.getYear()); } if (o instanceof Integer || o instanceof Long) { return Year.of(((Number)o).intValue()); } if (o instanceof TemporalAccessor) { return Year.from((TemporalAccessor) o); } throw new IllegalArgumentException("Cannot convert " + o + " to Year"); } }
private static String getFormatedDateString(String date, DateTimeFormatter formatter) { TemporalAccessor ta = formatter.parseBest(date, LocalDateTime::from, LocalDate::from, YearMonth::from, Year::from); if (ta instanceof LocalDateTime) { LocalDateTime ld = LocalDateTime.from(ta); return ld.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")); } if (ta instanceof LocalDate) { LocalDate ld = LocalDate.from(ta); return ld.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } if (ta instanceof YearMonth) { YearMonth ld = YearMonth.from(ta); return ld.format(DateTimeFormatter.ofPattern("yyyy-MM")); } if (ta instanceof Year) { Year ld = Year.from(ta); return ld.format(DateTimeFormatter.ofPattern("yyyy")); } return date; } }
public PastDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
public FutureDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
private static void javaTimeTypes(Map<Class, ObjectMapperRsExtractor<?>> exs) { reg(exs, LocalDate.class, (rs, i) -> { Date date = rs.getDate(i); return date != null ? date.toLocalDate() : null; }); reg(exs, LocalDateTime.class, (rs, i) -> { Timestamp stamp = rs.getTimestamp(i); return stamp != null ? stamp.toLocalDateTime() : null; }); reg(exs, LocalTime.class, (rs, i) -> { Time time = rs.getTime(i); return time != null ? time.toLocalTime() : null; }); reg(exs, Year.class, (rs, i) -> { Date date = rs.getDate(i); return date != null ? Year.from(date.toLocalDate()) : null; }); reg(exs, YearMonth.class, (rs, i) -> { Date date = rs.getDate(i); return date != null ? YearMonth.from(date.toLocalDate()) : null; }); reg(exs, Instant.class, (rs, i) -> { Timestamp stamp = rs.getTimestamp(i); return stamp != null ? stamp.toInstant() : null; }); }
public PastDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
public FutureOrPresentDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
public PastOrPresentDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
public PastOrPresentDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
private FutureOrPresentDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
public FutureDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
ldt = YearMonth.from(ta).atDay(1); } else if (ta.isSupported(ChronoField.YEAR)) { ldt = Year.from(ta).atDay(1);
Year end = Year.from(endExclusive); if (unit instanceof ChronoUnit) { long yearsUntil = ((long) end.year) - year; // no overflow
final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); final OffsetTime ot = OffsetTime.from(ta); final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); final OffsetTime ot = OffsetTime.from(ta); final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault()));
final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); final OffsetTime ot = OffsetTime.from(ta); final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); final OffsetTime ot = OffsetTime.from(ta); final Year y = Year.from(ta); final MonthDay md = MonthDay.from(ta); return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault()));
@Test public void testObjectToYear() throws Exception { ZoneId zoneId = ZoneId.systemDefault(); Date now = new Date(); Year year = Year.from(now.toInstant().atZone(zoneId)); testObjectToYear(null, null); testObjectToYear(year, year); testObjectToYear(year.atMonth(6).atEndOfMonth().atTime(1, 0).atZone(zoneId), year); testObjectToYear(now, year); testObjectToYear(year.getValue(), year); try { testObjectToYear("a string", year); fail(); } catch (IllegalArgumentException e) { // expected } }