コード例 #1
0
ファイル: TimeOfDay.java プロジェクト: kebernet/goda-cronic
 /**
  * Returns a copy of this time with the specified period added, wrapping to what would be a new
  * day if required.
  *
  * <p>If the addition is zero, then <code>this</code> is returned. Fields in the period that
  * aren't present in the partial are ignored.
  *
  * <p>This method is typically used to add multiple copies of complex period instances. Adding one
  * field is best achieved using methods like {@link #withFieldAdded(DurationFieldType, int)} or
  * {@link #plusHours(int)}.
  *
  * @param period the period to add to this one, null means zero
  * @param scalar the amount of times to add, such as -1 to subtract once
  * @return a copy of this instance with the period added
  * @throws ArithmeticException if the new datetime exceeds the capacity
  */
 public TimeOfDay withPeriodAdded(ReadablePeriod period, int scalar) {
   if (period == null || scalar == 0) {
     return this;
   }
   int[] newValues = getValues();
   for (int i = 0; i < period.size(); i++) {
     DurationFieldType fieldType = period.getFieldType(i);
     int index = indexOf(fieldType);
     if (index >= 0) {
       newValues =
           getField(index)
               .addWrapPartial(
                   this, index, newValues, FieldUtils.safeMultiply(period.getValue(i), scalar));
     }
   }
   return new TimeOfDay(this, newValues);
 }
コード例 #2
0
ファイル: Hours.java プロジェクト: kebernet/goda-cronic
 /**
  * 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));
 }
コード例 #3
0
ファイル: Hours.java プロジェクト: kebernet/goda-cronic
 /**
  * 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));
 }
コード例 #4
0
ファイル: Hours.java プロジェクト: kebernet/goda-cronic
 /**
  * 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));
 }