public enum CalendarUnit extends Enum<CalendarUnit> implements IsoDateUnit
Represents the most common time units related to a standard ISO-8601-calendar.
Default behaviour of addition or subtraction of month-related units:
If the addition of months results in an invalid intermediate date then the final date will be just the last valid date that is the last day of current month. Example:
PlainDate date = PlainDate.of(2013, 1, 31); System.out.println(date.plus(1, MONTHS)); // Output: 2013-02-28
| Enum Constant and Description |
|---|
CENTURIES
Time unit "centuries" (symbol C)
|
DAYS
Time unit "days" (symbol D)
|
DECADES
Time unit "decades" (symbol E)
|
MILLENNIA
Time unit "millennia" (symbol I)
|
MONTHS
Time unit "months" (symbol M)
|
QUARTERS
Time unit "quarter years" (symbol Q)
|
WEEKS
Time unit "weeks" (symbol W)
|
YEARS
Time unit "calendar years" (symbol Y)
|
| Modifier and Type | Method and Description |
|---|---|
IsoDateUnit |
atEndOfMonth()
Defines a variation of this unit which always sets the resulting
date in additions and subtractions to the end of month even if there
is no day overflow.
|
<T extends TimePoint<? super CalendarUnit,T>> |
between(T start,
T end)
Calculates the temporal distance between given calendar dates
in this calendar unit.
|
boolean |
isCalendrical()
A calendar unit is always calendrical.
|
IsoDateUnit |
nextValidDate()
Defines a variation of this unit which resolves invalid intermediate
dates in additions and subtractions to the first valid date after
(the first day of following month).
|
IsoDateUnit |
unlessInvalid()
Defines a variation of this unit which handles invalid
intermediate dates in additions and subtractions by throwing
a
ChronoException. |
static CalendarUnit |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static CalendarUnit[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
static IsoDateUnit |
weekBasedYears()
Defines a special calendar unit for week-based years which are
not bound to the calendar year but to the week cycle of a year
preserving the day of week and (if possible) the week of year.
|
IsoDateUnit |
withCarryOver()
Defines a variation of this unit which resolves invalid intermediate
dates in additions and subtractions by transferring any day overflow
to the following month.
|
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOfgetLengthpublic static final CalendarUnit MILLENNIA
public static final CalendarUnit CENTURIES
public static final CalendarUnit DECADES
public static final CalendarUnit YEARS
public static final CalendarUnit QUARTERS
public static final CalendarUnit MONTHS
public static final CalendarUnit WEEKS
public static final CalendarUnit DAYS
public static CalendarUnit[] values()
for (CalendarUnit c : CalendarUnit.values()) System.out.println(c);
public static CalendarUnit valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic <T extends TimePoint<? super CalendarUnit,T>> long between(T start, T end)
Calculates the temporal distance between given calendar dates in this calendar unit.
T - generic type of calendar datestart - starting dateend - ending datepublic boolean isCalendrical()
A calendar unit is always calendrical.
isCalendrical in interface ChronoUnittruepublic IsoDateUnit nextValidDate()
Defines a variation of this unit which resolves invalid intermediate dates in additions and subtractions to the first valid date after (the first day of following month).
Example for months:
PlainDate date = PlainDate.of(2013, 1, 31); System.out.println(date.plus(1, MONTHS.nextValidDate())); // Output: 2013-03-01
Note: The metric for calculation of temporal distances remains unaffected.
public IsoDateUnit withCarryOver()
Defines a variation of this unit which resolves invalid intermediate dates in additions and subtractions by transferring any day overflow to the following month.
Example for months:
PlainDate date = PlainDate.of(2013, 1, 31); System.out.println(date.plus(1, MONTHS.withCarryOver())); // Output: 2013-03-03
Note: The metric for calculation of temporal distances remains unaffected.
public IsoDateUnit unlessInvalid()
Defines a variation of this unit which handles invalid
intermediate dates in additions and subtractions by throwing
a ChronoException.
Example for months:
PlainDate date = PlainDate.of(2013, 1, 31); System.out.println(date.plus(1, MONTHS.unlessInvalid())); // February 31th does not exist => throws ChronoException
Note: The metric for calculation of temporal distances remains unaffected.
public IsoDateUnit atEndOfMonth()
Defines a variation of this unit which always sets the resulting date in additions and subtractions to the end of month even if there is no day overflow.
Example for months:
PlainDate date = PlainDate.of(2013, 2, 28); System.out.println(date.plus(2, MONTHS.atEndOfMonth())); // Output: 2013-04-30
Note: The metric for calculation of temporal distances remains unaffected.
public static IsoDateUnit weekBasedYears()
Defines a special calendar unit for week-based years which are not bound to the calendar year but to the week cycle of a year preserving the day of week and (if possible) the week of year.
Note: If the week of year is originally 53, but there is no such value after addition or subtraction then the week of year will be reduced to value 52.
PlainDate start = PlainDate.of(2000, 2, 29); // 2000-W09-2 System.out.println(start.plus(14, CalendarUnit.weekBasedYears())); // Output: 2014-02-25 (= 2014-W09-2)
Copyright © 2014. All rights reserved.