List of usage examples for org.joda.time LocalDate toInterval
public Interval toInterval(DateTimeZone zone)
From source file:org.killbill.clock.ClockUtil.java
License:Apache License
/** * The method will convert the provided LocalDate into an instant (DateTime). * The conversion will use a reference time that should be interpreted from a UTC standpoint. * * The the provided LocalDate overlaps with the present, the current point in time is returned (to make sure we don't * end up with future instant).// www .j a v a2s . co m * * If not, we use both the provide LocalDate and LocalTime to return the DateTime in UTC * * @param inputDateInTargetTimeZone The input LocalDate as interpreted in the specified targetTimeZone * @param inputTimeInUTCTimeZone The referenceTime in UTC * @param targetTimeZone The target timeZone * @param clock The current clock * @return */ public static DateTime computeDateTimeWithUTCReferenceTime(final LocalDate inputDateInTargetTimeZone, final LocalTime inputTimeInUTCTimeZone, final DateTimeZone targetTimeZone, final Clock clock) { final Interval interval = inputDateInTargetTimeZone.toInterval(targetTimeZone); // If the input date overlaps with the present, we return NOW. if (interval.contains(clock.getUTCNow())) { return clock.getUTCNow(); } // If not, we convert the inputTimeInUTCTimeZone -> inputTimeInTargetTimeZone, compute the resulting DateTime in targetTimeZone, and convert into a UTC DateTime: final LocalTime inputTimeInTargetTimeZone = inputTimeInUTCTimeZone .plusMillis(targetTimeZone.getOffset(clock.getUTCNow())); final DateTime resultInTargetTimeZone = new DateTime(inputDateInTargetTimeZone.getYear(), inputDateInTargetTimeZone.getMonthOfYear(), inputDateInTargetTimeZone.getDayOfMonth(), inputTimeInTargetTimeZone.getHourOfDay(), inputTimeInTargetTimeZone.getMinuteOfHour(), inputTimeInTargetTimeZone.getSecondOfMinute(), targetTimeZone); return resultInTargetTimeZone.toDateTime(DateTimeZone.UTC); }