/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Days.days(getValue()); }
/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Days.days(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); }
/** * Converts this period in seconds to a period in days 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 days for this number of seconds */ public Days toStandardDays() { return Days.days(getValue() / DateTimeConstants.SECONDS_PER_DAY); }
/** * Converts this period in minutes to a period in days assuming a * 24 hour day and 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 days are * 24 hours long and all hours are 60 minutes 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 whole days for this number of minutes */ public Days toStandardDays() { return Days.days(getValue() / DateTimeConstants.MINUTES_PER_DAY); }
/** * Returns a new instance with the days 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 Days dividedBy(int divisor) { if (divisor == 1) { return this; } return Days.days(getValue() / divisor); }
/** * 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())); }
/** * Creates a <code>Days</code> representing the number of whole days * between the two specified datetimes. This method correctly handles * any daylight savings time changes that may occur during the interval. * * @param start the start instant, must not be null * @param end the end instant, must not be null * @return the period in days * @throws IllegalArgumentException if the instants are null or invalid */ public static Days daysBetween(ReadableInstant start, ReadableInstant end) { int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.days()); return Days.days(amount); }
/** * 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 weeks to a period in days 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 days for this number of weeks * @throws ArithmeticException if the number of days is too large to be represented */ public Days toStandardDays() { return Days.days(FieldUtils.safeMultiply(getValue(), DateTimeConstants.DAYS_PER_WEEK)); }
/** * Creates a <code>Days</code> representing the number of whole days * between the two specified datetimes. This method correctly handles * any daylight savings time changes that may occur during the interval. * * @param start the start instant, must not be null * @param end the end instant, must not be null * @return the period in days * @throws IllegalArgumentException if the instants are null or invalid */ public static Days daysBetween(ReadableInstant start, ReadableInstant end) { int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.days()); return Days.days(amount); }
/** * Creates a <code>Days</code> representing the number of whole days * in the specified interval. This method correctly handles any daylight * savings time changes that may occur during the interval. * * @param interval the interval to extract days from, null returns zero * @return the period in days * @throws IllegalArgumentException if the partials are null or invalid */ public static Days daysIn(ReadableInterval interval) { if (interval == null) { return Days.ZERO; } int amount = BaseSingleFieldPeriod.between(interval.getStart(), interval.getEnd(), DurationFieldType.days()); return Days.days(amount); }
@Test public void testIterableAllSimple() { final DateTime baseTime = DateTimes.of("2011-01-01T00:00:00.000Z"); assertSameInterval( Collections.singletonList(baseTime), Granularities.ALL.getIterable(new Interval(baseTime, baseTime.plus(Days.days(3)))) ); }
@Test public void testIterableAllComplex() { final DateTime baseTime = DateTimes.of("2011-01-01T09:38:02.992Z"); assertSameInterval( Collections.singletonList(baseTime), Granularities.ALL.getIterable(new Interval(baseTime, baseTime.plus(Days.days(3)))) ); }
@Override public Interval getDataInterval() { return new Interval(DateTimes.nowUtc().minus(Days.days(1)), DateTimes.nowUtc()); }
@Test public void testIterableDaySimple() { final DateTime baseTime = DateTimes.of("2011-01-01T00:00:00.000Z"); assertSameInterval( Lists.newArrayList( DateTimes.of("2011-01-01T00:00:00.000Z"), DateTimes.of("2011-01-02T00:00:00.000Z"), DateTimes.of("2011-01-03T00:00:00.000Z") ), Granularities.DAY.getIterable(new Interval(baseTime, baseTime.plus(Days.days(3)))) ); }
@Test public void testIterableDayComplex() { final DateTime baseTime = DateTimes.of("2011-01-01T09:38:02.992Z"); assertSameInterval( Lists.newArrayList( DateTimes.of("2011-01-01T00:00:00.000Z"), DateTimes.of("2011-01-02T00:00:00.000Z"), DateTimes.of("2011-01-03T00:00:00.000Z"), DateTimes.of("2011-01-04T00:00:00.000Z") ), Granularities.DAY.getIterable(new Interval(baseTime, baseTime.plus(Days.days(3)))) ); }