java.lang.Object | ||
↳ | org.joda.time.base.AbstractPartial | |
↳ | org.joda.time.Partial |
Partial is an immutable partial datetime supporting any set of datetime fields.
A Partial instance can be used to hold any combination of fields. The instance does not contain a time zone, so any datetime is local.
A Partial can be matched against an instant using isMatch(ReadableInstant)
.
This method compares each field on this partial with those of the instant
and determines if the partial matches the instant.
Given this definition, an empty Partial instance represents any datetime
and always matches.
Calculations on Partial are performed using a Chronology
.
This chronology is set to be in the UTC time zone for all calculations.
Each individual field can be queried in two ways:
get(DateTimeFieldType.monthOfYear())
property(DateTimeFieldType.monthOfYear()).get()
monthOfYear().get()
monthOfYear().getAsText()
monthOfYear().getAsShortText()
monthOfYear().getMaximumValue()
monthOfYear().addToCopy()
monthOfYear().setCopy()
Partial is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Partial.Property | The property class for Partial . |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a Partial with no fields or values, which can be considered
to represent any date.
| |||||||||||
Constructs a Partial with no fields or values, which can be considered
to represent any date.
| |||||||||||
Constructs a Partial with the specified field and value.
| |||||||||||
Constructs a Partial with the specified field and value.
| |||||||||||
Constructs a Partial with the specified fields and values.
| |||||||||||
Constructs a Partial with the specified fields and values.
| |||||||||||
Constructs a Partial by copying all the fields and types from
another partial.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the chronology of the partial which is never null.
| |||||||||||
Gets the field type at the specified index.
| |||||||||||
Gets an array of the field type of each of the fields that
this partial supports.
| |||||||||||
Gets a formatter suitable for the fields in this partial.
| |||||||||||
Gets the value of the field at the specifed index.
| |||||||||||
Gets an array of the value of each of the fields that
this partial supports.
| |||||||||||
Does this partial match the specified instant.
| |||||||||||
Does this partial match the specified partial.
| |||||||||||
Gets a copy of this instance with the specified period take away.
| |||||||||||
Gets a copy of this instance with the specified period added.
| |||||||||||
Gets the property object for the specified type, which contains
many useful methods for getting and manipulating the partial.
| |||||||||||
Gets the number of fields in this partial.
| |||||||||||
Output the date in an appropriate ISO8601 format.
| |||||||||||
Output the date using the specified format pattern.
| |||||||||||
Output the date using the specified format pattern.
| |||||||||||
Gets a string version of the partial that lists all the fields.
| |||||||||||
Gets a copy of this date with the specified field set to a new value.
| |||||||||||
Creates a new Partial instance with the specified chronology.
| |||||||||||
Gets a copy of this Partial with the specified field set to a new value.
| |||||||||||
Gets a copy of this Partial with the value of the specified field increased.
| |||||||||||
Gets a copy of this Partial with the value of the specified field increased.
| |||||||||||
Gets a copy of this Partial with the specified period added.
| |||||||||||
Gets a copy of this date with the specified field removed.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the field for a specific index in the chronology specified.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.joda.time.base.AbstractPartial
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Comparable
| |||||||||||
From interface
org.joda.time.ReadablePartial
|
Constructs a Partial with no fields or values, which can be considered to represent any date.
This is most useful when constructing partials, for example:
Partial p = new Partial() .with(DateTimeFieldType.dayOfWeek(), 5) .with(DateTimeFieldType.hourOfDay(), 12) .with(DateTimeFieldType.minuteOfHour(), 20);Note that, although this is a clean way to write code, it is fairly inefficient internally.
The constructor uses the default ISO chronology.
Constructs a Partial with no fields or values, which can be considered to represent any date.
This is most useful when constructing partials, for example:
Partial p = new Partial(chrono) .with(DateTimeFieldType.dayOfWeek(), 5) .with(DateTimeFieldType.hourOfDay(), 12) .with(DateTimeFieldType.minuteOfHour(), 20);Note that, although this is a clean way to write code, it is fairly inefficient internally.
chrono | the chronology, null means ISO |
---|
Constructs a Partial with the specified field and value.
The constructor uses the default ISO chronology.
type | the single type to create the partial from, not null |
---|---|
value | the value to store |
IllegalArgumentException | if the type or value is invalid |
---|
Constructs a Partial with the specified field and value.
The constructor uses the specified chronology.
type | the single type to create the partial from, not null |
---|---|
value | the value to store |
chronology | the chronology, null means ISO |
IllegalArgumentException | if the type or value is invalid |
---|
Constructs a Partial with the specified fields and values. The fields must be specified in the order largest to smallest.
The constructor uses the specified chronology.
types | the types to create the partial from, not null |
---|---|
values | the values to store, not null |
IllegalArgumentException | if the types or values are invalid |
---|
Constructs a Partial with the specified fields and values. The fields must be specified in the order largest to smallest.
The constructor uses the specified chronology.
types | the types to create the partial from, not null |
---|---|
values | the values to store, not null |
chronology | the chronology, null means ISO |
IllegalArgumentException | if the types or values are invalid |
---|
Constructs a Partial by copying all the fields and types from another partial.
This is most useful when copying from a YearMonthDay or TimeOfDay.
Gets the chronology of the partial which is never null.
The Chronology
is the calculation engine behind the partial and
provides conversion and validation of the fields in a particular calendar system.
Gets the field type at the specified index.
index | the index to retrieve |
---|
IndexOutOfBoundsException | if the index is invalid |
---|
Gets an array of the field type of each of the fields that this partial supports.
The fields are returned largest to smallest.
Gets a formatter suitable for the fields in this partial.
If there is no appropriate ISO format, null is returned. This method may return a formatter that does not display all the fields of the partial. This might occur when you have overlapping fields, such as dayOfWeek and dayOfMonth.
Gets the value of the field at the specifed index.
index | the index |
---|
IndexOutOfBoundsException | if the index is invalid |
---|
Gets an array of the value of each of the fields that this partial supports.
The fields are returned largest to smallest.
Each value corresponds to the same array index as getFieldTypes()
Does this partial match the specified instant.
A match occurs when all the fields of this partial are the same as the corresponding fields on the specified instant.
instant | an instant to check against, null means now in default zone |
---|
Does this partial match the specified partial.
A match occurs when all the fields of this partial are the same as the corresponding fields on the specified partial.
partial | a partial to check against, must not be null |
---|
IllegalArgumentException | if the partial is null |
---|---|
IllegalArgumentException | if the fields of the two partials do not match |
Gets a copy of this instance with the specified period take away.
If the amount is zero or null, then this
is returned.
period | the period to reduce this instant by |
---|
ArithmeticException | if the new datetime exceeds the capacity of a long |
---|
Gets a copy of this instance with the specified period added.
If the amount is zero or null, then this
is returned.
period | the duration to add to this one, null means zero |
---|
ArithmeticException | if the new datetime exceeds the capacity of a long |
---|
Gets the property object for the specified type, which contains many useful methods for getting and manipulating the partial.
See also get(DateTimeFieldType)
.
type | the field type to get the property for, not null |
---|
IllegalArgumentException | if the field is null or unsupported |
---|
Gets the number of fields in this partial.
Output the date in an appropriate ISO8601 format.
This method will output the partial in one of two ways.
If getFormatter()
If there is no appropriate ISO format a dump of the fields is output
via toStringList()
.
Output the date using the specified format pattern. Unsupported fields will appear as special unicode characters.
pattern | the pattern specification, null means use toString |
---|---|
locale | Locale to use, null means default |
Output the date using the specified format pattern. Unsupported fields will appear as special unicode characters.
pattern | the pattern specification, null means use toString |
---|
Gets a string version of the partial that lists all the fields.
This method exists to provide a better debugging toString than the standard toString. This method lists all the fields and their values in a style similar to the collections framework.
Gets a copy of this date with the specified field set to a new value.
If this partial did not previously support the field, the new one will.
Contrast this behaviour with withField(DateTimeFieldType, int)
.
For example, if the field type is dayOfMonth
then the day
would be changed/added in the returned instance.
fieldType | the field type to set, not null |
---|---|
value | the value to set |
IllegalArgumentException | if the value is null or invalid |
---|
Creates a new Partial instance with the specified chronology. This instance is immutable and unaffected by this method call.
This method retains the values of the fields, thus the result will typically refer to a different instant.
The time zone of the specified chronology is ignored, as Partial operates without a time zone.
newChronology | the new chronology, null means ISO |
---|
IllegalArgumentException | if the values are invalid for the new chronology |
---|
Gets a copy of this Partial with the specified field set to a new value.
If this partial does not support the field, an exception is thrown.
Contrast this behaviour with with(DateTimeFieldType, int)
.
For example, if the field type is dayOfMonth
then the day
would be changed in the returned instance if supported.
fieldType | the field type to set, not null |
---|---|
value | the value to set |
IllegalArgumentException | if the value is null or invalid |
---|
Gets a copy of this Partial with the value of the specified field increased. If this partial does not support the field, an exception is thrown.
If the addition is zero, then this
is returned.
The addition will overflow into larger fields (eg. minute to hour).
If the maximum is reached, the addition will wra.
fieldType | the field type to add to, not null |
---|---|
amount | the amount to add |
IllegalArgumentException | if the value is null or invalid |
---|---|
ArithmeticException | if the new datetime exceeds the capacity |
Gets a copy of this Partial with the value of the specified field increased. If this partial does not support the field, an exception is thrown.
If the addition is zero, then this
is returned.
The addition will overflow into larger fields (eg. minute to hour).
However, it will not wrap around if the top maximum is reached.
fieldType | the field type to add to, not null |
---|---|
amount | the amount to add |
IllegalArgumentException | if the value is null or invalid |
---|---|
ArithmeticException | if the new datetime exceeds the capacity |
Gets a copy of this Partial with the specified period added.
If the addition is zero, then this
is returned.
Fields in the period that aren't present in the partial are ignored.
This method is typically used to add multiple copies of complex
period instances. Adding one field is best achieved using the method
withFieldAdded(DurationFieldType, int)
.
period | the period to add to this one, null means zero |
---|---|
scalar | the amount of times to add, such as -1 to subtract once |
ArithmeticException | if the new datetime exceeds the capacity |
---|
Gets a copy of this date with the specified field removed.
If this partial did not previously support the field, no error occurs.
fieldType | the field type to remove, may be null |
---|
Gets the field for a specific index in the chronology specified.
index | the index to retrieve |
---|---|
chrono | the chronology to use |
IndexOutOfBoundsException | if the index is invalid |
---|