/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Hours.hours(getValue()); }
/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Hours.hours(getValue()); }
/** * Converts this period in minutes to a period in hours 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 hours for this number of minutes */ public Hours toStandardHours() { return Hours.hours(getValue() / DateTimeConstants.MINUTES_PER_HOUR); }
/** * Converts this period in seconds to a period in hours 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 hours for this number of seconds */ public Hours toStandardHours() { return Hours.hours(getValue() / DateTimeConstants.SECONDS_PER_HOUR); }
/** * 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); }
/** * Converts this period in seconds to a period in hours 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 hours for this number of seconds */ public Hours toStandardHours() { return Hours.hours(getValue() / DateTimeConstants.SECONDS_PER_HOUR); }
/** * 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)); }
/** * Creates a <code>Hours</code> representing the number of whole hours * 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 hours * @throws IllegalArgumentException if the instants are null or invalid */ public static Hours hoursBetween(ReadableInstant start, ReadableInstant end) { int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.hours()); return Hours.hours(amount); }
/** * 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())); }
/** * Creates a <code>Hours</code> representing the number of whole hours * 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 hours * @throws IllegalArgumentException if the instants are null or invalid */ public static Hours hoursBetween(ReadableInstant start, ReadableInstant end) { int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.hours()); return Hours.hours(amount); }
/** * 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 duration to a period in hours assuming that there are the * standard number of milliseconds in an hour. * <p> * This method assumes that there are 60 minutes in an hour, * 60 seconds in a minute and 1000 milliseconds in a second. * All currently supplied chronologies use this definition. * * @return a period representing the number of standard hours in this period, never null * @throws ArithmeticException if the number of hours is too large to be represented * @since 2.0 */ public Hours toStandardHours() { long hours = getStandardHours(); return Hours.hours(FieldUtils.safeToInt(hours)); }
/** * 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)); }
/** * 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)); }
/** * Creates a <code>Hours</code> representing the number of whole hours * in the specified interval. * * @param interval the interval to extract hours from, null returns zero * @return the period in hours * @throws IllegalArgumentException if the partials are null or invalid */ public static Hours hoursIn(ReadableInterval interval) { if (interval == null) { return Hours.ZERO; } int amount = BaseSingleFieldPeriod.between(interval.getStart(), interval.getEnd(), DurationFieldType.hours()); return Hours.hours(amount); }
/** * Creates a <code>Hours</code> representing the number of whole hours * in the specified interval. * * @param interval the interval to extract hours from, null returns zero * @return the period in hours * @throws IllegalArgumentException if the partials are null or invalid */ public static Hours hoursIn(ReadableInterval interval) { if (interval == null) { return Hours.ZERO; } int amount = BaseSingleFieldPeriod.between(interval.getStart(), interval.getEnd(), DurationFieldType.hours()); return Hours.hours(amount); }
@Test public void testIterableHourSimple() { final DateTime baseTime = DateTimes.of("2011-01-01T09:00:00.000Z"); assertSameInterval( Lists.newArrayList( DateTimes.of("2011-01-01T09:00:00.000Z"), DateTimes.of("2011-01-01T10:00:00.000Z"), DateTimes.of("2011-01-01T11:00:00.000Z") ), Granularities.HOUR.getIterable(new Interval(baseTime, baseTime.plus(Hours.hours(3)))) ); }
@Test public void testIterableHourComplex() { final DateTime baseTime = DateTimes.of("2011-01-01T09:38:02.992Z"); assertSameInterval( Lists.newArrayList( DateTimes.of("2011-01-01T09:00:00.000Z"), DateTimes.of("2011-01-01T10:00:00.000Z"), DateTimes.of("2011-01-01T11:00:00.000Z"), DateTimes.of("2011-01-01T12:00:00.000Z") ), Granularities.HOUR.getIterable(new Interval(baseTime, baseTime.plus(Hours.hours(3)))) ); }