/** * Gets the number of hours that this period represents. * * @return the number of hours in the period */ public int getHours() { return getValue(); }
/** * Is this hours instance greater than the specified number of hours. * * @param other the other period, null means zero * @return true if this hours instance is greater than the specified one */ public boolean isGreaterThan(Hours other) { if (other == null) { return getValue() > 0; } return getValue() > other.getValue(); }
/** * Is this hours instance less than the specified number of hours. * * @param other the other period, null means zero * @return true if this hours instance is less than the specified one */ public boolean isLessThan(Hours other) { if (other == null) { return getValue() < 0; } return getValue() < other.getValue(); }
/** * Gets the number of hours that this period represents. * * @return the number of hours in the period */ public int getHours() { return getValue(); }
/** * Is this hours instance greater than the specified number of hours. * * @param other the other period, null means zero * @return true if this hours instance is greater than the specified one */ public boolean isGreaterThan(Hours other) { if (other == null) { return getValue() > 0; } return getValue() > other.getValue(); }
/** * Is this hours instance less than the specified number of hours. * * @param other the other period, null means zero * @return true if this hours instance is less than the specified one */ public boolean isLessThan(Hours other) { if (other == null) { return getValue() < 0; } return getValue() < other.getValue(); }
/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Hours.hours(getValue()); }
/** * Gets this instance as a String in the ISO8601 duration format. * <p> * For example, "PT4H" represents 4 hours. * * @return the value as an ISO8601 string */ @ToString public String toString() { return "PT" + String.valueOf(getValue()) + "H"; }
/** * Gets this instance as a String in the ISO8601 duration format. * <p> * For example, "PT4H" represents 4 hours. * * @return the value as an ISO8601 string */ @ToString public String toString() { return "PT" + String.valueOf(getValue()) + "H"; }
/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Hours.hours(getValue()); }
/** * Returns a new instance with the specified number of hours added. * <p> * This instance is immutable and unaffected by this method call. * * @param hours the amount of hours to add, may be negative, null means zero * @return the new period plus the specified number of hours * @throws ArithmeticException if the result overflows an int */ public Hours plus(Hours hours) { if (hours == null) { return this; } return plus(hours.getValue()); }
/** * Converts this period in hours to a period in days assuming a * 24 hour day. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all days are 24 hours long. * This is not true when daylight savings time is considered, and may also * not be true for some unusual chronologies. However, it is included as it * is a useful operation for many applications and business rules. * * @return a period representing the number of whole days for this number of hours */ public Days toStandardDays() { return Days.days(getValue() / DateTimeConstants.HOURS_PER_DAY); }
/** * Returns a new instance with the specified number of hours taken away. * <p> * This instance is immutable and unaffected by this method call. * * @param hours the amount of hours to take away, may be negative, null means zero * @return the new period minus the specified number of hours * @throws ArithmeticException if the result overflows an int */ public Hours minus(Hours hours) { if (hours == null) { return this; } return minus(hours.getValue()); }
/** * Returns a new instance with the hours divided by the specified divisor. * The calculation uses integer division, thus 3 divided by 2 is 1. * <p> * This instance is immutable and unaffected by this method call. * * @param divisor the amount to divide by, may be negative * @return the new period divided by the specified divisor * @throws ArithmeticException if the divisor is zero */ public Hours dividedBy(int divisor) { if (divisor == 1) { return this; } return Hours.hours(getValue() / divisor); }
/** * Returns a new instance with the hours value negated. * * @return the new period with a negated value * @throws ArithmeticException if the result overflows an int */ public Hours negated() { return Hours.hours(FieldUtils.safeNegate(getValue())); }
/** * Returns a new instance with the hours multiplied by the specified scalar. * <p> * This instance is immutable and unaffected by this method call. * * @param scalar the amount to multiply by, may be negative * @return the new period multiplied by the specified scalar * @throws ArithmeticException if the result overflows an int */ public Hours multipliedBy(int scalar) { return Hours.hours(FieldUtils.safeMultiply(getValue(), scalar)); }
/** * Returns a new instance with the hours value negated. * * @return the new period with a negated value * @throws ArithmeticException if the result overflows an int */ public Hours negated() { return Hours.hours(FieldUtils.safeNegate(getValue())); }
/** * Returns a new instance with the hours multiplied by the specified scalar. * <p> * This instance is immutable and unaffected by this method call. * * @param scalar the amount to multiply by, may be negative * @return the new period multiplied by the specified scalar * @throws ArithmeticException if the result overflows an int */ public Hours multipliedBy(int scalar) { return Hours.hours(FieldUtils.safeMultiply(getValue(), scalar)); }
/** * Returns a new instance with the specified number of hours added. * <p> * This instance is immutable and unaffected by this method call. * * @param hours the amount of hours to add, may be negative * @return the new period plus the specified number of hours * @throws ArithmeticException if the result overflows an int */ public Hours plus(int hours) { if (hours == 0) { return this; } return Hours.hours(FieldUtils.safeAdd(getValue(), hours)); }
/** * Converts this period in hours to a period in minutes assuming a * 60 minute hour. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all hours are 60 minutes long. * This may not be true for some unusual chronologies. However, it is included * as it is a useful operation for many applications and business rules. * * @return a period representing the number of minutes for this number of hours * @throws ArithmeticException if the number of minutes is too large to be represented */ public Minutes toStandardMinutes() { return Minutes.minutes(FieldUtils.safeMultiply(getValue(), DateTimeConstants.MINUTES_PER_HOUR)); }