java.lang.Object | |||
↳ | org.joda.time.base.AbstractPeriod | ||
↳ | org.joda.time.base.BasePeriod | ||
↳ | org.joda.time.MutablePeriod |
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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a zero-length period using the standard period type.
| |||||||||||
Creates a zero-length period using the specified period type.
| |||||||||||
Create a period from a set of field values using the standard set of fields.
| |||||||||||
Create a period from a set of field values using the standard set of fields.
| |||||||||||
Create a period from a set of field values.
| |||||||||||
Creates a period from the given millisecond duration using the standard
set of fields.
| |||||||||||
Creates a period from the given millisecond duration.
| |||||||||||
Creates a period from the given millisecond duration using the standard
set of fields.
| |||||||||||
Creates a period from the given millisecond duration.
| |||||||||||
Creates a period from the given interval endpoints using the standard
set of fields.
| |||||||||||
Creates a period from the given interval endpoints.
| |||||||||||
Creates a period from the given interval endpoints using the standard
set of fields.
| |||||||||||
Creates a period from the given interval endpoints.
| |||||||||||
Creates a period from the given interval endpoints using the standard
set of fields.
| |||||||||||
Creates a period from the given interval endpoints.
| |||||||||||
Creates a period from the given start point and the duration.
| |||||||||||
Creates a period from the given start point and the duration.
| |||||||||||
Creates a period from the given duration and end point.
| |||||||||||
Creates a period from the given duration and end point.
| |||||||||||
Creates a period by converting or copying from another object.
| |||||||||||
Creates a period by converting or copying from another object.
| |||||||||||
Creates a period by converting or copying from another object.
| |||||||||||
Creates a period by converting or copying from another object.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a duration to this one by dividing the duration into
fields and calling
add(ReadablePeriod) . | |||||||||||
Adds to each field of this period.
| |||||||||||
Adds a millisecond duration to this one by dividing the duration into
fields and calling
add(ReadablePeriod) . | |||||||||||
Adds a period to this one by adding each field in turn.
| |||||||||||
Adds an interval to this one by dividing the interval into
fields and calling
add(ReadablePeriod) . | |||||||||||
Adds a millisecond duration to this one by dividing the duration into
fields and calling
add(ReadablePeriod) . | |||||||||||
Adds to the value of one of the fields.
| |||||||||||
Adds the specified days to the number of days in the period.
| |||||||||||
Adds the specified hours to the number of hours in the period.
| |||||||||||
Adds the specified millis to the number of millis in the period.
| |||||||||||
Adds the specified minutes to the number of minutes in the period.
| |||||||||||
Adds the specified months to the number of months in the period.
| |||||||||||
Adds the specified seconds to the number of seconds in the period.
| |||||||||||
Adds the specified weeks to the number of weeks in the period.
| |||||||||||
Adds the specified years to the number of years in the period.
| |||||||||||
Clears the period, setting all values back to zero.
| |||||||||||
Clone this object.
| |||||||||||
Clone this object without having to cast the returned object.
| |||||||||||
Gets the days field part of the period.
| |||||||||||
Gets the hours field part of the period.
| |||||||||||
Gets the millis field part of the period.
| |||||||||||
Gets the minutes field part of the period.
| |||||||||||
Gets the months field part of the period.
| |||||||||||
Gets the seconds field part of the period.
| |||||||||||
Gets the weeks field part of the period.
| |||||||||||
Gets the years field part of the period.
| |||||||||||
Merges all the fields from the specified period into this one.
| |||||||||||
Sets the value of one of the fields.
| |||||||||||
Sets the number of days of the period.
| |||||||||||
Sets the number of hours of the period.
| |||||||||||
Sets the number of millis of the period.
| |||||||||||
Sets the number of minutes of the period.
| |||||||||||
Sets the number of months of the period.
| |||||||||||
Sets all the fields in one go from a duration dividing the
fields using the period type.
| |||||||||||
Sets all the fields in one go from a duration dividing the
fields using the period type.
| |||||||||||
Sets all the fields in one go from another ReadablePeriod.
| |||||||||||
Sets all the fields in one go from a millisecond interval using ISOChronology
and dividing the fields using the period type.
| |||||||||||
Sets all the fields in one go from a millisecond duration.
| |||||||||||
Sets all the fields in one go from two instants representing an interval.
| |||||||||||
Sets all the fields in one go from a millisecond duration dividing the
fields using the period type.
| |||||||||||
Sets all the fields in one go from an interval using the ISO chronology
and dividing the fields using the period type.
| |||||||||||
Sets all the fields in one go from a millisecond interval.
| |||||||||||
Sets all the fields in one go.
| |||||||||||
Sets the number of seconds of the period.
| |||||||||||
Sets the value of one of the fields by index.
| |||||||||||
Sets the number of weeks of the period.
| |||||||||||
Sets the number of years of the period.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.joda.time.base.BasePeriod
| |||||||||||
From class
org.joda.time.base.AbstractPeriod
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.joda.time.ReadWritablePeriod
| |||||||||||
From interface
org.joda.time.ReadablePeriod
|
Creates a zero-length period using the standard period type.
Creates a zero-length period using the specified period type.
type | which set of fields this period supports |
---|
Create a period from a set of field values using the standard set of fields.
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 |
Create a period from a set of field values using the standard set of fields.
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 |
Create a period from a set of field values.
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 |
IllegalArgumentException | if an unsupported field's value is non-zero |
---|
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:
Interval
, and from there obtain the period
duration | the duration, in milliseconds |
---|
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.
duration | the duration, in milliseconds |
---|---|
type | which set of fields this period supports, null means standard |
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.
duration | the duration, in milliseconds |
---|---|
chronology | the chronology to use to split the duration, null means ISO default |
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.
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 |
Creates a period from the given interval endpoints using the standard set of fields.
startInstant | interval start, in milliseconds |
---|---|
endInstant | interval end, in milliseconds |
Creates a period from the given interval endpoints.
startInstant | interval start, in milliseconds |
---|---|
endInstant | interval end, in milliseconds |
type | which set of fields this period supports, null means standard |
Creates a period from the given interval endpoints using the standard set of fields.
startInstant | interval start, in milliseconds |
---|---|
endInstant | interval end, in milliseconds |
chrono | the chronology to use, null means ISO in default zone |
Creates a period from the given interval endpoints.
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 |
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.
startInstant | interval start, null means now |
---|---|
endInstant | interval end, null means now |
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.
startInstant | interval start, null means now |
---|---|
endInstant | interval end, null means now |
type | which set of fields this period supports, null means AllType |
Creates a period from the given start point and the duration.
startInstant | the interval start, null means now |
---|---|
duration | the duration of the interval, null means zero-length |
Creates a period from the given start point and the duration.
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 |
Creates a period from the given duration and end point.
duration | the duration of the interval, null means zero-length |
---|---|
endInstant | the interval end, null means now |
Creates a period from the given duration and end point.
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 |
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 standard()
.
period | period to convert |
---|
IllegalArgumentException | if period is invalid |
---|---|
UnsupportedOperationException | if an unsupported field's value is non-zero |
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 standard()
.
period | period to convert |
---|---|
type | which set of fields this period supports, null means use converter |
IllegalArgumentException | if period is invalid |
---|---|
UnsupportedOperationException | if an unsupported field's value is non-zero |
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 standard()
.
period | period to convert |
---|---|
chrono | the chronology to use, null means ISO in default zone |
IllegalArgumentException | if period is invalid |
---|---|
UnsupportedOperationException | if an unsupported field's value is non-zero |
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 standard()
.
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 |
IllegalArgumentException | if period is invalid |
---|---|
UnsupportedOperationException | if an unsupported field's value is non-zero |
Adds a duration to this one by dividing the duration into
fields and calling add(ReadablePeriod)
.
duration | the duration to add, null means add nothing |
---|
ArithmeticException | if the addition exceeds the capacity of the period |
---|
Adds to each field of this period.
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 |
IllegalArgumentException | if the period being added contains a field not supported by this period |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
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.
duration | the duration, in milliseconds |
---|
ArithmeticException | if the addition exceeds the capacity of the period |
---|
Adds a period to this one by adding each field in turn.
period | the period to add, null means add nothing |
---|
IllegalArgumentException | if the period being added contains a field not supported by this period |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Adds an interval to this one by dividing the interval into
fields and calling add(ReadablePeriod)
.
interval | the interval to add, null means add nothing |
---|
ArithmeticException | if the addition exceeds the capacity of the period |
---|
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.
duration | the duration, in milliseconds |
---|---|
chrono | the chronology to use, null means ISO default |
ArithmeticException | if the addition exceeds the capacity of the period |
---|
Adds to the value of one of the fields.
The field type specified must be one of those that is supported by the period.
field | a DurationFieldType instance that is supported by this period, not null |
---|---|
value | the value to add to the field |
IllegalArgumentException | if the field is null or not supported |
---|
Adds the specified days to the number of days in the period.
days | the number of days |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Adds the specified hours to the number of hours in the period.
hours | the number of hours |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Adds the specified millis to the number of millis in the period.
millis | the number of millis |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Adds the specified minutes to the number of minutes in the period.
minutes | the number of minutes |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Adds the specified months to the number of months in the period.
months | the number of months |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Adds the specified seconds to the number of seconds in the period.
seconds | the number of seconds |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Adds the specified weeks to the number of weeks in the period.
weeks | the number of weeks |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Adds the specified years to the number of years in the period.
years | the number of years |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|---|
ArithmeticException | if the addition exceeds the capacity of the period |
Clears the period, setting all values back to zero.
Clone this object without having to cast the returned object.
Gets the days field part of the period.
Gets the hours field part of the period.
Gets the millis field part of the period.
Gets the minutes field part of the period.
Gets the months field part of the period.
Gets the seconds field part of the period.
Gets the weeks field part of the period.
Gets the years field part of the period.
Merges all the fields from the specified period into this one.
Fields that are not present in the specified period are left unaltered.
period | the period to set, null ignored |
---|
IllegalArgumentException | if an unsupported field's value is non-zero |
---|
Sets the value of one of the fields.
The field type specified must be one of those that is supported by the period.
field | a DurationFieldType instance that is supported by this period, not null |
---|---|
value | the new value for the field |
IllegalArgumentException | if the field is null or not supported |
---|
Sets the number of days of the period.
days | the number of days |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|
Sets the number of hours of the period.
hours | the number of hours |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|
Sets the number of millis of the period.
millis | the number of millis |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|
Sets the number of minutes of the period.
minutes | the number of minutes |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|
Sets the number of months of the period.
months | the number of months |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|
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.
duration | the duration to set, null means zero length |
---|
ArithmeticException | if the set exceeds the capacity of the period |
---|
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.
duration | the duration to set, null means zero length |
---|---|
chrono | the chronology to use, null means ISO default |
ArithmeticException | if the set exceeds the capacity of the period |
---|
Sets all the fields in one go from another ReadablePeriod.
period | the period to set, null means zero length period |
---|
IllegalArgumentException | if an unsupported field's value is non-zero |
---|
Sets all the fields in one go from a millisecond interval using ISOChronology and dividing the fields using the period type.
startInstant | interval start, in milliseconds |
---|---|
endInstant | interval end, in milliseconds |
ArithmeticException | if the set exceeds the capacity of the period |
---|
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.
duration | the duration, in milliseconds |
---|---|
chrono | the chronology to use, not null |
ArithmeticException | if the set exceeds the capacity of the period |
---|
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.
start | the start instant, null means now |
---|---|
end | the end instant, null means now |
ArithmeticException | if the set exceeds the capacity of the period |
---|
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.
duration | the duration, in milliseconds |
---|
ArithmeticException | if the set exceeds the capacity of the period |
---|
Sets all the fields in one go from an interval using the ISO chronology and dividing the fields using the period type.
interval | the interval to set, null means zero length |
---|
ArithmeticException | if the set exceeds the capacity of the period |
---|
Sets all the fields in one go from a millisecond interval.
startInstant | interval start, in milliseconds |
---|---|
endInstant | interval end, in milliseconds |
chrono | the chronology to use, not null |
ArithmeticException | if the set exceeds the capacity of the period |
---|
Sets all the fields in one go.
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 |
IllegalArgumentException | if an unsupported field's value is non-zero |
---|
Sets the number of seconds of the period.
seconds | the number of seconds |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|
Sets the value of one of the fields by index.
index | the field index |
---|---|
value | the new value for the field |
IndexOutOfBoundsException | if the index is invalid |
---|
Sets the number of weeks of the period.
weeks | the number of weeks |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|
Sets the number of years of the period.
years | the number of years |
---|
IllegalArgumentException | if field is not supported and the value is non-zero |
---|