org.joda.time
Class MutablePeriod

java.lang.Object
  extended by org.joda.time.base.AbstractPeriod
      extended by org.joda.time.base.BasePeriod
          extended by org.joda.time.MutablePeriod
All Implemented Interfaces:
Serializable, Cloneable, ReadablePeriod, ReadWritablePeriod

public class MutablePeriod
extends BasePeriod
implements ReadWritablePeriod, Cloneable, Serializable

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.

Since:
1.0
Author:
Brian S O'Neill, Stephen Colebourne
See Also:
Period, Serialized Form

Constructor Summary
MutablePeriod()
          Creates a zero-length period using the standard period type.
MutablePeriod(int hours, int minutes, int seconds, int millis)
          Create a period from a set of field values using the standard set of fields.
MutablePeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis)
          Create a period from a set of field values using the standard set of fields.
MutablePeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis, PeriodType type)
          Create a period from a set of field values.
MutablePeriod(long duration)
          Creates a period from the given millisecond duration using the standard set of fields.
MutablePeriod(long duration, Chronology chronology)
          Creates a period from the given millisecond duration using the standard set of fields.
MutablePeriod(long startInstant, long endInstant)
          Creates a period from the given interval endpoints using the standard set of fields.
MutablePeriod(long startInstant, long endInstant, Chronology chrono)
          Creates a period from the given interval endpoints using the standard set of fields.
MutablePeriod(long startInstant, long endInstant, PeriodType type)
          Creates a period from the given interval endpoints.
MutablePeriod(long startInstant, long endInstant, PeriodType type, Chronology chrono)
          Creates a period from the given interval endpoints.
MutablePeriod(long duration, PeriodType type)
          Creates a period from the given millisecond duration.
MutablePeriod(long duration, PeriodType type, Chronology chronology)
          Creates a period from the given millisecond duration.
MutablePeriod(Object period)
          Creates a period by converting or copying from another object.
MutablePeriod(Object period, Chronology chrono)
          Creates a period by converting or copying from another object.
MutablePeriod(Object period, PeriodType type)
          Creates a period by converting or copying from another object.
MutablePeriod(Object period, PeriodType type, Chronology chrono)
          Creates a period by converting or copying from another object.
MutablePeriod(PeriodType type)
          Creates a zero-length period using the specified period type.
MutablePeriod(ReadableDuration duration, ReadableInstant endInstant)
          Creates a period from the given duration and end point.
MutablePeriod(ReadableDuration duration, ReadableInstant endInstant, PeriodType type)
          Creates a period from the given duration and end point.
MutablePeriod(ReadableInstant startInstant, ReadableDuration duration)
          Creates a period from the given start point and the duration.
MutablePeriod(ReadableInstant startInstant, ReadableDuration duration, PeriodType type)
          Creates a period from the given start point and the duration.
MutablePeriod(ReadableInstant startInstant, ReadableInstant endInstant)
          Creates a period from the given interval endpoints using the standard set of fields.
MutablePeriod(ReadableInstant startInstant, ReadableInstant endInstant, PeriodType type)
          Creates a period from the given interval endpoints.
 
Method Summary
 void add(DurationFieldType field, int value)
          Adds to the value of one of the fields.
 void add(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis)
          Adds to each field of this period.
 void add(long duration)
          Adds a millisecond duration to this one by dividing the duration into fields and calling add(ReadablePeriod).
 void add(long duration, Chronology chrono)
          Adds a millisecond duration to this one by dividing the duration into fields and calling add(ReadablePeriod).
 void add(ReadableDuration duration)
          Adds a duration to this one by dividing the duration into fields and calling add(ReadablePeriod).
 void add(ReadableInterval interval)
          Adds an interval to this one by dividing the interval into fields and calling add(ReadablePeriod).
 void add(ReadablePeriod period)
          Adds a period to this one by adding each field in turn.
 void addDays(int days)
          Adds the specified days to the number of days in the period.
 void addHours(int hours)
          Adds the specified hours to the number of hours in the period.
 void addMillis(int millis)
          Adds the specified millis to the number of millis in the period.
 void addMinutes(int minutes)
          Adds the specified minutes to the number of minutes in the period.
 void addMonths(int months)
          Adds the specified months to the number of months in the period.
 void addSeconds(int seconds)
          Adds the specified seconds to the number of seconds in the period.
 void addWeeks(int weeks)
          Adds the specified weeks to the number of weeks in the period.
 void addYears(int years)
          Adds the specified years to the number of years in the period.
 void clear()
          Clears the period, setting all values back to zero.
 Object clone()
          Clone this object.
 MutablePeriod copy()
          Clone this object without having to cast the returned object.
 int getDays()
          Gets the days field part of the period.
 int getHours()
          Gets the hours field part of the period.
 int getMillis()
          Gets the millis field part of the period.
 int getMinutes()
          Gets the minutes field part of the period.
 int getMonths()
          Gets the months field part of the period.
 int getSeconds()
          Gets the seconds field part of the period.
 int getWeeks()
          Gets the weeks field part of the period.
 int getYears()
          Gets the years field part of the period.
 void mergePeriod(ReadablePeriod period)
          Merges all the fields from the specified period into this one.
static MutablePeriod parse(String str)
          Parses a MutablePeriod from the specified string.
static MutablePeriod parse(String str, PeriodFormatter formatter)
          Parses a MutablePeriod from the specified string using a formatter.
 void set(DurationFieldType field, int value)
          Sets the value of one of the fields.
 void setDays(int days)
          Sets the number of days of the period.
 void setHours(int hours)
          Sets the number of hours of the period.
 void setMillis(int millis)
          Sets the number of millis of the period.
 void setMinutes(int minutes)
          Sets the number of minutes of the period.
 void setMonths(int months)
          Sets the number of months of the period.
 void setPeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis)
          Sets all the fields in one go.
 void setPeriod(long duration)
          Sets all the fields in one go from a millisecond duration dividing the fields using the period type.
 void setPeriod(long duration, Chronology chrono)
          Sets all the fields in one go from a millisecond duration.
 void setPeriod(long startInstant, long endInstant)
          Sets all the fields in one go from a millisecond interval using ISOChronology and dividing the fields using the period type.
 void setPeriod(long startInstant, long endInstant, Chronology chrono)
          Sets all the fields in one go from a millisecond interval.
 void setPeriod(ReadableDuration duration)
          Sets all the fields in one go from a duration dividing the fields using the period type.
 void setPeriod(ReadableDuration duration, Chronology chrono)
          Sets all the fields in one go from a duration dividing the fields using the period type.
 void setPeriod(ReadableInstant start, ReadableInstant end)
          Sets all the fields in one go from two instants representing an interval.
 void setPeriod(ReadableInterval interval)
          Sets all the fields in one go from an interval using the ISO chronology and dividing the fields using the period type.
 void setPeriod(ReadablePeriod period)
          Sets all the fields in one go from another ReadablePeriod.
 void setSeconds(int seconds)
          Sets the number of seconds of the period.
 void setValue(int index, int value)
          Sets the value of one of the fields by index.
 void setWeeks(int weeks)
          Sets the number of weeks of the period.
 void setYears(int years)
          Sets the number of years of the period.
 
Methods inherited from class org.joda.time.base.BasePeriod
addField, addFieldInto, addPeriod, addPeriodInto, checkPeriodType, getPeriodType, getValue, mergePeriodInto, setField, setFieldInto, setValues, toDurationFrom, toDurationTo
 
Methods inherited from class org.joda.time.base.AbstractPeriod
equals, get, getFieldType, getFieldTypes, getValues, hashCode, indexOf, isSupported, size, toMutablePeriod, toPeriod, toString, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.time.ReadablePeriod
equals, get, getFieldType, getPeriodType, getValue, hashCode, isSupported, size, toMutablePeriod, toPeriod, toString
 

Constructor Detail

MutablePeriod

public MutablePeriod()
Creates a zero-length period using the standard period type.


MutablePeriod

public MutablePeriod(PeriodType type)
Creates a zero-length period using the specified period type.

Parameters:
type - which set of fields this period supports

MutablePeriod

public MutablePeriod(int hours,
                     int minutes,
                     int seconds,
                     int millis)
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

MutablePeriod

public MutablePeriod(int years,
                     int months,
                     int weeks,
                     int days,
                     int hours,
                     int minutes,
                     int seconds,
                     int millis)
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

MutablePeriod

public MutablePeriod(int years,
                     int months,
                     int weeks,
                     int days,
                     int hours,
                     int minutes,
                     int seconds,
                     int millis,
                     PeriodType type)
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

MutablePeriod

public MutablePeriod(long duration)
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:

Parameters:
duration - the duration, in milliseconds

MutablePeriod

public MutablePeriod(long duration,
                     PeriodType type)
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

MutablePeriod

public MutablePeriod(long duration,
                     Chronology chronology)
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

MutablePeriod

public MutablePeriod(long duration,
                     PeriodType type,
                     Chronology chronology)
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

MutablePeriod

public MutablePeriod(long startInstant,
                     long endInstant)
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

MutablePeriod

public MutablePeriod(long startInstant,
                     long endInstant,
                     PeriodType type)
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

MutablePeriod

public MutablePeriod(long startInstant,
                     long endInstant,
                     Chronology chrono)
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

MutablePeriod

public MutablePeriod(long startInstant,
                     long endInstant,
                     PeriodType type,
                     Chronology chrono)
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

MutablePeriod

public MutablePeriod(ReadableInstant startInstant,
                     ReadableInstant endInstant)
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

MutablePeriod

public MutablePeriod(ReadableInstant startInstant,
                     ReadableInstant endInstant,
                     PeriodType type)
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

MutablePeriod

public MutablePeriod(ReadableInstant startInstant,
                     ReadableDuration duration)
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

MutablePeriod

public MutablePeriod(ReadableInstant startInstant,
                     ReadableDuration duration,
                     PeriodType type)
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

MutablePeriod

public MutablePeriod(ReadableDuration duration,
                     ReadableInstant endInstant)
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

MutablePeriod

public MutablePeriod(ReadableDuration duration,
                     ReadableInstant endInstant,
                     PeriodType type)
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

MutablePeriod

public MutablePeriod(Object period)
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

MutablePeriod

public MutablePeriod(Object period,
                     PeriodType type)
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

MutablePeriod

public MutablePeriod(Object period,
                     Chronology chrono)
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

MutablePeriod

public MutablePeriod(Object period,
                     PeriodType type,
                     Chronology chrono)
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
Method Detail

parse

public static MutablePeriod parse(String str)
Parses a MutablePeriod from the specified string.

This uses ISOPeriodFormat.standard().

Parameters:
str - the string to parse, not null
Since:
2.0

parse

public static MutablePeriod parse(String str,
                                  PeriodFormatter formatter)
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

clear

public void clear()
Clears the period, setting all values back to zero.

Specified by:
clear in interface ReadWritablePeriod

setValue

public void setValue(int index,
                     int value)
Sets the value of one of the fields by index.

Specified by:
setValue in interface ReadWritablePeriod
Overrides:
setValue in class BasePeriod
Parameters:
index - the field index
value - the new value for the field
Throws:
IndexOutOfBoundsException - if the index is invalid

set

public void set(DurationFieldType field,
                int value)
Sets the value of one of the fields.

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

Specified by:
set in interface ReadWritablePeriod
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

setPeriod

public void setPeriod(ReadablePeriod period)
Sets all the fields in one go from another ReadablePeriod.

Specified by:
setPeriod in interface ReadWritablePeriod
Overrides:
setPeriod in class BasePeriod
Parameters:
period - the period to set, null means zero length period
Throws:
IllegalArgumentException - if an unsupported field's value is non-zero

setPeriod

public void setPeriod(int years,
                      int months,
                      int weeks,
                      int days,
                      int hours,
                      int minutes,
                      int seconds,
                      int millis)
Sets all the fields in one go.

Specified by:
setPeriod in interface ReadWritablePeriod
Overrides:
setPeriod in class BasePeriod
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

setPeriod

public void setPeriod(ReadableInterval interval)
Sets all the fields in one go from an interval using the ISO chronology and dividing the fields using the period type.

Specified by:
setPeriod in interface ReadWritablePeriod
Parameters:
interval - the interval to set, null means zero length
Throws:
ArithmeticException - if the set exceeds the capacity of the period

setPeriod

public void setPeriod(ReadableInstant start,
                      ReadableInstant end)
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

setPeriod

public void setPeriod(long startInstant,
                      long endInstant)
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

setPeriod

public void setPeriod(long startInstant,
                      long endInstant,
                      Chronology chrono)
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, null means ISO chronology
Throws:
ArithmeticException - if the set exceeds the capacity of the period

setPeriod

public void setPeriod(ReadableDuration duration)
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

setPeriod

public void setPeriod(ReadableDuration duration,
                      Chronology chrono)
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

setPeriod

public void setPeriod(long duration)
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

setPeriod

public void setPeriod(long duration,
                      Chronology chrono)
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, null means ISO chronology
Throws:
ArithmeticException - if the set exceeds the capacity of the period

add

public void add(DurationFieldType field,
                int value)
Adds to the value of one of the fields.

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

Specified by:
add in interface ReadWritablePeriod
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

add

public void add(ReadablePeriod period)
Adds a period to this one by adding each field in turn.

Specified by:
add in interface ReadWritablePeriod
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

add

public void add(int years,
                int months,
                int weeks,
                int days,
                int hours,
                int minutes,
                int seconds,
                int millis)
Adds to each field of this period.

Specified by:
add in interface ReadWritablePeriod
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

add

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

Specified by:
add in interface ReadWritablePeriod
Parameters:
interval - the interval to add, null means add nothing
Throws:
ArithmeticException - if the addition exceeds the capacity of the period

add

public void add(ReadableDuration duration)
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

add

public void add(long duration)
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

add

public void add(long duration,
                Chronology chrono)
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

mergePeriod

public void mergePeriod(ReadablePeriod period)
Merges all the fields from the specified period into this one.

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

Overrides:
mergePeriod in class BasePeriod
Parameters:
period - the period to set, null ignored
Throws:
IllegalArgumentException - if an unsupported field's value is non-zero

getYears

public int getYears()
Gets the years field part of the period.

Returns:
the number of years in the period, zero if unsupported

getMonths

public int getMonths()
Gets the months field part of the period.

Returns:
the number of months in the period, zero if unsupported

getWeeks

public int getWeeks()
Gets the weeks field part of the period.

Returns:
the number of weeks in the period, zero if unsupported

getDays

public int getDays()
Gets the days field part of the period.

Returns:
the number of days in the period, zero if unsupported

getHours

public int getHours()
Gets the hours field part of the period.

Returns:
the number of hours in the period, zero if unsupported

getMinutes

public int getMinutes()
Gets the minutes field part of the period.

Returns:
the number of minutes in the period, zero if unsupported

getSeconds

public int getSeconds()
Gets the seconds field part of the period.

Returns:
the number of seconds in the period, zero if unsupported

getMillis

public int getMillis()
Gets the millis field part of the period.

Returns:
the number of millis in the period, zero if unsupported

setYears

public void setYears(int years)
Sets the number of years of the period.

Specified by:
setYears in interface ReadWritablePeriod
Parameters:
years - the number of years
Throws:
IllegalArgumentException - if field is not supported and the value is non-zero

addYears

public void addYears(int years)
Adds the specified years to the number of years in the period.

Specified by:
addYears in interface ReadWritablePeriod
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

setMonths

public void setMonths(int months)
Sets the number of months of the period.

Specified by:
setMonths in interface ReadWritablePeriod
Parameters:
months - the number of months
Throws:
IllegalArgumentException - if field is not supported and the value is non-zero

addMonths

public void addMonths(int months)
Adds the specified months to the number of months in the period.

Specified by:
addMonths in interface ReadWritablePeriod
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

setWeeks

public void setWeeks(int weeks)
Sets the number of weeks of the period.

Specified by:
setWeeks in interface ReadWritablePeriod
Parameters:
weeks - the number of weeks
Throws:
IllegalArgumentException - if field is not supported and the value is non-zero

addWeeks

public void addWeeks(int weeks)
Adds the specified weeks to the number of weeks in the period.

Specified by:
addWeeks in interface ReadWritablePeriod
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

setDays

public void setDays(int days)
Sets the number of days of the period.

Specified by:
setDays in interface ReadWritablePeriod
Parameters:
days - the number of days
Throws:
IllegalArgumentException - if field is not supported and the value is non-zero

addDays

public void addDays(int days)
Adds the specified days to the number of days in the period.

Specified by:
addDays in interface ReadWritablePeriod
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

setHours

public void setHours(int hours)
Sets the number of hours of the period.

Specified by:
setHours in interface ReadWritablePeriod
Parameters:
hours - the number of hours
Throws:
IllegalArgumentException - if field is not supported and the value is non-zero

addHours

public void addHours(int hours)
Adds the specified hours to the number of hours in the period.

Specified by:
addHours in interface ReadWritablePeriod
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

setMinutes

public void setMinutes(int minutes)
Sets the number of minutes of the period.

Specified by:
setMinutes in interface ReadWritablePeriod
Parameters:
minutes - the number of minutes
Throws:
IllegalArgumentException - if field is not supported and the value is non-zero

addMinutes

public void addMinutes(int minutes)
Adds the specified minutes to the number of minutes in the period.

Specified by:
addMinutes in interface ReadWritablePeriod
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

setSeconds

public void setSeconds(int seconds)
Sets the number of seconds of the period.

Specified by:
setSeconds in interface ReadWritablePeriod
Parameters:
seconds - the number of seconds
Throws:
IllegalArgumentException - if field is not supported and the value is non-zero

addSeconds

public void addSeconds(int seconds)
Adds the specified seconds to the number of seconds in the period.

Specified by:
addSeconds in interface ReadWritablePeriod
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

setMillis

public void setMillis(int millis)
Sets the number of millis of the period.

Specified by:
setMillis in interface ReadWritablePeriod
Parameters:
millis - the number of millis
Throws:
IllegalArgumentException - if field is not supported and the value is non-zero

addMillis

public void addMillis(int millis)
Adds the specified millis to the number of millis in the period.

Specified by:
addMillis in interface ReadWritablePeriod
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

copy

public MutablePeriod copy()
Clone this object without having to cast the returned object.

Returns:
a clone of the this object.

clone

public Object clone()
Clone this object.

Overrides:
clone in class Object
Returns:
a clone of this object.


Copyright © 2002-2013 Joda.org. All Rights Reserved.