Java Code Examples for org.joda.time.ReadableDuration#getMillis()
The following examples show how to use
org.joda.time.ReadableDuration#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: TimeUtil.java From beam with Apache License 2.0 | 5 votes |
/** Converts a {@link ReadableDuration} into a Dataflow API duration string. */ public static String toCloudDuration(ReadableDuration duration) { // Note that since Joda objects use millisecond resolution, we always // produce either no fractional seconds or fractional seconds with // millisecond resolution. long millis = duration.getMillis(); long seconds = millis / 1000; millis = millis % 1000; if (millis == 0) { return String.format("%ds", seconds); } else { return String.format("%d.%03ds", seconds, millis); } }
Example 2
Source File: AbstractDuration.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Compares this duration with the specified duration based on length. * * @param other a duration 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 given object is not supported */ public int compareTo(ReadableDuration other) { long thisMillis = this.getMillis(); long otherMillis = other.getMillis(); // cannot do (thisMillis - otherMillis) as it can overflow if (thisMillis < otherMillis) { return -1; } if (thisMillis > otherMillis) { return 1; } return 0; }
Example 3
Source File: AbstractDuration.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Compares this object with the specified object for equality based * on the millisecond length. All ReadableDuration instances are accepted. * * @param duration a readable duration to check against * @return true if the length of the duration is equal */ public boolean equals(Object duration) { if (this == duration) { return true; } if (duration instanceof ReadableDuration == false) { return false; } ReadableDuration other = (ReadableDuration) duration; return (getMillis() == other.getMillis()); }
Example 4
Source File: AbstractDuration.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Compares this duration with the specified duration based on length. * * @param other a duration 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 given object is not supported */ public int compareTo(ReadableDuration other) { long thisMillis = this.getMillis(); long otherMillis = other.getMillis(); // cannot do (thisMillis - otherMillis) as it can overflow if (thisMillis < otherMillis) { return -1; } if (thisMillis > otherMillis) { return 1; } return 0; }
Example 5
Source File: AbstractDuration.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Compares this object with the specified object for equality based * on the millisecond length. All ReadableDuration instances are accepted. * * @param duration a readable duration to check against * @return true if the length of the duration is equal */ public boolean equals(Object duration) { if (this == duration) { return true; } if (duration instanceof ReadableDuration == false) { return false; } ReadableDuration other = (ReadableDuration) duration; return (getMillis() == other.getMillis()); }
Example 6
Source File: DurationCoder.java From beam with Apache License 2.0 | 4 votes |
private Long toLong(ReadableDuration value) { return value.getMillis(); }
Example 7
Source File: ReadableDurationConverter.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Extracts duration values from an object of this converter's type, and * sets them into the given ReadWritableDuration. * * @param writablePeriod period to get modified * @param object the object to convert, must not be null * @param chrono the chronology to use, must not be null * @throws NullPointerException if the duration or object is null * @throws ClassCastException if the object is an invalid type * @throws IllegalArgumentException if the object is invalid */ public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) { ReadableDuration dur = (ReadableDuration) object; chrono = DateTimeUtils.getChronology(chrono); long duration = dur.getMillis(); int[] values = chrono.get(writablePeriod, duration); for (int i = 0; i < values.length; i++) { writablePeriod.setValue(i, values[i]); } }
Example 8
Source File: ReadableDurationConverter.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Extracts duration values from an object of this converter's type, and * sets them into the given ReadWritableDuration. * * @param writablePeriod period to get modified * @param object the object to convert, must not be null * @param chrono the chronology to use, must not be null * @throws NullPointerException if the duration or object is null * @throws ClassCastException if the object is an invalid type * @throws IllegalArgumentException if the object is invalid */ public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) { ReadableDuration dur = (ReadableDuration) object; chrono = DateTimeUtils.getChronology(chrono); long duration = dur.getMillis(); int[] values = chrono.get(writablePeriod, duration); for (int i = 0; i < values.length; i++) { writablePeriod.setValue(i, values[i]); } }