Java Code Examples for org.joda.time.ReadableInstant#getMillis()

The following examples show how to use org.joda.time.ReadableInstant#getMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractInstant.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 other  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(ReadableInstant other) {
    if (this == other) {
        return 0;
    }
    
    long otherMillis = other.getMillis();
    long thisMillis = getMillis();
    
    // cannot do (thisMillis - otherMillis) as can overflow
    if (thisMillis == otherMillis) {
        return 0;
    }
    if (thisMillis < otherMillis) {
        return -1;
    } else {
        return 1;
    }
}
 
Example 2
Source File: AbstractInstant.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 other  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(ReadableInstant other) {
    if (this == other) {
        return 0;
    }
    
    long otherMillis = other.getMillis();
    long thisMillis = getMillis();
    
    // cannot do (thisMillis - otherMillis) as can overflow
    if (thisMillis == otherMillis) {
        return 0;
    }
    if (thisMillis < otherMillis) {
        return -1;
    } else {
        return 1;
    }
}
 
Example 3
Source File: FakeClock.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a FakeClock instance initialized to the given time.
 */
public FakeClock(ReadableInstant now) {
  baseTimeMs = now.getMillis();
  fakeNowMs = new AtomicLong(baseTimeMs);
}
 
Example 4
Source File: AbstractInstant.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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());
}
 
Example 5
Source File: AbstractInstant.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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());
}