/** * Uses the specified formatter to convert this partial to a String. * * @param formatter the formatter to use, null means use <code>toString()</code>. * @return the formatted string, not null * @since 1.1 */ public String toString(DateTimeFormatter formatter) { if (formatter == null) { return toString(); } return formatter.print(this); }
/** * Gets a hash code for the instant as defined in <code>ReadableInstant</code>. * * @return a suitable hash code */ public int hashCode() { // must be to fulfil ReadableInstant contract return ((int) (getMillis() ^ (getMillis() >>> 32))) + (getChronology().hashCode()); }
/** * Is this instant strictly after the current instant * comparing solely by millisecond. * * @return true if this instant is strictly after the current instant */ public boolean isAfterNow() { return isAfter(DateTimeUtils.currentTimeMillis()); }
/** * Is this instant strictly before the current instant * comparing solely by millisecond. * * @return true if this instant is strictly before the current instant */ public boolean isBeforeNow() { return isBefore(DateTimeUtils.currentTimeMillis()); }
/** * Is this instant equal to the current instant * comparing solely by millisecond. * * @return true if this instant is equal to the current instant */ public boolean isEqualNow() { return isEqual(DateTimeUtils.currentTimeMillis()); }
/** * Is this instant equal to the millisecond instant passed in * comparing solely by millisecond. * * @param instant a millisecond instant to check against * @return true if this instant is equal to the instant passed in */ public boolean isEqual(long instant) { return (getMillis() == instant); }
/** * helper function to create the timer * * @param instant the point in time when the code should be executed * @param closure string for job id * @param dataMap job data map, preconfigured with arguments * @return */ private static Timer makeTimer(AbstractInstant instant, String closure, JobDataMap dataMap) { Logger logger = LoggerFactory.getLogger(ScriptExecution.class); JobKey jobKey = new JobKey(instant.toString() + ": " + closure.toString()); Trigger trigger = newTrigger().startAt(instant.toDate()).build(); Timer timer = new TimerImpl(jobKey, trigger.getKey(), dataMap, instant); try { JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build(); if (TimerImpl.scheduler.checkExists(job.getKey())) { TimerImpl.scheduler.deleteJob(job.getKey()); logger.debug("Deleted existing Job {}", job.getKey().toString()); } TimerImpl.scheduler.scheduleJob(job, trigger); logger.debug("Scheduled code for execution at {}", instant.toString()); return timer; } catch (SchedulerException e) { logger.error("Failed to schedule code for execution.", e); return null; } } }
/** * Gets the time zone of the instant from the chronology. * * @return the DateTimeZone that the instant is using, never null */ public DateTimeZone getZone() { return getChronology().getZone(); }
/** * Set a list of positional parameters on a query. * <p> * Values of type {@link java.util.Date} and {@link org.joda.time.base.AbstractInstant} * are recognized and set as a timestamp ({@link javax.persistence.TemporalType#TIMESTAMP}. */ public static <A extends Query> A setParams(A q, Object... params) { for (int i = 0; i < params.length; i++) { final Object value = params[i]; if (value instanceof Date) { q.setParameter(i + 1, (Date) value, TemporalType.TIMESTAMP); } if (value instanceof AbstractInstant) { q.setParameter(i + 1, ((AbstractInstant) value).toDate(), TemporalType.TIMESTAMP); } else { q.setParameter(i + 1, value); } } return q; }
/** * Is this instant strictly after the instant passed in * comparing solely by millisecond. * * @param instant an instant to check against, null means now * @return true if the instant is strictly after the instant passed in */ public boolean isAfter(ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); return isAfter(instantMillis); }
/** * Is this instant strictly before the instant passed in * comparing solely by millisecond. * * @param instant an instant to check against, null means now * @return true if the instant is strictly before the instant passed in */ public boolean isBefore(ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); return isBefore(instantMillis); }
/** * Is this instant equal to the instant passed in * comparing solely by millisecond. * * @param instant an instant to check against, null means now * @return true if the instant is equal to the instant passed in */ public boolean isEqual(ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); return isEqual(instantMillis); }
/** * Is this instant strictly after the millisecond instant passed in * comparing solely by millisecond. * * @param instant a millisecond instant to check against * @return true if this instant is strictly after the instant passed in */ public boolean isAfter(long instant) { return (getMillis() > instant); }
/** * Gets the time zone of the instant from the chronology. * * @return the DateTimeZone that the instant is using, never null */ public DateTimeZone getZone() { return getChronology().getZone(); }
/** * Set a list of positional parameters on a query. * * Values of type {@link java.util.Date} and {@link org.joda.time.base.AbstractInstant} * are recognized and set as a timestamp ({@link javax.persistence.TemporalType#TIMESTAMP}. */ public static <A extends Query> A setParams(A q, Object... params) { for (int i = 0; i < params.length; i++) { final Object value = params[i]; if (value instanceof Date) { q.setParameter(i + 1, (Date) value, TemporalType.TIMESTAMP); } if (value instanceof AbstractInstant) { q.setParameter(i + 1, ((AbstractInstant) value).toDate(), TemporalType.TIMESTAMP); } else { q.setParameter(i + 1, value); } } return q; }
/** * Gets a hash code for the instant as defined in <code>ReadableInstant</code>. * * @return a suitable hash code */ public int hashCode() { // must be to fulfil ReadableInstant contract return ((int) (getMillis() ^ (getMillis() >>> 32))) + (getChronology().hashCode()); }
/** * Uses the specified formatter to convert this partial to a String. * * @param formatter the formatter to use, null means use <code>toString()</code>. * @return the formatted string, not null * @since 1.1 */ public String toString(DateTimeFormatter formatter) { if (formatter == null) { return toString(); } return formatter.print(this); }
/** * Is this instant strictly after the current instant * comparing solely by millisecond. * * @return true if this instant is strictly after the current instant */ public boolean isAfterNow() { return isAfter(DateTimeUtils.currentTimeMillis()); }