Class DateAdjusters
DateAdjuster
.
DateAdjusters is a utility class. All adjusters returned are immutable and thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Class implementing day-of-week in month adjuster.private static enum
Enum implementing the adjusters.private static final class
Implementation of next, previous or current day-of-week. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor since this is a utility class. -
Method Summary
Modifier and TypeMethodDescriptionstatic DateAdjuster
dayOfWeekInMonth
(int ordinal, DayOfWeek dayOfWeek) Returns the day-of-week in month adjuster, which returns a new date in the same month with the ordinal day-of-week.static DateAdjuster
Returns the first day-of-month adjuster, which returns a new date with the day-of-month changed to be the first day of the month.static DateAdjuster
Returns the first day-of-year adjuster, which returns a new date with the day-of-year changed to be the first day of the year - January 1.static DateAdjuster
firstInMonth
(DayOfWeek dayOfWeek) Returns the first in month adjuster, which returns a new date in the same month with the first matching day-of-week.static DateAdjuster
Returns the last day-of-month adjuster, which returns a new date with the day-of-month changed to be the last valid day of the month.static DateAdjuster
Returns the last day-of-year adjuster, which returns a new date with the day-of-year changed to be the last day of the year - December 31.static DateAdjuster
Returns the next day-of-week adjuster, which adjusts the date to be the next of the specified day-of-week after the specified date.static DateAdjuster
Returns the next non weekend day adjuster, which adjusts the date one day forward skipping Saturday and Sunday.static DateAdjuster
nextOrCurrent
(DayOfWeek dow) Returns the next or current day-of-week adjuster, which adjusts the date to be be the next of the specified day-of-week, returning the input date if the day-of-week matched.static DateAdjuster
Returns the previous day-of-week adjuster, which adjusts the date to be the previous of the specified day-of-week after the specified date.static DateAdjuster
Returns the previous or current day-of-week adjuster, which adjusts the date to be be the previous of the specified day-of-week, returning the input date if the day-of-week matched.
-
Constructor Details
-
DateAdjusters
private DateAdjusters()Private constructor since this is a utility class.
-
-
Method Details
-
firstDayOfMonth
Returns the first day-of-month adjuster, which returns a new date with the day-of-month changed to be the first day of the month.The input 2007-01-15 will return 2007-01-01.
The input 2008-02-15 will return 2008-02-01.- Returns:
- the first day-of-month adjuster, never null
-
lastDayOfMonth
Returns the last day-of-month adjuster, which returns a new date with the day-of-month changed to be the last valid day of the month.The input 2007-01-15 will return 2007-01-31.
The input 2007-02-15 will return 2007-02-28.
The input 2007-03-15 will return 2007-03-31.
The input 2007-04-15 will return 2007-04-30.
The input 2008-02-15 will return 2008-02-29.- Returns:
- the last day-of-month adjuster, never null
-
firstDayOfYear
Returns the first day-of-year adjuster, which returns a new date with the day-of-year changed to be the first day of the year - January 1.The input 2007-01-15 will return 2007-01-01.
The input 2008-02-15 will return 2008-01-01.- Returns:
- the first day-of-year adjuster, never null
-
lastDayOfYear
Returns the last day-of-year adjuster, which returns a new date with the day-of-year changed to be the last day of the year - December 31.The input 2007-01-15 will return 2007-12-31.
The input 2008-02-15 will return 2008-12-31.- Returns:
- the last day-of-year adjuster, never null
-
nextNonWeekendDay
Returns the next non weekend day adjuster, which adjusts the date one day forward skipping Saturday and Sunday.- Returns:
- the next working day adjuster, never null
-
firstInMonth
Returns the first in month adjuster, which returns a new date in the same month with the first matching day-of-week. This is used for expressions like 'first Tuesday in March'.The input 2007-12-15 for (MONDAY) will return 2007-12-03.
The input 2007-12-15 for (TUESDAY) will return 2007-12-04.- Parameters:
dayOfWeek
- the day-of-week, not null- Returns:
- the first in month adjuster, never null
-
dayOfWeekInMonth
Returns the day-of-week in month adjuster, which returns a new date in the same month with the ordinal day-of-week. This is used for expressions like 'second Tuesday in March'.The input 2007-12-15 for (1,MONDAY) will return 2007-12-03.
The input 2007-12-15 for (2,TUESDAY) will return 2007-12-11.
The input 2007-12-15 for (3,TUESDAY) will return 2007-12-18.
The input 2007-12-15 for (4,TUESDAY) will return 2007-12-25.
The input 2007-12-15 for (5,TUESDAY) will return 2008-01-01.
If the ordinal is 5 and there is no 5th of the requested day-of-week, then the first of the next month is returned.
- Parameters:
ordinal
- ordinal, from 1 to 5dayOfWeek
- the day-of-week, not null- Returns:
- the day-of-week in month adjuster, never null
- Throws:
IllegalArgumentException
- if the ordinal is invalid
-
next
Returns the next day-of-week adjuster, which adjusts the date to be the next of the specified day-of-week after the specified date.- Parameters:
dow
- the day-of-week to move the date to, not null- Returns:
- the next day-of-week adjuster, never null
-
nextOrCurrent
Returns the next or current day-of-week adjuster, which adjusts the date to be be the next of the specified day-of-week, returning the input date if the day-of-week matched.- Parameters:
dow
- the day-of-week to move the date to, not null- Returns:
- the next day-of-week adjuster, never null
-
previous
Returns the previous day-of-week adjuster, which adjusts the date to be the previous of the specified day-of-week after the specified date.- Parameters:
dow
- the day-of-week to move the date to, not null- Returns:
- the next day-of-week adjuster, never null
-
previousOrCurrent
Returns the previous or current day-of-week adjuster, which adjusts the date to be be the previous of the specified day-of-week, returning the input date if the day-of-week matched.- Parameters:
dow
- the day-of-week to move the date to, not null- Returns:
- the next day-of-week adjuster, never null
-