@Override public LocalDate convert(OffsetDateTime source) { return source.toLocalDate(); } }
@Override public LocalDate convert(OffsetDateTime source) { return source.toLocalDate(); } }
int dateInt = (int) timestamp.toLocalDateTime().atOffset(ZoneOffset.UTC).toLocalDate().toEpochDay(); int localTimeInt = (int) (localTimestamp % DateTimeUtils.MILLIS_PER_DAY); int currentTimeInt = (int) (currentTimestamp % DateTimeUtils.MILLIS_PER_DAY);
public static final long nextDayStartSec(long epochSecondsInUTC) { OffsetDateTime odt = Instant.ofEpochSecond(epochSecondsInUTC).atOffset(ZoneOffset.UTC); return odt.toLocalDate().plusDays(1).atStartOfDay(ZoneOffset.UTC).toEpochSecond(); }
@Override public LocalDate convert(OffsetDateTime source) { return source.toLocalDate(); } }
import java.time.OffsetDateTime; public class SQLDateTest { public static void main(String[] args){ Date d = java.sql.Date.valueOf(OffsetDateTime.parse("0123-12-27T00:00:00.000+01:00").toLocalDate()); System.out.println(d); } }
// Parser DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss.SSS Z"); // Parse date/time with time zone // OffsetDateTime odtWithTime = OffsetDateTime.parse("2011/02/14 00:00:00.000 -0800", formatter); OffsetDateTime odtWithTime = OffsetDateTime.parse("2011/02/14 09:30:00.999 -0800", formatter); // odtWithTime: 2011-02-14T09:30:00.999-08:00 // Remove time from odtWithTime LocalDateTime ldtWithoutTime = odtWithTime.toLocalDate().atStartOfDay(); OffsetDateTime odtWihtoutTime = OffsetDateTime.of(ldtWithoutTime, odtWithTime.getOffset()); // odtWihtoutTime: 2011-02-14T00:00-08:00 // All time information are reset to Zero
public static boolean isDaysBefore(OffsetDateTime dateTime, int days) { if (dateTime != null) { // ZonedDateTime ldt = date.atZone(ZoneId.systemDefault()); if (CURRENT_DATE_EPOCH_DAYS - dateTime.toLocalDate().toEpochDay() > days) { return true; } } return false; }
/** * Gets the inclusive temporal start date of this period of time. * * If the period is in days, then the returned temporal is a {@link LocalDate} which represents * the first day of the period.<br> * Otherwise, the date and the time in UTC/Greenwich at which this period starts on the * timeline is returned. * @return a temporal instance ({@link LocalDate} if all day period or {@link OffsetDateTime}) * otherwise. */ public Temporal getStartDate() { return isInDays() ? startDateTime.toLocalDate() : startDateTime; }
/** * Gets the end date of the recurrence. The end date of the recurrence can be unspecified, in that * case the returned end date is empty. * @return an optional recurrence end date. The optional is empty if the end date of the * recurrence is unspecified, otherwise the recurrence termination date or datetime can be get * from the {@link Optional}. The returned datetime is from UTC/Greenwich. */ public Optional<Temporal> getRecurrenceEndDate() { if (this.endDateTime != NO_RECURRENCE_END_DATE) { return Optional.of( getStartDate() instanceof LocalDate ? this.endDateTime.toLocalDate() : this.endDateTime); } return Optional.empty(); }
/** * Gets the exclusive temporal end date of this period of time. * * If the period is in days, then the returned temporal is a {@link LocalDate} which represents * the last day of the period.<br> * Otherwise, the date and the time in UTC/Greenwich at which this period ends on the * timeline is returned. * @return a temporal instance ({@link LocalDate} if all day period or {@link OffsetDateTime}) * otherwise. */ public Temporal getEndDate() { return isInDays() ? endDateTime.toLocalDate() : endDateTime; }
/** * */ @Override protected Scheduler scheduler() { OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC); return Scheduler.newFixedRateSchedule( Duration.between(now, OffsetDateTime.of(now.toLocalDate().plusDays(1).atStartOfDay(), ZoneOffset.UTC)).getSeconds(), Duration.ofDays(1).getSeconds(), TimeUnit.SECONDS); } }
private static List<Development> getDevelopments(final Tenant auth, final int loanId, final LocalDate delinquentSince) { final LocalDate lastNonDelinquentDay = delinquentSince.minusDays(1); final List<Development> developments = auth.call(z -> z.getDevelopments(loanId)) .filter(d -> d.getDateFrom().toLocalDate().isAfter(lastNonDelinquentDay)) .collect(toList()); Collections.reverse(developments); return developments; }
private static List<Development> getDevelopments(final Tenant auth, final int loanId, final LocalDate delinquentSince) { final LocalDate lastNonDelinquentDay = delinquentSince.minusDays(1); final List<Development> developments = auth.call(z -> z.getDevelopments(loanId)) .filter(d -> d.getDateFrom().toLocalDate().isAfter(lastNonDelinquentDay)) .collect(toList()); Collections.reverse(developments); return developments; }
/** * */ @Override protected Scheduler scheduler() { OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC); return Scheduler.newFixedRateSchedule( Duration.between(now, OffsetDateTime.of(now.toLocalDate().plusDays(1).atStartOfDay(), ZoneOffset.UTC)).getSeconds(), Duration.ofDays(1).getSeconds(), TimeUnit.SECONDS); } }
protected static String printLiteral(OffsetDateTime val) { return "TIMESTAMP '" + val.toLocalDate() + " " + printTime(val.toLocalTime()) + val.getOffset() + "'"; } }
public void write (Kryo kryo, Output out, OffsetDateTime obj) { LocalDateSerializer.write(out, obj.toLocalDate()); LocalTimeSerializer.write(out, obj.toLocalTime()); ZoneOffsetSerializer.write(out, obj.getOffset()); }
public void write (Kryo kryo, Output out, OffsetDateTime obj) { LocalDateSerializer.write(out, obj.toLocalDate()); LocalTimeSerializer.write(out, obj.toLocalTime()); ZoneOffsetSerializer.write(out, obj.getOffset()); }
public void write(Kryo kryo, Output out, OffsetDateTime obj) { LocalDateSerializer.write(out, obj.toLocalDate()); LocalTimeSerializer.write(out, obj.toLocalTime()); ZoneOffsetSerializer.write(out, obj.getOffset()); }
@Override @SuppressWarnings("unchecked") public <T> Literal<T> to(Type type) { switch (type.typeId()) { case TIMESTAMP: return (Literal<T>) this; case DATE: return (Literal<T>) new DateLiteral((int) ChronoUnit.DAYS.between( EPOCH_DAY, EPOCH.plus(value(), ChronoUnit.MICROS).toLocalDate())); default: } return null; } }