コード例 #1
0
 @Test
 public void stoppedAtWithMillisWorks() throws Exception {
   ReadableInstant instant = new DateMidnight(2012, 3, 18);
   assertEquals(instant.getMillis(), JodaClocks.stoppedAt(instant.getMillis()).nowInMillis());
   assertEquals(
       instant.getMillis(), JodaClocks.stoppedAt(instant.getMillis()).nowAsDateTime().getMillis());
 }
コード例 #2
0
 public boolean isValidAt(ReadableInstant instant) {
   if (instant == null) {
     return !isClosed();
   } else {
     return (notValidBefore == null || !instant.isBefore(getNotValidBefore()))
         && (notValidAfter == null || !instant.isAfter(getNotValidAfter()));
   }
 }
コード例 #3
0
 /**
  * Compares this object with the specified object for equality based on the millisecond instant,
  * chronology and time zone.
  *
  * <p>Two objects which represent the same instant in time, but are in different time zones (based
  * on time zone id), will be considered to be different. Only two objects with the same {@link
  * DateTimeZone}, {@link Chronology} and instant are equal.
  *
  * <p>See {@link #isEqual(ReadableInstant)} for an equals method that ignores the Chronology and
  * time zone.
  *
  * <p>All ReadableInstant instances are accepted.
  *
  * @param readableInstant a readable instant to check against
  * @return true if millisecond and chronology are equal, false if not or the instant is null or of
  *     an incorrect type
  */
 public boolean equals(Object readableInstant) {
   // must be to fulfil ReadableInstant contract
   if (this == readableInstant) {
     return true;
   }
   if (readableInstant instanceof ReadableInstant == false) {
     return false;
   }
   ReadableInstant otherInstant = (ReadableInstant) readableInstant;
   return getMillis() == otherInstant.getMillis()
       && FieldUtils.equals(getChronology(), otherInstant.getChronology());
 }
コード例 #4
0
 public ValidityPeriod(ReadableInstant notValidBefore, ReadableInstant notValidAfter) {
   this.notValidBefore =
       (notValidBefore == null)
           ? null
           : new DateTime(truncatedMillis(notValidBefore.getMillis()), DateTimeZone.UTC);
   this.notValidAfter =
       (notValidAfter == null)
           ? null
           : new DateTime(truncatedMillis(notValidAfter.getMillis()), DateTimeZone.UTC);
   Validate.isTrue(
       isDateOrderingValid(this.notValidBefore, this.notValidAfter),
       "Got an invalid validatity time from: " + notValidBefore + " to: " + notValidAfter);
 }
コード例 #5
0
  /**
   * Compares this object with the specified object for ascending millisecond instant order. This
   * ordering is inconsistent with equals, as it ignores the Chronology.
   *
   * <p>All ReadableInstant instances are accepted.
   *
   * @param instant a readable instant to check against
   * @return negative value if this is less, 0 if equal, or positive value if greater
   * @throws NullPointerException if the object is null
   * @throws ClassCastException if the object type is not supported
   */
  public int compareTo(Object instant) {
    if (this == instant) {
      return 0;
    }

    ReadableInstant otherInstant = (ReadableInstant) instant;

    long otherMillis = otherInstant.getMillis();
    long thisMillis = getMillis();

    // cannot do (thisMillis - otherMillis) as can overflow
    if (thisMillis == otherMillis) {
      return 0;
    }
    if (thisMillis < otherMillis) {
      return -1;
    } else {
      return 1;
    }
  }
コード例 #6
0
ファイル: Dates.java プロジェクト: tl121/multibit-hd
 /**
  * Get the number of seconds since epoch for the given instant
  *
  * @param then The instant
  * @return the number of seconds since the epoch
  */
 public static long thenInSeconds(ReadableInstant then) {
   return (long) (then.getMillis() * 0.001);
 }
コード例 #7
0
 @Test
 public void startingInWithDurationWorks() throws Exception {
   ReadableInstant instant = new DateMidnight(2012, 3, 18);
   long offset = instant.getMillis() - System.currentTimeMillis();
   testRunningClock(JodaClocks.startingIn(new Duration(offset)), instant.getMillis());
 }
コード例 #8
0
 @Test
 public void startingAtWithInstantWorks() throws Exception {
   ReadableInstant instant = new DateMidnight(2012, 3, 18);
   testRunningClock(JodaClocks.startingAt(instant), instant.getMillis());
 }
コード例 #9
0
 public boolean isExpiredAt(ReadableInstant instant) {
   return notValidAfter != null && instant.isAfter(getNotValidAfter());
 }
コード例 #10
0
 /**
  * Is this time interval after the specified instant.
  *
  * <p>Intervals are inclusive of the start instant and exclusive of the end.
  *
  * @param instant the instant to compare to, null means now
  * @return true if this time interval is after the instant
  */
 public boolean isAfter(ReadableInstant instant) {
   if (instant == null) {
     return isAfterNow();
   }
   return isAfter(instant.getMillis());
 }
コード例 #11
0
 /**
  * Is this time interval before the specified instant.
  *
  * <p>Intervals are inclusive of the start instant and exclusive of the end.
  *
  * @param instant the instant to compare to, null means now
  * @return true if this time interval is before the instant
  */
 public boolean isBefore(ReadableInstant instant) {
   if (instant == null) {
     return isBeforeNow();
   }
   return isBefore(instant.getMillis());
 }
コード例 #12
0
 /**
  * Does this time interval contain the specified instant.
  *
  * <p>Non-zero duration intervals are inclusive of the start instant and exclusive of the end. A
  * zero duration interval cannot contain anything.
  *
  * <p>For example:
  *
  * <pre>
  * [09:00 to 10:00) contains 08:59  = false (before start)
  * [09:00 to 10:00) contains 09:00  = true
  * [09:00 to 10:00) contains 09:59  = true
  * [09:00 to 10:00) contains 10:00  = false (equals end)
  * [09:00 to 10:00) contains 10:01  = false (after end)
  *
  * [14:00 to 14:00) contains 14:00  = false (zero duration contains nothing)
  * </pre>
  *
  * Passing in a <code>null</code> parameter will have the same effect as calling {@link
  * #containsNow()}.
  *
  * @param instant the instant, null means now
  * @return true if this time interval contains the instant
  */
 public boolean contains(ReadableInstant instant) {
   if (instant == null) {
     return containsNow();
   }
   return contains(instant.getMillis());
 }
コード例 #13
0
 @Override
 public String asCassandraValue(final DateTime value) {
   final ReadableInstant utcDateTime = new DateTime(value, DateTimeZone.UTC);
   return utcDateTime.toString();
 }