Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    *  Copyright 2001-2010 Stephen Colebourne
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
    *  You may obtain a copy of the License at
    *
    *      http://www.apache.org/licenses/LICENSE-2.0
    *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.joda.time;
  
  
  import  org.joda.convert.FromString;
Standard mutable time period implementation.

A time period is divided into a number of fields, such as hours and seconds. Which fields are supported is defined by the PeriodType class. The default is the standard period type, which supports years, months, weeks, days, hours, minutes, seconds and millis.

When this time period is added to an instant, the effect is of adding each field in turn. As a result, this takes into account daylight savings time. Adding a time period of 1 day to the day before daylight savings starts will only add 23 hours rather than 24 to ensure that the time remains the same. If this is not the behaviour you want, then see Duration.

The definition of a period also affects the equals method. A period of 1 day is not equal to a period of 24 hours, nor 1 hour equal to 60 minutes. This is because periods represent an abstracted definition of a time period (eg. a day may not actually be 24 hours, it might be 23 or 25 at daylight savings boundary). To compare the actual duration of two periods, convert both to durations using toDuration, an operation that emphasises that the result may differ according to the date you choose.

MutablePeriod is mutable and not thread-safe, unless concurrent threads are not invoking mutator methods.

Author(s):
Brian S O'Neill
Stephen Colebourne
Since:
1.0
See also:
Period
  
  public class MutablePeriod
          extends BasePeriod
          implements ReadWritablePeriodCloneableSerializable {

    
Serialization version
  
      private static final long serialVersionUID = 3436451121567212165L;
  
      //-----------------------------------------------------------------------
      
Parses a MutablePeriod from the specified string.

This uses ISOPeriodFormat.standard().

Parameters:
str the string to parse, not null
Since:
2.0
  
      @FromString
      public static MutablePeriod parse(String str) {
          return parse(str, ISOPeriodFormat.standard());
      }

    
Parses a MutablePeriod from the specified string using a formatter.

Parameters:
str the string to parse, not null
formatter the formatter to use, not null
Since:
2.0
  
      public static MutablePeriod parse(String strPeriodFormatter formatter) {
          return formatter.parsePeriod(str).toMutablePeriod();
      }
  
      //-----------------------------------------------------------------------
      
Creates a zero-length period using the standard period type.
  
      public MutablePeriod() {
          super(0L, nullnull);
      }

    
Creates a zero-length period using the specified period type.

Parameters:
type which set of fields this period supports
 
     public MutablePeriod(PeriodType type) {
         super(0L, typenull);
     }

    
Create a period from a set of field values using the standard set of fields.

Parameters:
hours amount of hours in this period
minutes amount of minutes in this period
seconds amount of seconds in this period
millis amount of milliseconds in this period
 
     public MutablePeriod(int hoursint minutesint secondsint millis) {
         super(0, 0, 0, 0, hoursminutessecondsmillis, PeriodType.standard());
     }

    
Create a period from a set of field values using the standard set of fields.

Parameters:
years amount of years in this period
months amount of months in this period
weeks amount of weeks in this period
days amount of days in this period
hours amount of hours in this period
minutes amount of minutes in this period
seconds amount of seconds in this period
millis amount of milliseconds in this period
 
     public MutablePeriod(int yearsint monthsint weeksint days,
                   int hoursint minutesint secondsint millis) {
         super(yearsmonthsweeksdayshoursminutessecondsmillis, PeriodType.standard());
     }

    
Create a period from a set of field values.

Parameters:
years amount of years in this period, which must be zero if unsupported
months amount of months in this period, which must be zero if unsupported
weeks amount of weeks in this period, which must be zero if unsupported
days amount of days in this period, which must be zero if unsupported
hours amount of hours in this period, which must be zero if unsupported
minutes amount of minutes in this period, which must be zero if unsupported
seconds amount of seconds in this period, which must be zero if unsupported
millis amount of milliseconds in this period, which must be zero if unsupported
type which set of fields this period supports, null means AllType
Throws:
IllegalArgumentException if an unsupported field's value is non-zero
 
     public MutablePeriod(int yearsint monthsint weeksint days,
                     int hoursint minutesint secondsint millisPeriodType type) {
         super(yearsmonthsweeksdayshoursminutessecondsmillistype);
     }

    
Creates a period from the given millisecond duration using the standard set of fields.

Only precise fields in the period type will be used. For the standard period type this is the time fields only. Thus the year, month, week and day fields will not be populated.

If the duration is small, less than one day, then this method will perform as you might expect and split the fields evenly.

If the duration is larger than one day then all the remaining duration will be stored in the largest available precise field, hours in this case.

For example, a duration equal to (365 + 60 + 5) days will be converted to ((365 + 60 + 5) * 24) hours by this constructor.

For more control over the conversion process, you have two options:

  • convert the duration to an Interval, and from there obtain the period
  • specify a period type that contains precise definitions of the day and larger fields, such as the UTC or precise types.

Parameters:
duration the duration, in milliseconds
 
     public MutablePeriod(long duration) {
         super(duration);
     }

    
Creates a period from the given millisecond duration.

Only precise fields in the period type will be used. Imprecise fields will not be populated.

If the duration is small then this method will perform as you might expect and split the fields evenly.

If the duration is large then all the remaining duration will be stored in the largest available precise field. For details as to which fields are precise, review the period type javadoc.

Parameters:
duration the duration, in milliseconds
type which set of fields this period supports, null means standard
 
     public MutablePeriod(long durationPeriodType type) {
         super(durationtypenull);
     }

    
Creates a period from the given millisecond duration using the standard set of fields.

Only precise fields in the period type will be used. Imprecise fields will not be populated.

If the duration is small then this method will perform as you might expect and split the fields evenly.

If the duration is large then all the remaining duration will be stored in the largest available precise field. For details as to which fields are precise, review the period type javadoc.

Parameters:
duration the duration, in milliseconds
chronology the chronology to use to split the duration, null means ISO default
 
     public MutablePeriod(long durationChronology chronology) {
         super(durationnullchronology);
     }

    
Creates a period from the given millisecond duration.

Only precise fields in the period type will be used. Imprecise fields will not be populated.

If the duration is small then this method will perform as you might expect and split the fields evenly.

If the duration is large then all the remaining duration will be stored in the largest available precise field. For details as to which fields are precise, review the period type javadoc.

Parameters:
duration the duration, in milliseconds
type which set of fields this period supports, null means standard
chronology the chronology to use to split the duration, null means ISO default
 
     public MutablePeriod(long durationPeriodType typeChronology chronology) {
         super(durationtypechronology);
     }

    
Creates a period from the given interval endpoints using the standard set of fields.

Parameters:
startInstant interval start, in milliseconds
endInstant interval end, in milliseconds
 
     public MutablePeriod(long startInstantlong endInstant) {
         super(startInstantendInstantnullnull);
     }

    
Creates a period from the given interval endpoints.

Parameters:
startInstant interval start, in milliseconds
endInstant interval end, in milliseconds
type which set of fields this period supports, null means standard
 
     public MutablePeriod(long startInstantlong endInstantPeriodType type) {
         super(startInstantendInstanttypenull);
     }

    
Creates a period from the given interval endpoints using the standard set of fields.

Parameters:
startInstant interval start, in milliseconds
endInstant interval end, in milliseconds
chrono the chronology to use, null means ISO in default zone
 
     public MutablePeriod(long startInstantlong endInstantChronology chrono) {
         super(startInstantendInstantnullchrono);
     }

    
Creates a period from the given interval endpoints.

Parameters:
startInstant interval start, in milliseconds
endInstant interval end, in milliseconds
type which set of fields this period supports, null means standard
chrono the chronology to use, null means ISO in default zone
 
     public MutablePeriod(long startInstantlong endInstantPeriodType typeChronology chrono) {
         super(startInstantendInstanttypechrono);
     }

    
Creates a period from the given interval endpoints using the standard set of fields.

The chronology of the start instant is used, unless that is null when the chronology of the end instant is used instead.

Parameters:
startInstant interval start, null means now
endInstant interval end, null means now
 
     public MutablePeriod(ReadableInstant startInstantReadableInstant endInstant) {
         super(startInstantendInstantnull);
     }

    
Creates a period from the given interval endpoints.

The chronology of the start instant is used, unless that is null when the chronology of the end instant is used instead.

Parameters:
startInstant interval start, null means now
endInstant interval end, null means now
type which set of fields this period supports, null means AllType
 
     public MutablePeriod(ReadableInstant startInstantReadableInstant endInstantPeriodType type) {
         super(startInstantendInstanttype);
     }

    
Creates a period from the given start point and the duration.

Parameters:
startInstant the interval start, null means now
duration the duration of the interval, null means zero-length
 
     public MutablePeriod(ReadableInstant startInstantReadableDuration duration) {
         super(startInstantdurationnull);
     }

    
Creates a period from the given start point and the duration.

Parameters:
startInstant the interval start, null means now
duration the duration of the interval, null means zero-length
type which set of fields this period supports, null means standard
 
     public MutablePeriod(ReadableInstant startInstantReadableDuration durationPeriodType type) {
         super(startInstantdurationtype);
     }

    
Creates a period from the given duration and end point.

Parameters:
duration the duration of the interval, null means zero-length
endInstant the interval end, null means now
 
     public MutablePeriod(ReadableDuration durationReadableInstant endInstant) {
         super(durationendInstantnull);
     }

    
Creates a period from the given duration and end point.

Parameters:
duration the duration of the interval, null means zero-length
endInstant the interval end, null means now
type which set of fields this period supports, null means standard
 
     public MutablePeriod(ReadableDuration durationReadableInstant endInstantPeriodType type) {
         super(durationendInstanttype);
     }

    
Creates a period by converting or copying from another object.

The recognised object types are defined in ConverterManager and include ReadablePeriod, ReadableInterval and String. The String formats are described by ISOPeriodFormat.standard().

Parameters:
period period to convert
Throws:
IllegalArgumentException if period is invalid
UnsupportedOperationException if an unsupported field's value is non-zero
 
     public MutablePeriod(Object period) {
         super(periodnullnull);
     }

    
Creates a period by converting or copying from another object.

The recognised object types are defined in ConverterManager and include ReadablePeriod, ReadableInterval and String. The String formats are described by ISOPeriodFormat.standard().

Parameters:
period period to convert
type which set of fields this period supports, null means use converter
Throws:
IllegalArgumentException if period is invalid
UnsupportedOperationException if an unsupported field's value is non-zero
 
     public MutablePeriod(Object periodPeriodType type) {
         super(periodtypenull);
     }

    
Creates a period by converting or copying from another object.

The recognised object types are defined in ConverterManager and include ReadablePeriod, ReadableInterval and String. The String formats are described by ISOPeriodFormat.standard().

Parameters:
period period to convert
chrono the chronology to use, null means ISO in default zone
Throws:
IllegalArgumentException if period is invalid
UnsupportedOperationException if an unsupported field's value is non-zero
 
     public MutablePeriod(Object periodChronology chrono) {
         super(periodnullchrono);
     }

    
Creates a period by converting or copying from another object.

The recognised object types are defined in ConverterManager and include ReadablePeriod, ReadableInterval and String. The String formats are described by ISOPeriodFormat.standard().

Parameters:
period period to convert
type which set of fields this period supports, null means use converter
chrono the chronology to use, null means ISO in default zone
Throws:
IllegalArgumentException if period is invalid
UnsupportedOperationException if an unsupported field's value is non-zero
 
     public MutablePeriod(Object periodPeriodType typeChronology chrono) {
         super(periodtypechrono);
     }
 
     //-----------------------------------------------------------------------
     
Clears the period, setting all values back to zero.
 
     public void clear() {
         super.setValues(new int[size()]);
     }

    
Sets the value of one of the fields by index.

Parameters:
index the field index
value the new value for the field
Throws:
IndexOutOfBoundsException if the index is invalid
 
     public void setValue(int indexint value) {
         super.setValue(indexvalue);
     }

    
Sets the value of one of the fields.

The field type specified must be one of those that is supported by the period.

Parameters:
field a DurationFieldType instance that is supported by this period, not null
value the new value for the field
Throws:
IllegalArgumentException if the field is null or not supported
 
     public void set(DurationFieldType fieldint value) {
         super.setField(fieldvalue);
     }

    
Sets all the fields in one go from another ReadablePeriod.

Parameters:
period the period to set, null means zero length period
Throws:
IllegalArgumentException if an unsupported field's value is non-zero
 
     public void setPeriod(ReadablePeriod period) {
         super.setPeriod(period);
     }

    
Sets all the fields in one go.

Parameters:
years amount of years in this period, which must be zero if unsupported
months amount of months in this period, which must be zero if unsupported
weeks amount of weeks in this period, which must be zero if unsupported
days amount of days in this period, which must be zero if unsupported
hours amount of hours in this period, which must be zero if unsupported
minutes amount of minutes in this period, which must be zero if unsupported
seconds amount of seconds in this period, which must be zero if unsupported
millis amount of milliseconds in this period, which must be zero if unsupported
Throws:
IllegalArgumentException if an unsupported field's value is non-zero
 
     public void setPeriod(int yearsint monthsint weeksint days,
                           int hoursint minutesint secondsint millis) {
         super.setPeriod(yearsmonthsweeksdayshoursminutessecondsmillis);
     }

    
Sets all the fields in one go from an interval using the ISO chronology and dividing the fields using the period type.

Parameters:
interval the interval to set, null means zero length
Throws:
ArithmeticException if the set exceeds the capacity of the period
 
     public void setPeriod(ReadableInterval interval) {
         if (interval == null) {
             setPeriod(0L);
         } else {
             Chronology chrono = DateTimeUtils.getChronology(interval.getChronology());
             setPeriod(interval.getStartMillis(), interval.getEndMillis(), chrono);
         }
     }

    
Sets all the fields in one go from two instants representing an interval.

The chronology of the start instant is used, unless that is null when the chronology of the end instant is used instead.

Parameters:
start the start instant, null means now
end the end instant, null means now
Throws:
ArithmeticException if the set exceeds the capacity of the period
 
     public void setPeriod(ReadableInstant startReadableInstant end) {
         if (start == end) {
             setPeriod(0L);
         } else {
             long startMillis = DateTimeUtils.getInstantMillis(start);
             long endMillis = DateTimeUtils.getInstantMillis(end);
             Chronology chrono = DateTimeUtils.getIntervalChronology(startend);
             setPeriod(startMillisendMillischrono);
         }
     }

    
Sets all the fields in one go from a millisecond interval using ISOChronology and dividing the fields using the period type.

Parameters:
startInstant interval start, in milliseconds
endInstant interval end, in milliseconds
Throws:
ArithmeticException if the set exceeds the capacity of the period
 
     public void setPeriod(long startInstantlong endInstant) {
         setPeriod(startInstantendInstantnull);
     }

    
Sets all the fields in one go from a millisecond interval.

Parameters:
startInstant interval start, in milliseconds
endInstant interval end, in milliseconds
chrono the chronology to use, not null
Throws:
ArithmeticException if the set exceeds the capacity of the period
 
     public void setPeriod(long startInstantlong endInstantChronology chrono) {
         chrono = DateTimeUtils.getChronology(chrono);
         setValues(chrono.get(thisstartInstantendInstant));
     }

    
Sets all the fields in one go from a duration dividing the fields using the period type.

When dividing the duration, only precise fields in the period type will be used. For large durations, all the remaining duration will be stored in the largest available precise field.

Parameters:
duration the duration to set, null means zero length
Throws:
ArithmeticException if the set exceeds the capacity of the period
 
     public void setPeriod(ReadableDuration duration) {
         setPeriod(durationnull);
     }

    
Sets all the fields in one go from a duration dividing the fields using the period type.

When dividing the duration, only precise fields in the period type will be used. For large durations, all the remaining duration will be stored in the largest available precise field.

Parameters:
duration the duration to set, null means zero length
chrono the chronology to use, null means ISO default
Throws:
ArithmeticException if the set exceeds the capacity of the period
 
     public void setPeriod(ReadableDuration durationChronology chrono) {
         long durationMillis = DateTimeUtils.getDurationMillis(duration);
         setPeriod(durationMillischrono);
     }

    
Sets all the fields in one go from a millisecond duration dividing the fields using the period type.

When dividing the duration, only precise fields in the period type will be used. For large durations, all the remaining duration will be stored in the largest available precise field.

Parameters:
duration the duration, in milliseconds
Throws:
ArithmeticException if the set exceeds the capacity of the period
 
     public void setPeriod(long duration) {
         setPeriod(durationnull);
     }

    
Sets all the fields in one go from a millisecond duration.

When dividing the duration, only precise fields in the period type will be used. For large durations, all the remaining duration will be stored in the largest available precise field.

Parameters:
duration the duration, in milliseconds
chrono the chronology to use, not null
Throws:
ArithmeticException if the set exceeds the capacity of the period
 
     public void setPeriod(long durationChronology chrono) {
         chrono = DateTimeUtils.getChronology(chrono);
         setValues(chrono.get(thisduration));
     }
 
     //-----------------------------------------------------------------------
     
Adds to the value of one of the fields.

The field type specified must be one of those that is supported by the period.

Parameters:
field a DurationFieldType instance that is supported by this period, not null
value the value to add to the field
Throws:
IllegalArgumentException if the field is null or not supported
 
     public void add(DurationFieldType fieldint value) {
         super.addField(fieldvalue);
     }

    
Adds a period to this one by adding each field in turn.

Parameters:
period the period to add, null means add nothing
Throws:
IllegalArgumentException if the period being added contains a field not supported by this period
ArithmeticException if the addition exceeds the capacity of the period
 
     public void add(ReadablePeriod period) {
         super.addPeriod(period);
     }

    
Adds to each field of this period.

Parameters:
years amount of years to add to this period, which must be zero if unsupported
months amount of months to add to this period, which must be zero if unsupported
weeks amount of weeks to add to this period, which must be zero if unsupported
days amount of days to add to this period, which must be zero if unsupported
hours amount of hours to add to this period, which must be zero if unsupported
minutes amount of minutes to add to this period, which must be zero if unsupported
seconds amount of seconds to add to this period, which must be zero if unsupported
millis amount of milliseconds to add to this period, which must be zero if unsupported
Throws:
IllegalArgumentException if the period being added contains a field not supported by this period
ArithmeticException if the addition exceeds the capacity of the period
 
     public void add(int yearsint monthsint weeksint days,
                        int hoursint minutesint secondsint millis) {
         setPeriod(
             FieldUtils.safeAdd(getYears(), years),
             FieldUtils.safeAdd(getMonths(), months),
             FieldUtils.safeAdd(getWeeks(), weeks),
             FieldUtils.safeAdd(getDays(), days),
             FieldUtils.safeAdd(getHours(), hours),
             FieldUtils.safeAdd(getMinutes(), minutes),
             FieldUtils.safeAdd(getSeconds(), seconds),
             FieldUtils.safeAdd(getMillis(), millis)
         );
     }

    
Adds an interval to this one by dividing the interval into fields and calling add(ReadablePeriod).

Parameters:
interval the interval to add, null means add nothing
Throws:
ArithmeticException if the addition exceeds the capacity of the period
 
     public void add(ReadableInterval interval) {
         if (interval != null) {
             add(interval.toPeriod(getPeriodType()));
         }
     }

    
Adds a duration to this one by dividing the duration into fields and calling add(ReadablePeriod).

Parameters:
duration the duration to add, null means add nothing
Throws:
ArithmeticException if the addition exceeds the capacity of the period
 
     public void add(ReadableDuration duration) {
         if (duration != null) {
             add(new Period(duration.getMillis(), getPeriodType()));
         }
     }

    
Adds a millisecond duration to this one by dividing the duration into fields and calling add(ReadablePeriod).

When dividing the duration, only precise fields in the period type will be used. For large durations, all the remaining duration will be stored in the largest available precise field.

Parameters:
duration the duration, in milliseconds
Throws:
ArithmeticException if the addition exceeds the capacity of the period
 
     public void add(long duration) {
         add(new Period(durationgetPeriodType()));
     }

    
Adds a millisecond duration to this one by dividing the duration into fields and calling add(ReadablePeriod).

When dividing the duration, only precise fields in the period type will be used. For large durations, all the remaining duration will be stored in the largest available precise field.

Parameters:
duration the duration, in milliseconds
chrono the chronology to use, null means ISO default
Throws:
ArithmeticException if the addition exceeds the capacity of the period
 
     public void add(long durationChronology chrono) {
         add(new Period(durationgetPeriodType(), chrono));
     }
 
     //-----------------------------------------------------------------------
     
Merges all the fields from the specified period into this one.

Fields that are not present in the specified period are left unaltered.

Parameters:
period the period to set, null ignored
Throws:
IllegalArgumentException if an unsupported field's value is non-zero
 
     public void mergePeriod(ReadablePeriod period) {
         super.mergePeriod(period);
     }
 
     //-----------------------------------------------------------------------
     
Gets the years field part of the period.

Returns:
the number of years in the period, zero if unsupported
 
     public int getYears() {
         return getPeriodType().getIndexedField(this.);
     }

    
Gets the months field part of the period.

Returns:
the number of months in the period, zero if unsupported
 
     public int getMonths() {
         return getPeriodType().getIndexedField(this.);
     }

    
Gets the weeks field part of the period.

Returns:
the number of weeks in the period, zero if unsupported
 
     public int getWeeks() {
         return getPeriodType().getIndexedField(this.);
     }

    
Gets the days field part of the period.

Returns:
the number of days in the period, zero if unsupported
 
     public int getDays() {
         return getPeriodType().getIndexedField(this.);
     }
 
     //-----------------------------------------------------------------------
     
Gets the hours field part of the period.

Returns:
the number of hours in the period, zero if unsupported
 
     public int getHours() {
         return getPeriodType().getIndexedField(this.);
     }

    
Gets the minutes field part of the period.

Returns:
the number of minutes in the period, zero if unsupported
 
     public int getMinutes() {
         return getPeriodType().getIndexedField(this.);
     }

    
Gets the seconds field part of the period.

Returns:
the number of seconds in the period, zero if unsupported
 
     public int getSeconds() {
         return getPeriodType().getIndexedField(this.);
     }

    
Gets the millis field part of the period.

Returns:
the number of millis in the period, zero if unsupported
 
     public int getMillis() {
         return getPeriodType().getIndexedField(this.);
     }
 
     //-----------------------------------------------------------------------
     
Sets the number of years of the period.

Parameters:
years the number of years
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
 
     public void setYears(int years) {
         super.setField(DurationFieldType.years(), years);
     }

    
Adds the specified years to the number of years in the period.

Parameters:
years the number of years
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
ArithmeticException if the addition exceeds the capacity of the period
 
     public void addYears(int years) {
         super.addField(DurationFieldType.years(), years);
     }
 
     //-----------------------------------------------------------------------
     
Sets the number of months of the period.

Parameters:
months the number of months
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
 
     public void setMonths(int months) {
         super.setField(DurationFieldType.months(), months);
     }

    
Adds the specified months to the number of months in the period.

Parameters:
months the number of months
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
ArithmeticException if the addition exceeds the capacity of the period
 
     public void addMonths(int months) {
         super.addField(DurationFieldType.months(), months);
     }
 
     //-----------------------------------------------------------------------
     
Sets the number of weeks of the period.

Parameters:
weeks the number of weeks
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
 
     public void setWeeks(int weeks) {
         super.setField(DurationFieldType.weeks(), weeks);
     }

    
Adds the specified weeks to the number of weeks in the period.

Parameters:
weeks the number of weeks
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
ArithmeticException if the addition exceeds the capacity of the period
 
     public void addWeeks(int weeks) {
         super.addField(DurationFieldType.weeks(), weeks);
     }
 
     //-----------------------------------------------------------------------
     
Sets the number of days of the period.

Parameters:
days the number of days
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
 
     public void setDays(int days) {
         super.setField(DurationFieldType.days(), days);
     }

    
Adds the specified days to the number of days in the period.

Parameters:
days the number of days
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
ArithmeticException if the addition exceeds the capacity of the period
 
     public void addDays(int days) {
         super.addField(DurationFieldType.days(), days);
     }
 
     //-----------------------------------------------------------------------
     
Sets the number of hours of the period.

Parameters:
hours the number of hours
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
 
     public void setHours(int hours) {
         super.setField(DurationFieldType.hours(), hours);
     }

    
Adds the specified hours to the number of hours in the period.

Parameters:
hours the number of hours
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
ArithmeticException if the addition exceeds the capacity of the period
 
     public void addHours(int hours) {
         super.addField(DurationFieldType.hours(), hours);
     }
 
     //-----------------------------------------------------------------------
     
Sets the number of minutes of the period.

Parameters:
minutes the number of minutes
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
 
     public void setMinutes(int minutes) {
         super.setField(DurationFieldType.minutes(), minutes);
     }

    
Adds the specified minutes to the number of minutes in the period.

Parameters:
minutes the number of minutes
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
ArithmeticException if the addition exceeds the capacity of the period
 
     public void addMinutes(int minutes) {
         super.addField(DurationFieldType.minutes(), minutes);
     }
 
     //-----------------------------------------------------------------------
     
Sets the number of seconds of the period.

Parameters:
seconds the number of seconds
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
 
     public void setSeconds(int seconds) {
         super.setField(DurationFieldType.seconds(), seconds);
     }

    
Adds the specified seconds to the number of seconds in the period.

Parameters:
seconds the number of seconds
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
ArithmeticException if the addition exceeds the capacity of the period
 
     public void addSeconds(int seconds) {
         super.addField(DurationFieldType.seconds(), seconds);
     }
 
     //-----------------------------------------------------------------------
     
Sets the number of millis of the period.

Parameters:
millis the number of millis
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
 
     public void setMillis(int millis) {
         super.setField(DurationFieldType.millis(), millis);
     }

    
Adds the specified millis to the number of millis in the period.

Parameters:
millis the number of millis
Throws:
IllegalArgumentException if field is not supported and the value is non-zero
ArithmeticException if the addition exceeds the capacity of the period
 
     public void addMillis(int millis) {
         super.addField(DurationFieldType.millis(), millis);
     }
 
     // Misc
     //-----------------------------------------------------------------------
     
Clone this object without having to cast the returned object.

Returns:
a clone of the this object.
 
     public MutablePeriod copy() {
         return (MutablePeriodclone();
     }

    
Clone this object.

Returns:
a clone of this object.
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException ex) {
            throw new InternalError("Clone error");
        }
    }
New to GrepCode? Check out our FAQ X