/** * Is this days instance greater than the specified number of days. * * @param other the other period, null means zero * @return true if this days instance is greater than the specified one */ public boolean isGreaterThan(Days other) { if (other == null) { return getValue() > 0; } return getValue() > other.getValue(); }
/** * Is this days instance less than the specified number of days. * * @param other the other period, null means zero * @return true if this days instance is less than the specified one */ public boolean isLessThan(Days other) { if (other == null) { return getValue() < 0; } return getValue() < other.getValue(); }
/** * Gets the number of days that this period represents. * * @return the number of days in the period */ public int getDays() { return getValue(); }
/** * Is this days instance greater than the specified number of days. * * @param other the other period, null means zero * @return true if this days instance is greater than the specified one */ public boolean isGreaterThan(Days other) { if (other == null) { return getValue() > 0; } return getValue() > other.getValue(); }
/** * Is this days instance less than the specified number of days. * * @param other the other period, null means zero * @return true if this days instance is less than the specified one */ public boolean isLessThan(Days other) { if (other == null) { return getValue() < 0; } return getValue() < other.getValue(); }
/** * Gets the number of days that this period represents. * * @return the number of days in the period */ public int getDays() { return getValue(); }
/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Days.days(getValue()); }
/** * Gets this instance as a String in the ISO8601 duration format. * <p> * For example, "P4D" represents 4 days. * * @return the value as an ISO8601 string */ @ToString public String toString() { return "P" + String.valueOf(getValue()) + "D"; }
/** * Gets this instance as a String in the ISO8601 duration format. * <p> * For example, "P4D" represents 4 days. * * @return the value as an ISO8601 string */ @ToString public String toString() { return "P" + String.valueOf(getValue()) + "D"; }
/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Days.days(getValue()); }
/** * Returns a new instance with the specified number of days taken away. * <p> * This instance is immutable and unaffected by this method call. * * @param days the amount of days to take away, may be negative, null means zero * @return the new period minus the specified number of days * @throws ArithmeticException if the result overflows an int */ public Days minus(Days days) { if (days == null) { return this; } return minus(days.getValue()); }
/** * Converts this period in days to a period in weeks assuming a * 7 day week. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all weeks are * 7 days 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 weeks for this number of days */ public Weeks toStandardWeeks() { return Weeks.weeks(getValue() / DateTimeConstants.DAYS_PER_WEEK); }
/** * Returns a new instance with the specified number of days added. * <p> * This instance is immutable and unaffected by this method call. * * @param days the amount of days to add, may be negative, null means zero * @return the new period plus the specified number of days * @throws ArithmeticException if the result overflows an int */ public Days plus(Days days) { if (days == null) { return this; } return plus(days.getValue()); }
/** * Returns a new instance with the specified number of days added. * <p> * This instance is immutable and unaffected by this method call. * * @param days the amount of days to add, may be negative, null means zero * @return the new period plus the specified number of days * @throws ArithmeticException if the result overflows an int */ public Days plus(Days days) { if (days == null) { return this; } return plus(days.getValue()); }
/** * Returns a new instance with the days value negated. * * @return the new period with a negated value * @throws ArithmeticException if the result overflows an int */ public Days negated() { return Days.days(FieldUtils.safeNegate(getValue())); }
/** * Returns a new instance with the days 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 Days multipliedBy(int scalar) { return Days.days(FieldUtils.safeMultiply(getValue(), scalar)); }
/** * Returns a new instance with the days 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 Days multipliedBy(int scalar) { return Days.days(FieldUtils.safeMultiply(getValue(), scalar)); }
/** * Returns a new instance with the days value negated. * * @return the new period with a negated value * @throws ArithmeticException if the result overflows an int */ public Days negated() { return Days.days(FieldUtils.safeNegate(getValue())); }
/** * Returns a new instance with the specified number of days added. * <p> * This instance is immutable and unaffected by this method call. * * @param days the amount of days to add, may be negative * @return the new period plus the specified number of days * @throws ArithmeticException if the result overflows an int */ public Days plus(int days) { if (days == 0) { return this; } return Days.days(FieldUtils.safeAdd(getValue(), days)); }
/** * Converts this period in days to a period in hours 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 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 hours for this number of days * @throws ArithmeticException if the number of hours is too large to be represented */ public Hours toStandardHours() { return Hours.hours(FieldUtils.safeMultiply(getValue(), DateTimeConstants.HOURS_PER_DAY)); }