/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Seconds.seconds(getValue()); }
/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Seconds.seconds(getValue()); }
/** * Returns a new instance with the seconds 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 Seconds dividedBy(int divisor) { if (divisor == 1) { return this; } return Seconds.seconds(getValue() / divisor); }
/** * Returns a new instance with the seconds 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 Seconds multipliedBy(int scalar) { return Seconds.seconds(FieldUtils.safeMultiply(getValue(), scalar)); }
/** * Returns a new instance with the seconds value negated. * * @return the new period with a negated value * @throws ArithmeticException if the result overflows an int */ public Seconds negated() { return Seconds.seconds(FieldUtils.safeNegate(getValue())); }
/** * 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); }
/** * Returns a new instance with the seconds 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 Seconds multipliedBy(int scalar) { return Seconds.seconds(FieldUtils.safeMultiply(getValue(), scalar)); }
/** * Returns a new instance with the seconds value negated. * * @return the new period with a negated value * @throws ArithmeticException if the result overflows an int */ public Seconds negated() { return Seconds.seconds(FieldUtils.safeNegate(getValue())); }
/** * 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); }
/** * Converts this duration to a period in seconds assuming that there are the * standard number of milliseconds in a second. * <p> * This method assumes that there are 1000 milliseconds in a second. * All currently supplied chronologies use this definition. * * @return a period representing the number of standard seconds in this period, never null * @throws ArithmeticException if the number of seconds is too large to be represented * @since 1.6 */ public Seconds toStandardSeconds() { long seconds = getStandardSeconds(); return Seconds.seconds(FieldUtils.safeToInt(seconds)); }
/** * Returns a new instance with the specified number of seconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param seconds the amount of seconds to add, may be negative * @return the new period plus the specified number of seconds * @throws ArithmeticException if the result overflows an int */ public Seconds plus(int seconds) { if (seconds == 0) { return this; } return Seconds.seconds(FieldUtils.safeAdd(getValue(), seconds)); }
/** * Converts this period in minutes to a period in seconds assuming a * 60 second minute. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all minutes are * 60 seconds 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 seconds for this number of minutes * @throws ArithmeticException if the number of seconds is too large to be represented */ public Seconds toStandardSeconds() { return Seconds.seconds(FieldUtils.safeMultiply(getValue(), DateTimeConstants.SECONDS_PER_MINUTE)); }
/** * Converts this period in hours to a period in seconds assuming a * 60 minute hour and 60 second minute. * <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 and all minutes are 60 seconds 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 seconds for this number of hours * @throws ArithmeticException if the number of seconds is too large to be represented */ public Seconds toStandardSeconds() { return Seconds.seconds(FieldUtils.safeMultiply(getValue(), DateTimeConstants.SECONDS_PER_HOUR)); }
/** * Returns a new instance with the specified number of seconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param seconds the amount of seconds to add, may be negative * @return the new period plus the specified number of seconds * @throws ArithmeticException if the result overflows an int */ public Seconds plus(int seconds) { if (seconds == 0) { return this; } return Seconds.seconds(FieldUtils.safeAdd(getValue(), seconds)); }
/** * Converts this duration to a period in seconds assuming that there are the * standard number of milliseconds in a second. * <p> * This method assumes that there are 1000 milliseconds in a second. * All currently supplied chronologies use this definition. * * @return a period representing the number of standard seconds in this period, never null * @throws ArithmeticException if the number of seconds is too large to be represented * @since 1.6 */ public Seconds toStandardSeconds() { long seconds = getStandardSeconds(); return Seconds.seconds(FieldUtils.safeToInt(seconds)); }
/** * Converts this period in days to a period in seconds assuming a * 24 hour day, 60 minute hour and 60 second minute. * <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, all hours are 60 minutes long and all minutes are 60 seconds 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 seconds for this number of days * @throws ArithmeticException if the number of seconds is too large to be represented */ public Seconds toStandardSeconds() { return Seconds.seconds(FieldUtils.safeMultiply(getValue(), DateTimeConstants.SECONDS_PER_DAY)); }
@Override @JsonIgnore public DateTime getFrom() { // TODO this should be computed once if (range() > 0) { return Tools.nowUTC().minus(Seconds.seconds(range())); } return new DateTime(0, DateTimeZone.UTC); }
/** * Converts this period in weeks to a period in seconds assuming a * 7 day week, 24 hour day, 60 minute hour and 60 second minute. * <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, all days are 24 hours long, all hours are 60 minutes long * and all minutes are 60 seconds 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 seconds for this number of weeks * @throws ArithmeticException if the number of seconds is too large to be represented */ public Seconds toStandardSeconds() { return Seconds.seconds(FieldUtils.safeMultiply(getValue(), DateTimeConstants.SECONDS_PER_WEEK)); }
/** * Creates a <code>Seconds</code> representing the number of whole seconds * in the specified interval. * * @param interval the interval to extract seconds from, null returns zero * @return the period in seconds * @throws IllegalArgumentException if the partials are null or invalid */ public static Seconds secondsIn(ReadableInterval interval) { if (interval == null) { return Seconds.ZERO; } int amount = BaseSingleFieldPeriod.between(interval.getStart(), interval.getEnd(), DurationFieldType.seconds()); return Seconds.seconds(amount); }
/** * Creates a <code>Seconds</code> representing the number of whole seconds * in the specified interval. * * @param interval the interval to extract seconds from, null returns zero * @return the period in seconds * @throws IllegalArgumentException if the partials are null or invalid */ public static Seconds secondsIn(ReadableInterval interval) { if (interval == null) { return Seconds.ZERO; } int amount = BaseSingleFieldPeriod.between(interval.getStart(), interval.getEnd(), DurationFieldType.seconds()); return Seconds.seconds(amount); }