Package net.pricefx.common.util
Enum Class CalendarUtil.TimeUnit
- All Implemented Interfaces:
Serializable,Comparable<CalendarUtil.TimeUnit>,Constable
- Enclosing class:
CalendarUtil
Unit of a
CalendarUtil.TimePeriod: day, week, month, quarter or year.
Methods that take a unit as a string accept the constant name in any letter case, for example
"Month" or "MONTH".
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionReturns the last day of the period of this unit that contains the given date, at the start of that day.static CalendarUtil.TimeUnitReturns the unit with the given name, ignoring letter case.static CalendarUtil.TimeUnitget(String unit, CalendarUtil.TimeUnit defaultValue) Returns the unit with the given name, ignoring letter case.getName()Returns the display name of the unit, for example"Month".offsetDate(Date date, int offset) Moves a date by a number of units of this type.Returns the start of the period of this unit that contains the given date.toString()Returns the display name of the unit, the same asgetName().static CalendarUtil.TimeUnitReturns the enum constant of this class with the specified name.static CalendarUtil.TimeUnit[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
DAY
One calendar day. -
WEEK
One calendar week. The first day of the week and the minimal number of days in the first week of the year follow the calendar settings of the partition. -
MONTH
One calendar month. -
QUARTER
Three calendar months, starting in January, April, July or October. -
YEAR
One year. A period named by its year, such as2026, is the calendar year; a period created from a date starts on that date (seestartDate(Date)).
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getName
Returns the display name of the unit, for example"Month".- Returns:
- Display name of the unit.
-
startDate
Returns the start of the period of this unit that contains the given date. For example, forMONTHand the date 2026-02-15, the result is 2026-02-01 at the start of the day. ForWEEK, the week starts on the first day of the week set for the partition.For
YEAR, the date is returned unchanged, including the time of day. It is not moved to January 1.- Parameters:
date- Date inside the period.- Returns:
- Start date of the period, or
nullifdateisnull.
-
endDate
Returns the last day of the period of this unit that contains the given date, at the start of that day. For example, forMONTHand the date 2026-02-15, the result is 2026-02-28.For
YEAR, the result is the day before the same date one year later, with the time of day of the given date. For example, for 2026-06-15 the result is 2027-06-14 (seestartDate(Date)).- Parameters:
date- Date inside the period.- Returns:
- End date of the period, or
nullifdateisnull.
-
offsetDate
Moves a date by a number of units of this type. A negative offset moves the date back. AQUARTERmoves the date by three months.- Parameters:
date- Date to move.offset- Number of units to move the date by.- Returns:
- Moved date. Returns
dateunchanged if it isnullor ifoffsetis 0.
-
toString
Returns the display name of the unit, the same asgetName().- Overrides:
toStringin classEnum<CalendarUtil.TimeUnit>- Returns:
- Display name of the unit, for example
"Month".
-
get
Returns the unit with the given name, ignoring letter case.- Parameters:
unit- Name of the unit, for example"Month"or"MONTH".defaultValue- Unit to return whenunitisnullor not a valid unit name.- Returns:
- Matching unit, or
defaultValueif there is no match.
-
get
Returns the unit with the given name, ignoring letter case.- Parameters:
unit- Name of the unit, for example"Month"or"MONTH".- Returns:
- Matching unit, or
nullifunitisnullor not a valid unit name.
-