return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis(); case "bound_time": return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis(); case "bound_timestamp": return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis();
LocalTime localTime = new LocalTime( 13 , 15 ); // Quarter-hour after 1 PM. System.out.println( "localTime: " + localTime ); DateTimeZone timeZone = DateTimeZone.forID( "America/Montreal" ); // Or DateTimeZone.UTC DateTime today = localTime.toDateTimeToday( timeZone ); DateTime now = DateTime.now(); // You may want to pad an bit of extra time in case now is extremely close to midnight (new day). if ( today.isBefore( now ) ) { // If the local time in question when applied to today has already past, then // adjust to tomorrow while accounting for Daylight Saving Time or other anomaly. DateTime tomorrowInitial = today.plusDays( 1 ); // Get tomorrow by adding 1 day to today. DateTime tomorrow = localTime.toDateTime( tomorrowInitial ); // DST or other anomaly may mean that tomorrow got adjusted to a different time-of-day. Override with our desired time-of-day. System.out.println( "tomorrow: " + tomorrow ); // return tomorrow; } System.out.println( "today: " + today ); // return today;
public DateTimeRange(final DateTime day, final TimeRange range) { DateTime from; DateTime to; if (range.startsDayBefore()) { to = range.getTo().toDateTime(day.plusDays(1)); } else { to = range.getTo().toDateTime(day); } from = range.getFrom().toDateTime(day); interval = new Interval(from, to); }
/** * Returns true if the given DateTime matches the time range indicated by the * filter/rule. * @param currentTime * @param filter */ private boolean matchesTime(TimeRestrictedAccess filter) { Date start = filter.getTimeStart(); Date end = filter.getTimeEnd(); if (end == null || start == null) { return true; } long startMs = start.getTime(); long endMs = end.getTime(); DateTime currentTime = new LocalTime(DateTimeZone.UTC).toDateTime(new DateTime(0l)); long nowMs = currentTime.toDate().getTime(); return nowMs >= startMs && nowMs < endMs; }
@Override public DateTime getDateTime() { DateTime dt = this.dateTime; if (dt == null) { dt = this.timeDimension.getTime().toDateTime(this.dateDimension.getDate()); this.dateTime = dt; } return dt; }
public void setActionTime(String actionTime) { if (StringUtils.isNotBlank(actionTime)) { setLocalTime(actionTime != null ? FORMATTER.parseLocalTime(actionTime) : null); if (localDate != null && localTime != null) { actionDateTime = localTime.toDateTime(localDate.toDateTimeAtStartOfDay()).toDate(); } } }
@Override public Object encode(Object value, MappedField optionalExtraInfo) { if (null == value) { return null; } if (value instanceof DateTime) { DateTime dateTime = (DateTime) value; return dateTime.getMillis(); } else if (value instanceof LocalDateTime) { LocalDateTime localDateTime = (LocalDateTime) value; return localDateTime.toDateTime().getMillis(); } else if (value instanceof LocalDate) { LocalDate localDate = (LocalDate) value; return localDate.toDateTimeAtStartOfDay().getMillis(); } else if (value instanceof LocalTime) { LocalTime localTime = (LocalTime) value; return localTime.toDateTime(new DateTime(0)).getMillis(); } else { assert false; return null; } }
private DateRange buildDateRangeFrom(final TimeRange timeRange, final Date date) { DateTime dateTime = new DateTime(date); DateTime midnight = dateTime.withTimeAtStartOfDay(); DateTime from; DateTime to; if (timeRange.startsDayBefore()) { if (dateTime.toLocalTime().isBefore(timeRange.getFrom())) { from = timeRange.getFrom().toDateTime(midnight.minusDays(1)); to = timeRange.getTo().toDateTime(midnight); } else { from = timeRange.getFrom().toDateTime(midnight); to = timeRange.getTo().toDateTime(midnight.plusDays(1)); } } else { from = timeRange.getFrom().toDateTime(midnight); to = timeRange.getTo().toDateTime(midnight); } return new DateRange(from.toDate(), to.toDate()); }
import org.joda.time.DateTime; import org.joda.time.DateTimeConstants; import org.joda.time.Interval; import org.joda.time.LocalTime; public class Main { public static void main(String[] args) { Interval interval = betweenNowAndNext(DateTimeConstants.MONDAY, new LocalTime(10, 14)); System.out.println(interval.toDurationMillis()); } public static Interval betweenNowAndNext(int dayOfWeek, LocalTime time) { DateTime now = DateTime.now(); DateTime closest = time.toDateTime(now).withDayOfWeek(dayOfWeek); return new Interval(now, closest.isBefore(now) ? closest.plusWeeks(1) : closest); } }
this(from == null ? null : from.toDateTime(INSTANT), to == null ? null : to.toDateTime(INSTANT));
protected List<Shift> createShifts(ShiftDifferentialRule rule, LocalDateTime spanBegin, LocalDateTime spanEnd, DateTimeZone zone) { DateTime spanBeginDT = spanBegin.toDateTime(zone); DateTime spanEndDT = spanEnd.toDateTime(zone); Interval calendarEntryInterval = new Interval(spanBeginDT, spanEndDT); DateTime shiftEnd = LocalTime.fromDateFields(rule.getEndTime()).toDateTime(spanBeginDT).minusDays(1); DateTime shiftStart = LocalTime.fromDateFields(rule.getBeginTime()).toDateTime(spanBeginDT).minusDays(1); if (shiftEnd.isBefore(shiftStart) || shiftEnd.isEqual(shiftStart)) { shiftEnd = shiftEnd.plusDays(1); } List<Shift> shifts = new ArrayList<Shift>(); Interval shiftInterval = new Interval(shiftStart, shiftEnd); //possible that there is no overlap between 1st interval and cal entry interval... if so, add a day. if (!calendarEntryInterval.overlaps(shiftInterval)) { shiftInterval = incrementShift(shiftInterval); } while (calendarEntryInterval.overlaps(shiftInterval)) { if (ruleIsActiveForDay(shiftInterval.getStart(), rule)) { shifts.add(new Shift(rule, shiftInterval, zone)); } shiftInterval = incrementShift(shiftInterval); } return shifts; }
LocalTime ruleEnd = new LocalTime(rule.getEndTime()); DateTime beginShiftEnd = ruleEnd.toDateTime(calEntryBegin.minusDays(1)); DateTime beginShiftStart = ruleStart.toDateTime(calEntryBegin.minusDays(1)); DateTime endShiftEnd = ruleEnd.toDateTime(calEntryEnd); DateTime endShiftBegin = ruleStart.toDateTime(calEntryEnd);
@Override public Object getValue(Symbol symbol) { switch (symbol.getName().toLowerCase(ENGLISH)) { case "bound_long": return 1234L; case "bound_string": return utf8Slice("hello"); case "bound_double": return 12.34; case "bound_date": return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis(); case "bound_time": return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis(); case "bound_timestamp": return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis(); case "bound_pattern": return utf8Slice("%el%"); case "bound_timestamp_with_timezone": return new SqlTimestampWithTimeZone(new DateTime(1970, 1, 1, 1, 0, 0, 999, DateTimeZone.UTC).getMillis(), getTimeZoneKey("Z")); case "bound_varbinary": return Slices.wrappedBuffer((byte) 0xab); } return new QualifiedNameReference(symbol.toQualifiedName()); } });
} else if( comparisonValue instanceof org.joda.time.LocalTime ) { final Date date = ((org.joda.time.LocalTime) comparisonValue).toDateTime(new DateTime(0, DateTimeZone.UTC)).toDate(); odataExpr = new FilterExpression(fieldName, function, ODataType.of(date)); } else if( comparisonValue instanceof org.joda.time.LocalDateTime ) {
return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis(); case "bound_time": return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis(); case "bound_timestamp": return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis();
return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis(); case "bound_time": return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis(); case "bound_timestamp": return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis();