@Nonnull private static Calendar _createCalendarTime (final Date dateTime) { final Calendar cal = PDTFactory.createCalendar (); cal.setTime (dateTime); return cal; }
public static Date futureDate (final int interval, final EIntervalUnit unit) { final Calendar c = PDTFactory.createCalendar (); c.setTime (new Date ()); c.setLenient (true); c.add (_translate (unit), interval); return c.getTime (); }
/** * Return a date with time of day reset to this object values. The millisecond * value will be zero. */ @Nullable public Date getTimeOfDayForDate (final Date dateTime) { if (dateTime == null) return null; final Calendar cal = PDTFactory.createCalendar (); cal.setTime (dateTime); cal.set (Calendar.HOUR_OF_DAY, m_nHour); cal.set (Calendar.MINUTE, m_nMinute); cal.set (Calendar.SECOND, m_nSecond); cal.clear (Calendar.MILLISECOND); return cal.getTime (); }
/** * <p> * Returns a date that is rounded to the previous even second below the given * date. * </p> * <p> * For example an input date with a time of 08:13:54.341 would result in a * date with the time of 08:13:54.000. * </p> * * @param date * the Date to round, if <code>null</code> the current time will be * used * @return the new rounded date */ public static Date evenSecondDateBefore (final Date date) { final Calendar c = PDTFactory.createCalendar (); c.setTime (date != null ? date : new Date ()); c.set (Calendar.MILLISECOND, 0); return c.getTime (); }
/** * <p> * Returns a date that is rounded to the next even second above the given * date. * </p> * * @param date * the Date to round, if <code>null</code> the current time will be * used * @return the new rounded date */ public static Date evenSecondDate (final Date date) { final Calendar c = PDTFactory.createCalendar (); c.setTime (date != null ? date : new Date ()); c.setLenient (true); c.set (Calendar.SECOND, c.get (Calendar.SECOND) + 1); c.set (Calendar.MILLISECOND, 0); return c.getTime (); }
/** * <p> * Returns a date that is rounded to the previous even minute below the given * date. * </p> * <p> * For example an input date with a time of 08:13:54 would result in a date * with the time of 08:13:00. * </p> * * @param date * the Date to round, if <code>null</code> the current time will be * used * @return the new rounded date */ public static Date evenMinuteDateBefore (final Date date) { final Calendar c = PDTFactory.createCalendar (); c.setTime (date != null ? date : new Date ()); c.set (Calendar.SECOND, 0); c.set (Calendar.MILLISECOND, 0); return c.getTime (); }
/** * Create a {@link TimeOfDay} from the given date, in the given TimeZone. * * @param dateTime * The {@link Date} from which to extract Hour, Minute and Second. * @param tz * The {@link TimeZone} from which relate Hour, Minute and Second for * the given date. If null, system default TimeZone will be used. */ @Nullable public static TimeOfDay hourAndMinuteAndSecondFromDate (@Nullable final Date dateTime, @Nullable final TimeZone tz) { if (dateTime == null) return null; final Calendar cal = PDTFactory.createCalendar (); cal.setTime (dateTime); if (tz != null) cal.setTimeZone (tz); return new TimeOfDay (cal.get (Calendar.HOUR_OF_DAY), cal.get (Calendar.MINUTE), cal.get (Calendar.SECOND)); }
/** * <p> * Returns a date that is rounded to the next even hour above the given date. * </p> * <p> * For example an input date with a time of 08:13:54 would result in a date * with the time of 09:00:00. If the date's time is in the 23rd hour, the * date's 'day' will be promoted, and the time will be set to 00:00:00. * </p> * * @param date * the Date to round, if <code>null</code> the current time will be * used * @return the new rounded date */ public static Date evenHourDate (final Date date) { final Calendar c = PDTFactory.createCalendar (); c.setTime (date != null ? date : new Date ()); c.setLenient (true); c.set (Calendar.HOUR_OF_DAY, c.get (Calendar.HOUR_OF_DAY) + 1); c.set (Calendar.MINUTE, 0); c.set (Calendar.SECOND, 0); c.set (Calendar.MILLISECOND, 0); return c.getTime (); }
/** * <p> * Returns a date that is rounded to the previous even hour below the given * date. * </p> * <p> * For example an input date with a time of 08:13:54 would result in a date * with the time of 08:00:00. * </p> * * @param date * the Date to round, if <code>null</code> the current time will be * used * @return the new rounded date */ public static Date evenHourDateBefore (final Date date) { final Calendar c = PDTFactory.createCalendar (); c.setTime (date != null ? date : new Date ()); c.set (Calendar.MINUTE, 0); c.set (Calendar.SECOND, 0); c.set (Calendar.MILLISECOND, 0); return c.getTime (); }
/** * <p> * Returns a date that is rounded to the next even minute above the given * date. * </p> * <p> * For example an input date with a time of 08:13:54 would result in a date * with the time of 08:14:00. If the date's time is in the 59th minute, then * the hour (and possibly the day) will be promoted. * </p> * * @param date * the Date to round, if <code>null</code> the current time will be * used * @return the new rounded date */ public static Date evenMinuteDate (final Date date) { final Calendar c = PDTFactory.createCalendar (); c.setTime (date != null ? date : new Date ()); c.setLenient (true); c.set (Calendar.MINUTE, c.get (Calendar.MINUTE) + 1); c.set (Calendar.SECOND, 0); c.set (Calendar.MILLISECOND, 0); return c.getTime (); }
/** * Build the Date defined by this builder instance. */ @Nonnull public Date build () { Calendar cal; if (m_aTZ != null && m_aLocale != null) cal = Calendar.getInstance (m_aTZ, m_aLocale); else if (m_aTZ != null) cal = Calendar.getInstance (m_aTZ, Locale.getDefault (Locale.Category.FORMAT)); else if (m_aLocale != null) cal = Calendar.getInstance (TimeZone.getDefault (), m_aLocale); else cal = PDTFactory.createCalendar (); cal.set (Calendar.YEAR, year); cal.set (Calendar.MONTH, month - 1); cal.set (Calendar.DAY_OF_MONTH, day); cal.set (Calendar.HOUR_OF_DAY, hour); cal.set (Calendar.MINUTE, minute); cal.set (Calendar.SECOND, second); cal.set (Calendar.MILLISECOND, 0); return cal.getTime (); }
/** * Create a {@link TimeOfDay} from the given date (at the zero-second), in the * system default TimeZone. * * @param dateTime * The {@link Date} from which to extract Hour and Minute. * @param tz * The {@link TimeZone} from which relate Hour and Minute for the given * date. If null, system default TimeZone will be used. */ @Nullable public static TimeOfDay hourAndMinuteFromDate (@Nullable final Date dateTime, @Nullable final TimeZone tz) { if (dateTime == null) return null; final Calendar cal = PDTFactory.createCalendar (); cal.setTime (dateTime); if (tz != null) cal.setTimeZone (tz); return new TimeOfDay (cal.get (Calendar.HOUR_OF_DAY), cal.get (Calendar.MINUTE), 0); } }
@Override public final void setStartTime (@Nonnull final Date startTime) { ValueEnforcer.notNull (startTime, "StartTime"); final Date eTime = getEndTime (); if (eTime != null && eTime.before (startTime)) { throw new IllegalArgumentException ("End time cannot be before start time"); } // round off millisecond... // Note timeZone is not needed here as parameter for // Calendar.getInstance(), // since time zone is implicit when using a Date in the setTime method. final Calendar cl = PDTFactory.createCalendar (); cl.setTime (startTime); cl.set (Calendar.MILLISECOND, 0); this.m_aStartTime = cl.getTime (); }
/** * <p> * Get a <code>Date</code> object that represents the given time, on today's * date (equivalent to {@link #todayAt(int, int, int)}). * </p> * * @param second * The value (0-59) to give the seconds field of the date * @param minute * The value (0-59) to give the minutes field of the date * @param hour * The value (0-23) to give the hours field of the date * @return the new date */ public static Date dateOf (final int hour, final int minute, final int second) { validateSecond (second); validateMinute (minute); validateHour (hour); final Date date = new Date (); final Calendar c = PDTFactory.createCalendar (); c.setTime (date); c.setLenient (true); c.set (Calendar.HOUR_OF_DAY, hour); c.set (Calendar.MINUTE, minute); c.set (Calendar.SECOND, second); c.set (Calendar.MILLISECOND, 0); return c.getTime (); }
final Calendar c = PDTFactory.createCalendar (); c.setTime (date); c.setLenient (true);
/** * <p> * Called when the <code>{@link IScheduler}</code> has decided to 'fire' the * trigger (execute the associated <code>Job</code>), in order to give the * <code>Trigger</code> a chance to update itself for its next triggering (if * any). * </p> * * @see #executionComplete(IJobExecutionContext, JobExecutionException) */ @Override public void triggered (final ICalendar calendar) { m_nTimesTriggered++; m_aPreviousFireTime = m_aNextFireTime; m_aNextFireTime = getFireTimeAfter (m_aNextFireTime); while (m_aNextFireTime != null && calendar != null && !calendar.isTimeIncluded (m_aNextFireTime.getTime ())) { m_aNextFireTime = getFireTimeAfter (m_aNextFireTime); if (m_aNextFireTime == null) break; // avoid infinite loop final Calendar c = PDTFactory.createCalendar (); c.setTime (m_aNextFireTime); if (c.get (Calendar.YEAR) > CQuartz.MAX_YEAR) { m_aNextFireTime = null; } } }
final Calendar c = PDTFactory.createCalendar (); c.setTime (m_aNextFireTime); if (c.get (Calendar.YEAR) > CQuartz.MAX_YEAR)
final Calendar c = PDTFactory.createCalendar (); c.setTime (m_aNextFireTime); if (c.get (Calendar.YEAR) > CQuartz.MAX_YEAR)
final Calendar c = PDTFactory.createCalendar (); c.setTime (m_aNextFireTime); if (c.get (Calendar.YEAR) > CQuartz.MAX_YEAR)
final Calendar c = PDTFactory.createCalendar (); c.setTime (m_aNextFireTime); if (c.get (Calendar.YEAR) > CQuartz.MAX_YEAR)