Controls a period implementation by specifying which duration fields are to be used.
The following implementations are provided:
- Standard - years, months, weeks, days, hours, minutes, seconds, millis
- YearMonthDayTime - years, months, days, hours, minutes, seconds, millis
- YearMonthDay - years, months, days
- YearWeekDayTime - years, weeks, days, hours, minutes, seconds, millis
- YearWeekDay - years, weeks, days
- YearDayTime - years, days, hours, minutes, seconds, millis
- YearDay - years, days, hours
- DayTime - days, hours, minutes, seconds, millis
- Time - hours, minutes, seconds, millis
- plus one for each single type
PeriodType is thread-safe and immutable, and all subclasses must be as well.
dayTime
public static PeriodType dayTime()
Gets a type that defines all standard fields from days downwards.
- days
- hours
- minutes
- seconds
- milliseconds
days
public static PeriodType days()
Gets a type that defines just the days field.
equals
public boolean equals(Object obj)
Compares this type to another object.
To be equal, the object must be a PeriodType with the same set of fields.
obj
- the object to compare to
forFields
public static PeriodType forFields(DurationFieldType[] types)
Gets a period type that contains the duration types of the array.
Only the 8 standard duration field types are supported.
types
- the types to include in the array.
getFieldType
public DurationFieldType getFieldType(int index)
Gets the field type by index.
index
- the index to retrieve
getName
public String getName()
Gets the name of the period type.
hashCode
public int hashCode()
Returns a hashcode based on the field types.
hours
public static PeriodType hours()
Gets a type that defines just the hours field.
indexOf
public int indexOf(DurationFieldType type)
Gets the index of the field in this period.
type
- the type to check, may be null which returns -1
- the index of -1 if not supported
isSupported
public boolean isSupported(DurationFieldType type)
Checks whether the field specified is supported by this period.
type
- the type to check, may be null which returns false
- true if the field is supported
millis
public static PeriodType millis()
Gets a type that defines just the millis field.
minutes
public static PeriodType minutes()
Gets a type that defines just the minutes field.
months
public static PeriodType months()
Gets a type that defines just the months field.
seconds
public static PeriodType seconds()
Gets a type that defines just the seconds field.
size
public int size()
Gets the number of fields in the period type.
standard
public static PeriodType standard()
Gets a type that defines all standard fields.
- years
- months
- weeks
- days
- hours
- minutes
- seconds
- milliseconds
time
public static PeriodType time()
Gets a type that defines all standard time fields.
- hours
- minutes
- seconds
- milliseconds
toString
public String toString()
Gets a debugging to string.
weeks
public static PeriodType weeks()
Gets a type that defines just the weeks field.
withDaysRemoved
public PeriodType withDaysRemoved()
Returns a version of this PeriodType instance that does not support days.
- a new period type that supports the original set of fields except days
withHoursRemoved
public PeriodType withHoursRemoved()
Returns a version of this PeriodType instance that does not support hours.
- a new period type that supports the original set of fields except hours
withMillisRemoved
public PeriodType withMillisRemoved()
Returns a version of this PeriodType instance that does not support milliseconds.
- a new period type that supports the original set of fields except milliseconds
withMinutesRemoved
public PeriodType withMinutesRemoved()
Returns a version of this PeriodType instance that does not support minutes.
- a new period type that supports the original set of fields except minutes
withMonthsRemoved
public PeriodType withMonthsRemoved()
Returns a version of this PeriodType instance that does not support months.
- a new period type that supports the original set of fields except months
withSecondsRemoved
public PeriodType withSecondsRemoved()
Returns a version of this PeriodType instance that does not support seconds.
- a new period type that supports the original set of fields except seconds
withWeeksRemoved
public PeriodType withWeeksRemoved()
Returns a version of this PeriodType instance that does not support weeks.
- a new period type that supports the original set of fields except weeks
withYearsRemoved
public PeriodType withYearsRemoved()
Returns a version of this PeriodType instance that does not support years.
- a new period type that supports the original set of fields except years
yearDay
public static PeriodType yearDay()
Gets a type that defines the year and day fields.
yearDayTime
public static PeriodType yearDayTime()
Gets a type that defines all standard fields except months and weeks.
- years
- days
- hours
- minutes
- seconds
- milliseconds
yearMonthDay
public static PeriodType yearMonthDay()
Gets a type that defines the year, month and day fields.
yearMonthDayTime
public static PeriodType yearMonthDayTime()
Gets a type that defines all standard fields except weeks.
- years
- months
- days
- hours
- minutes
- seconds
- milliseconds
yearWeekDay
public static PeriodType yearWeekDay()
Gets a type that defines year, week and day fields.
yearWeekDayTime
public static PeriodType yearWeekDayTime()
Gets a type that defines all standard fields except months.
- years
- weeks
- days
- hours
- minutes
- seconds
- milliseconds
years
public static PeriodType years()
Gets a type that defines just the years field.