Module

Temporal.PlainDate.Weekday

Package
purescript-temporal
Repository
philippedev101/purescript-temporal

Weekday utilities for PlainDate.

Provides a Weekday ADT with full typeclass instances, weekday predicates, business day arithmetic, and ordinal weekday functions (e.g. "3rd Thursday of the month").

All functions are pure PureScript — no FFI required.

#getWeekday Source

getWeekday :: PlainDate -> Weekday

Get the weekday of a date.

#isWeekday Source

isWeekday :: PlainDate -> Boolean

Whether the date falls on a weekday (Monday through Friday).

#isWeekend Source

isWeekend :: PlainDate -> Boolean

Whether the date falls on a weekend (Saturday or Sunday).

#addBusinessDays Source

addBusinessDays :: Int -> PlainDate -> PlainDate

Add business days (Monday–Friday), skipping weekends. Supports negative values for going backward.

addBusinessDays 1 friday    == monday     -- skips weekend
addBusinessDays (-1) monday == friday     -- skips weekend backward
addBusinessDays 0 saturday  == saturday   -- identity
addBusinessDays 6 monday    == tuesday    -- 5 days = 1 week, +1

#nextWeekday Source

nextWeekday :: Weekday -> PlainDate -> PlainDate

The next occurrence of the given weekday, always advancing at least 1 day.

nextWeekday Monday someMonday  == next Monday (7 days later)
nextWeekday Wednesday someMonday == next Wednesday (2 days later)

#nextOrSameWeekday Source

nextOrSameWeekday :: Weekday -> PlainDate -> PlainDate

The next occurrence of the given weekday, or the same date if it already matches.

#previousWeekday Source

previousWeekday :: Weekday -> PlainDate -> PlainDate

The previous occurrence of the given weekday, always retreating at least 1 day.

#previousOrSameWeekday Source

previousOrSameWeekday :: Weekday -> PlainDate -> PlainDate

The previous occurrence of the given weekday, or the same date if it already matches.

#dayOfWeekInSameWeek Source

dayOfWeekInSameWeek :: Weekday -> PlainDate -> PlainDate

Find the given weekday within the same ISO week as the input date. The ISO week runs Monday through Sunday.

dayOfWeekInSameWeek Wednesday someMonday  == the Wednesday of that week
dayOfWeekInSameWeek Monday someSunday     == the Monday of that week

#nthWeekdayOfMonth Source

nthWeekdayOfMonth :: Int -> Weekday -> PlainDate -> Maybe PlainDate

The nth occurrence of a weekday within the month containing the given date. Returns Nothing if the nth occurrence doesn't exist (e.g. there is no 5th Monday in most months).

-- Thanksgiving: 4th Thursday of November
nthWeekdayOfMonth 4 Thursday (plainDate 2024 11 1)

-- 1st Monday of the month
nthWeekdayOfMonth 1 Monday (plainDate 2024 3 15)

#lastWeekdayOfMonth Source

lastWeekdayOfMonth :: Weekday -> PlainDate -> PlainDate

The last occurrence of a weekday within the month containing the given date.

lastWeekdayOfMonth Friday (plainDate 2024 3 15)  -- last Friday of March