/** * Creates a <code>Minutes</code> representing the number of whole minutes * between the two specified datetimes. * * @param start the start instant, must not be null * @param end the end instant, must not be null * @return the period in minutes * @throws IllegalArgumentException if the instants are null or invalid */ public static Minutes minutesBetween(ReadableInstant start, ReadableInstant end) { int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.minutes()); return Minutes.minutes(amount); }
/** * Gets the value of a duration field represented by this period. * <p> * If the field type specified does not match the type used by this class * then zero is returned. * * @param type the field type to query, null returns zero * @return the value of that field, zero if field not supported */ public int get(DurationFieldType type) { if (type == getFieldType()) { return getValue(); } return 0; }
/** * Compares this object with the specified object for equality based on the * value of each field. All ReadablePeriod instances are accepted, but only * those with a matching <code>PeriodType</code> can return true. * * @param period a readable period to check against * @return true if all the field values are equal, false if * not or the period is null or of an incorrect type */ public boolean equals(Object period) { if (this == period) { return true; } if (period instanceof ReadablePeriod == false) { return false; } ReadablePeriod other = (ReadablePeriod) period; return (other.getPeriodType() == getPeriodType() && other.getValue(0) == getValue()); }
/** * Creates a new <code>Weeks</code> representing the number of complete * standard length weeks in the specified period. * <p> * This factory method converts all fields from the period to hours using standardised * durations for each field. Only those fields which have a precise duration in * the ISO UTC chronology can be converted. * <ul> * <li>One week consists of 7 days. * <li>One day consists of 24 hours. * <li>One hour consists of 60 minutes. * <li>One minute consists of 60 weeks. * <li>One second consists of 1000 milliseconds. * </ul> * Months and Years are imprecise and periods containing these values cannot be converted. * * @param period the period to get the number of hours from, null returns zero * @return the period in weeks * @throws IllegalArgumentException if the period contains imprecise duration values */ public static Weeks standardWeeksIn(ReadablePeriod period) { int amount = BaseSingleFieldPeriod.standardPeriodIn(period, DateTimeConstants.MILLIS_PER_WEEK); return Weeks.weeks(amount); }
/** * Checks whether the duration field specified is supported by this period. * * @param type the type to check, may be null which returns false * @return true if the field is supported */ public boolean isSupported(DurationFieldType type) { return (type == getFieldType()); }
/** * Gets the value at the specified index. * <p> * The only index supported by this period is zero. * * @param index the index to retrieve, which must be zero * @return the value of the field at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public int getValue(int index) { if (index != 0) { throw new IndexOutOfBoundsException(String.valueOf(index)); } return getValue(); }
/** * Creates a new <code>Hours</code> representing the number of complete * standard length hours in the specified period. * <p> * This factory method converts all fields from the period to hours using standardised * durations for each field. Only those fields which have a precise duration in * the ISO UTC chronology can be converted. * <ul> * <li>One week consists of 7 days. * <li>One day consists of 24 hours. * <li>One hour consists of 60 minutes. * <li>One minute consists of 60 seconds. * <li>One second consists of 1000 milliseconds. * </ul> * Months and Years are imprecise and periods containing these values cannot be converted. * * @param period the period to get the number of hours from, null returns zero * @return the period in hours * @throws IllegalArgumentException if the period contains imprecise duration values */ public static Hours standardHoursIn(ReadablePeriod period) { int amount = BaseSingleFieldPeriod.standardPeriodIn(period, DateTimeConstants.MILLIS_PER_HOUR); return Hours.hours(amount); }
/** * Checks whether the duration field specified is supported by this period. * * @param type the type to check, may be null which returns false * @return true if the field is supported */ public boolean isSupported(DurationFieldType type) { return (type == getFieldType()); }
/** * Gets the value at the specified index. * <p> * The only index supported by this period is zero. * * @param index the index to retrieve, which must be zero * @return the value of the field at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public int getValue(int index) { if (index != 0) { throw new IndexOutOfBoundsException(String.valueOf(index)); } return getValue(); }
/** * Gets the value of a duration field represented by this period. * <p> * If the field type specified does not match the type used by this class * then zero is returned. * * @param type the field type to query, null returns zero * @return the value of that field, zero if field not supported */ public int get(DurationFieldType type) { if (type == getFieldType()) { return getValue(); } return 0; }
/** * Creates a <code>Seconds</code> representing the number of whole seconds * between the two specified datetimes. * * @param start the start instant, must not be null * @param end the end instant, must not be null * @return the period in seconds * @throws IllegalArgumentException if the instants are null or invalid */ public static Seconds secondsBetween(ReadableInstant start, ReadableInstant end) { int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.seconds()); return Seconds.seconds(amount); }
/** * Creates a new <code>Days</code> representing the number of complete * standard length days in the specified period. * <p> * This factory method converts all fields from the period to hours using standardised * durations for each field. Only those fields which have a precise duration in * the ISO UTC chronology can be converted. * <ul> * <li>One week consists of 7 days. * <li>One day consists of 24 hours. * <li>One hour consists of 60 minutes. * <li>One minute consists of 60 seconds. * <li>One second consists of 1000 milliseconds. * </ul> * Months and Years are imprecise and periods containing these values cannot be converted. * * @param period the period to get the number of hours from, null returns zero * @return the period in days * @throws IllegalArgumentException if the period contains imprecise duration values */ public static Days standardDaysIn(ReadablePeriod period) { int amount = BaseSingleFieldPeriod.standardPeriodIn(period, DateTimeConstants.MILLIS_PER_DAY); return Days.days(amount); }
/** * Gets the field type at the specified index. * <p> * The only index supported by this period is zero which returns the * field type of this class. * * @param index the index to retrieve, which must be zero * @return the field at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public DurationFieldType getFieldType(int index) { if (index != 0) { throw new IndexOutOfBoundsException(String.valueOf(index)); } return getFieldType(); }
/** * Compares this object with the specified object for equality based on the * value of each field. All ReadablePeriod instances are accepted, but only * those with a matching <code>PeriodType</code> can return true. * * @param period a readable period to check against * @return true if all the field values are equal, false if * not or the period is null or of an incorrect type */ public boolean equals(Object period) { if (this == period) { return true; } if (period instanceof ReadablePeriod == false) { return false; } ReadablePeriod other = (ReadablePeriod) period; return (other.getPeriodType() == getPeriodType() && other.getValue(0) == getValue()); }
/** * Compares this period to another object of the same class. * * @param other the other period, must not be null * @return zero if equal, positive if greater, negative if less * @throws NullPointerException if the other period is null * @throws ClassCastException if the other period is of a different type */ public int compareTo(BaseSingleFieldPeriod other) { if (other.getClass() != getClass()) { throw new ClassCastException(getClass() + " cannot be compared to " + other.getClass()); } int otherValue = other.getValue(); int thisValue = getValue(); if (thisValue > otherValue) { return 1; } if (thisValue < otherValue) { return -1; } return 0; }
/** * Gets a hash code for the period as defined by ReadablePeriod. * * @return a hash code */ public int hashCode() { int total = 17; total = 27 * total + getValue(); total = 27 * total + getFieldType().hashCode(); return total; }
/** * Creates a <code>Weeks</code> representing the number of whole weeks * between the two specified datetimes. * * @param start the start instant, must not be null * @param end the end instant, must not be null * @return the period in weeks * @throws IllegalArgumentException if the instants are null or invalid */ public static Weeks weeksBetween(ReadableInstant start, ReadableInstant end) { int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.weeks()); return Weeks.weeks(amount); }
/** * Creates a new <code>Minutes</code> representing the number of complete * standard length minutes in the specified period. * <p> * This factory method converts all fields from the period to minutes using standardised * durations for each field. Only those fields which have a precise duration in * the ISO UTC chronology can be converted. * <ul> * <li>One week consists of 7 days. * <li>One day consists of 24 hours. * <li>One hour consists of 60 minutes. * <li>One minute consists of 60 seconds. * <li>One second consists of 1000 milliseconds. * </ul> * Months and Years are imprecise and periods containing these values cannot be converted. * * @param period the period to get the number of minutes from, null returns zero * @return the period in minutes * @throws IllegalArgumentException if the period contains imprecise duration values */ public static Minutes standardMinutesIn(ReadablePeriod period) { int amount = BaseSingleFieldPeriod.standardPeriodIn(period, DateTimeConstants.MILLIS_PER_MINUTE); return Minutes.minutes(amount); }
/** * Gets the field type at the specified index. * <p> * The only index supported by this period is zero which returns the * field type of this class. * * @param index the index to retrieve, which must be zero * @return the field at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public DurationFieldType getFieldType(int index) { if (index != 0) { throw new IndexOutOfBoundsException(String.valueOf(index)); } return getFieldType(); }
/** * Compares this object with the specified object for equality based on the * value of each field. All ReadablePeriod instances are accepted, but only * those with a matching <code>PeriodType</code> can return true. * * @param period a readable period to check against * @return true if all the field values are equal, false if * not or the period is null or of an incorrect type */ public boolean equals(Object period) { if (this == period) { return true; } if (period instanceof ReadablePeriod == false) { return false; } ReadablePeriod other = (ReadablePeriod) period; return (other.getPeriodType() == getPeriodType() && other.getValue(0) == getValue()); }