private static long minute(final LocalDateTime localDateTime) { return localDateTime.getMinuteOfHour(); } }
protected Calendar dateToCalendar(Date date, TimeZone offerTimeZone) { DateTimeZone offerDateTimeZone = DateTimeZone.forTimeZone(offerTimeZone); LocalDateTime offerDateTime = new LocalDateTime(date, offerDateTimeZone); Calendar calendar = new GregorianCalendar(offerTimeZone); calendar.set(Calendar.YEAR, offerDateTime.getYear()); calendar.set(Calendar.MONTH, offerDateTime.getMonthOfYear() - 1); calendar.set(Calendar.DAY_OF_MONTH, offerDateTime.getDayOfMonth()); calendar.set(Calendar.HOUR_OF_DAY, offerDateTime.getHourOfDay()); calendar.set(Calendar.MINUTE, offerDateTime.getMinuteOfHour()); calendar.set(Calendar.SECOND, offerDateTime.getSecondOfMinute()); calendar.get(Calendar.HOUR_OF_DAY);//do not delete this line calendar.get(Calendar.MINUTE); return calendar; }
/** * Get the date time as a <code>java.util.Date</code> using the specified time zone. * <p> * The <code>Date</code> object created has exactly the same fields as this * date-time, except when the time would be invalid due to a daylight savings * gap. In that case, the time will be set to the earliest valid time after the gap. * <p> * In the case of a daylight savings overlap, the earlier instant is selected. * <p> * Converting to a JDK Date is full of complications as the JDK Date constructor * doesn't behave as you might expect around DST transitions. This method works * by taking a first guess and then adjusting. This also handles the situation * where the JDK time zone data differs from the Joda-Time time zone data. * <p> * Unlike {@link #toDate()}, this implementation does not rely on Java's synchronized * time zone initialization logic, and should demonstrate better concurrent performance * characteristics. * * @return a Date initialised with this date-time, never null * @since 2.3 */ public Date toDate(final TimeZone timeZone) { final Calendar calendar = Calendar.getInstance(timeZone); calendar.clear(); calendar.set(getYear(), getMonthOfYear() - 1, getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute()); Date date = calendar.getTime(); date.setTime(date.getTime() + getMillisOfSecond()); return correctDstTransition(date, timeZone); }
/** * Get the date time as a <code>java.util.Date</code> using the specified time zone. * <p> * The <code>Date</code> object created has exactly the same fields as this * date-time, except when the time would be invalid due to a daylight savings * gap. In that case, the time will be set to the earliest valid time after the gap. * <p> * In the case of a daylight savings overlap, the earlier instant is selected. * <p> * Converting to a JDK Date is full of complications as the JDK Date constructor * doesn't behave as you might expect around DST transitions. This method works * by taking a first guess and then adjusting. This also handles the situation * where the JDK time zone data differs from the Joda-Time time zone data. * <p> * Unlike {@link #toDate()}, this implementation does not rely on Java's synchronized * time zone initialization logic, and should demonstrate better concurrent performance * characteristics. * * @return a Date initialised with this date-time, never null * @since 2.3 */ public Date toDate(final TimeZone timeZone) { final Calendar calendar = Calendar.getInstance(timeZone); calendar.clear(); calendar.set(getYear(), getMonthOfYear() - 1, getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute()); Date date = calendar.getTime(); date.setTime(date.getTime() + getMillisOfSecond()); return correctDstTransition(date, timeZone); }
/** * Get the date time as a <code>java.util.Date</code>. * <p> * The <code>Date</code> object created has exactly the same fields as this * date-time, except when the time would be invalid due to a daylight savings * gap. In that case, the time will be set to the earliest valid time after the gap. * <p> * In the case of a daylight savings overlap, the earlier instant is selected. * <p> * Converting to a JDK Date is full of complications as the JDK Date constructor * doesn't behave as you might expect around DST transitions. This method works * by taking a first guess and then adjusting. This also handles the situation * where the JDK time zone data differs from the Joda-Time time zone data. * * @return a Date initialised with this date-time, never null * @since 2.0 */ @SuppressWarnings("deprecation") public Date toDate() { int dom = getDayOfMonth(); Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom, getHourOfDay(), getMinuteOfHour(), getSecondOfMinute()); date.setTime(date.getTime() + getMillisOfSecond()); return correctDstTransition(date, TimeZone.getDefault()); }
/** * Get the date time as a <code>java.util.Date</code>. * <p> * The <code>Date</code> object created has exactly the same fields as this * date-time, except when the time would be invalid due to a daylight savings * gap. In that case, the time will be set to the earliest valid time after the gap. * <p> * In the case of a daylight savings overlap, the earlier instant is selected. * <p> * Converting to a JDK Date is full of complications as the JDK Date constructor * doesn't behave as you might expect around DST transitions. This method works * by taking a first guess and then adjusting. This also handles the situation * where the JDK time zone data differs from the Joda-Time time zone data. * * @return a Date initialised with this date-time, never null * @since 2.0 */ @SuppressWarnings("deprecation") public Date toDate() { int dom = getDayOfMonth(); Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom, getHourOfDay(), getMinuteOfHour(), getSecondOfMinute()); date.setTime(date.getTime() + getMillisOfSecond()); return correctDstTransition(date, TimeZone.getDefault()); }
/** * Converts this object to a DateTime using the specified zone. * <p> * When the time zone is applied, the local date-time may be affected by daylight saving. * In a daylight saving gap, when the local time does not exist, * this method will throw an exception. * In a daylight saving overlap, when the same local time occurs twice, * this method returns the first occurrence of the local time. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis * @throws IllegalInstantException if the local time does not exist when the time zone is applied */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = iChronology.withZone(zone); return new DateTime( getYear(), getMonthOfYear(), getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute(), getMillisOfSecond(), chrono); }
/** * Converts this object to a DateTime using the specified zone. * <p> * When the time zone is applied, the local date-time may be affected by daylight saving. * In a daylight saving gap, when the local time does not exist, * this method will throw an exception. * In a daylight saving overlap, when the same local time occurs twice, * this method returns the first occurrence of the local time. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis * @throws IllegalInstantException if the local time does not exist when the time zone is applied */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = iChronology.withZone(zone); return new DateTime( getYear(), getMonthOfYear(), getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute(), getMillisOfSecond(), chrono); }
int dom = getDayOfMonth(); Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom, getHourOfDay(), getMinuteOfHour(), getSecondOfMinute()); date.setTime(date.getTime() + getMillisOfSecond()); LocalDateTime check = LocalDateTime.fromDateFields(date);
/** * Converts this object to a DateTime using the specified zone. * <p> * This method will throw an exception if the datetime that would be * created does not exist when the time zone is taken into account. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = iChronology.withZone(zone); return new DateTime( getYear(), getMonthOfYear(), getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute(), getMillisOfSecond(), chrono); }
/** * Returns true if both datetime are in the same year, month, day of month, hour and minute, false otherwise. * * @param actual the actual datetime. expected not be null * @param other the other datetime. expected not be null * @return true if both datetime are in the same year, month, day of month, hour and minute, false otherwise. */ private static boolean areEqualIgnoringSeconds(LocalDateTime actual, LocalDateTime other) { return areEqualIgnoringMinutes(actual, other) && actual.getMinuteOfHour() == other.getMinuteOfHour(); }
Date toQuaterOfHour(Date date) { LocalDateTime ldt = new LocalDateTime(date.getTime()); int quater = ldt.getMinuteOfHour() / 15; return ldt.withMinuteOfHour(quater * 15).toDate(); }
public TimePrintMillis(LocalDateTime time) { super(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute()); millisOfSecond = time.getMillisOfSecond(); }
@Override public java.time.LocalDateTime convert(LocalDateTime in, Context context) throws Exception { if (in == null) return null; return java.time.LocalDateTime.of(in.getYear(), in.getMonthOfYear(), in.getDayOfMonth(), in.getHourOfDay(), in.getMinuteOfHour(), in.getSecondOfMinute(), in.getMillisOfSecond() * 1000); } }
@Override public void setup() { int timeZoneIndex = contextInfo.getRootFragmentTimeZone(); org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.arrow.vector.util.DateUtility.getTimeZone(timeZoneIndex)); org.joda.time.LocalDateTime now = new org.joda.time.LocalDateTime(contextInfo.getQueryStartTime(), timeZone); queryStartTime= (now.getHourOfDay() * org.apache.arrow.vector.util.DateUtility.hoursToMillis) + (now.getMinuteOfHour() * org.apache.arrow.vector.util.DateUtility.minutesToMillis) + (now.getSecondOfMinute() * org.apache.arrow.vector.util.DateUtility.secondsToMillis) + (now.getMillisOfSecond()); }
@Override public void setup() { org.joda.time.LocalDateTime now = new org.joda.time.LocalDateTime(contextInfo.getQueryStartTime(), org.joda.time.DateTimeZone.UTC); queryStartTime= (now.getHourOfDay() * org.apache.arrow.vector.util.DateUtility.hoursToMillis) + (now.getMinuteOfHour() * org.apache.arrow.vector.util.DateUtility.minutesToMillis) + (now.getSecondOfMinute() * org.apache.arrow.vector.util.DateUtility.secondsToMillis) + (now.getMillisOfSecond()); }
@Override public Timestamp getTimestamp(int index) { if (ac.isNull(index)) { return null; } org.joda.time.LocalDateTime date = new org.joda.time.LocalDateTime(ac.get(index), org.joda.time.DateTimeZone.UTC); return new Timestamp(date.getYear() - 1900, date.getMonthOfYear() - 1, date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(), (int) java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(date.getMillisOfSecond())); }
/** * Converts this object to a DateTime using the specified zone. * <p> * This method will throw an exception if the datetime that would be * created does not exist when the time zone is taken into account. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = iChronology.withZone(zone); return new DateTime( getYear(), getMonthOfYear(), getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute(), getMillisOfSecond(), chrono); }
/** * Converts this object to a DateTime using the specified zone. * <p> * This method will throw an exception if the datetime that would be * created does not exist when the time zone is taken into account. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = iChronology.withZone(zone); return new DateTime( getYear(), getMonthOfYear(), getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute(), getMillisOfSecond(), chrono); }
@Override public RexNode convertCall(SqlRexContext cx, SqlCall call) { final int timeZoneIndex = getContextInformation().getRootFragmentTimeZone(); final DateTimeZone timeZone = DateTimeZone.forID(DateUtility.getTimeZone(timeZoneIndex)); final LocalDateTime dateTime = new LocalDateTime(getContextInformation().getQueryStartTime(), timeZone); final long queryStartTime = (dateTime.getHourOfDay() * DateUtility.hoursToMillis) + (dateTime.getMinuteOfHour() * DateUtility.minutesToMillis) + (dateTime.getSecondOfMinute() * DateUtility.secondsToMillis) + (dateTime.getMillisOfSecond()); return cx.getRexBuilder() .makeTimeLiteral( DateTimes.toDateTime(new LocalDateTime(queryStartTime, DateTimeZone.UTC)) .toCalendar(null), // null sets locale to default locale getReturnTypePrecision(cx, call)); } }