timing.adjusters

Temporal adjusters for the Timing library - functions that adjust dates/times to specific temporal points using numeric domain arithmetic.

add-business-days

(add-business-days value n)(add-business-days value n {:keys [weekend-days], :or {weekend-days #{7 6}}})

Adds n business days, skipping weekends.

add-months

(add-months value n)

Adds n months to a time value, handling variable month lengths properly. Examples: - Jan 31 + 1 month = Feb 28 (Feb has fewer days) - Feb 29 + 12 months = Feb 28 (if target year is not a leap year) - Any date + n months maintains the same day when possible

add-years

(add-years value n)

Adds n years to a time value, handling leap years properly. Examples: - Feb 29, 2024 + 1 year = Feb 28, 2025 (2025 is not a leap year) - Any other date + n years maintains the same month and day

business-days-in-range

(business-days-in-range start end)(business-days-in-range start end {:keys [weekend-days], :or {weekend-days #{7 6}}})

Returns sequence of business days between start and end (inclusive).

end-of-month

(end-of-month value)

Adjusts value to the last day of the month just before midnight.

end-of-quarter

(end-of-quarter value)

Adjusts value to the last day of the quarter.

end-of-week

(end-of-week value)(end-of-week value {:keys [first-day-of-week], :or {first-day-of-week 1}})

Adjusts value to the end of the week (Sunday by default). Options: {:first-day-of-week 7} for Sunday start

end-of-year

(end-of-year value)

Adjusts value to December 31st just before midnight.

every-nth-day-of-week

(every-nth-day-of-week start-value target-day n)

Generates a sequence of every nth occurrence of a day-of-week. Example: Every 2nd Monday starting from a date

first-day-of-month-on-day-of-week

(first-day-of-month-on-day-of-week value target-day)

Finds the first occurrence of a day of week in the month. Example: First Monday of March 2024

last-day-of-month-on-day-of-week

(last-day-of-month-on-day-of-week value target-day)

Finds the last occurrence of a day of week in the month. Example: Last Friday of March 2024

next-business-day

(next-business-day value)(next-business-day value {:keys [weekend-days], :or {weekend-days #{7 6}}})

Adjusts to the next business day (Monday-Friday). Options: {:weekend-days #{6 7}} to customize weekend

next-day-of-week

(next-day-of-week value target-day)

Adjusts value to the next occurrence of the specified day of week. Day: 1=Monday, 2=Tuesday, …, 7=Sunday

next-or-same-day-of-week

(next-or-same-day-of-week value target-day)

Adjusts value to the next occurrence of the specified day of week, or returns the same value if it’s already that day.

nth-day-of-month-on-day-of-week

(nth-day-of-month-on-day-of-week value target-day n)

Finds the nth occurrence of a day of week in the month. Example: 3rd Tuesday of March 2024

previous-business-day

(previous-business-day value)(previous-business-day value {:keys [weekend-days], :or {weekend-days #{7 6}}})

Adjusts to the previous business day (Monday-Friday). Options: {:weekend-days #{6 7}} to customize weekend

previous-day-of-week

(previous-day-of-week value target-day)

Adjusts value to the previous occurrence of the specified day of week. Day: 1=Monday, 2=Tuesday, …, 7=Sunday

start-of-month

(start-of-month value)

Adjusts value to the first day of the month at midnight.

start-of-quarter

(start-of-quarter value)

Adjusts value to the first day of the quarter.

start-of-week

(start-of-week value)(start-of-week value {:keys [first-day-of-week], :or {first-day-of-week 1}})

Adjusts value to the start of the week (Monday by default). Options: {:first-day-of-week 7} for Sunday start

start-of-year

(start-of-year value)

Adjusts value to January 1st at midnight.