Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "week of year" expression #173

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Categorize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ parseCondExpr = buildExpressionParser [
[ Prefix (reservedOp lang "!" >> return checkNot) ],
[ Prefix (reserved lang "day of week" >> return evalDayOfWeek)
, Prefix (reserved lang "day of month" >> return evalDayOfMonth)
, Prefix (reserved lang "week of year" >> return evalWeekOfYear)
, Prefix (reserved lang "month" >> return evalMonth)
, Prefix (reserved lang "year" >> return evalYear)
, Prefix (reserved lang "format" >> return formatDate) ],
Expand Down Expand Up @@ -354,6 +355,15 @@ evalDayOfMonth cp = Left $ printf
"Cannot apply day of month to an expression of type %s, only to $date."
(cpType cp)

-- Day of month is an integer in [1..31].
isovector marked this conversation as resolved.
Show resolved Hide resolved
evalWeekOfYear :: CondPrim -> Erring CondPrim
evalWeekOfYear (CondDate df) = Right $ CondInteger $ \ctx ->
let tz = zonedTimeZone (cCurrentTime ctx) in
(toInteger . snd3 . toWeekDate . localDay . utcToLocalTime tz) `fmap` df ctx
evalWeekOfYear cp = Left $ printf
"Cannot apply week of year to an expression of type %s, only to $date."
(cpType cp)

-- Month is an integer in [1..12].
evalMonth :: CondPrim -> Erring CondPrim
evalMonth (CondDate df) = Right $ CondInteger $ \ctx ->
Expand Down