From e79c2e1b7299e2ac2c4b66edcee81e9616778e83 Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Tue, 19 Mar 2024 10:25:50 -0700 Subject: [PATCH 1/5] add week of year --- src/Categorize.hs | 10 ++++++++++ stack.yaml | 2 +- stack.yaml.lock | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 stack.yaml.lock diff --git a/src/Categorize.hs b/src/Categorize.hs index 82246eb..bc277a4 100644 --- a/src/Categorize.hs +++ b/src/Categorize.hs @@ -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) ], @@ -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]. +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 -> diff --git a/stack.yaml b/stack.yaml index 2f5d9ca..bd556f9 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-13.18 +resolver: lts-21.14 flags: bytestring-progress: diff --git a/stack.yaml.lock b/stack.yaml.lock new file mode 100644 index 0000000..c7f7410 --- /dev/null +++ b/stack.yaml.lock @@ -0,0 +1,26 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: +- completed: + hackage: bytestring-progress-1.2@sha256:57854dc62fd48daf3fc24629d19f05e58841f152b6a20e677c84d34b7a264934,1151 + pantry-tree: + sha256: e990b24deded845cf13a336037a0a2edbc444290677a18ad81863bca5530a8e2 + size: 360 + original: + hackage: bytestring-progress-1.2 +- completed: + hackage: terminal-progress-bar-0.4.0.1@sha256:ef97018e0a6cf496e2c14f93f29e0c343ff3ffee647505f0fa01e310983a9723,2391 + pantry-tree: + sha256: 856144d2494ca098a6c9af203562861f6a6da8df9d4a7e28c3e6fc9fd2d1a2b0 + size: 393 + original: + hackage: terminal-progress-bar-0.4.0.1 +snapshots: +- completed: + sha256: 60e54c1ba3c1e7163acf6dafa9d56b2d3b23f88a31ad53a1c9d888f32561f8da + size: 639819 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/14.yaml + original: lts-21.14 From 8f5e572d6c05e40960ea488db70a2eb9bc44138c Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Tue, 19 Mar 2024 11:16:05 -0700 Subject: [PATCH 2/5] undo changes to stack --- stack.yaml | 2 +- stack.yaml.lock | 26 -------------------------- 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 stack.yaml.lock diff --git a/stack.yaml b/stack.yaml index bd556f9..2f5d9ca 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-21.14 +resolver: lts-13.18 flags: bytestring-progress: diff --git a/stack.yaml.lock b/stack.yaml.lock deleted file mode 100644 index c7f7410..0000000 --- a/stack.yaml.lock +++ /dev/null @@ -1,26 +0,0 @@ -# This file was autogenerated by Stack. -# You should not edit this file by hand. -# For more information, please see the documentation at: -# https://docs.haskellstack.org/en/stable/lock_files - -packages: -- completed: - hackage: bytestring-progress-1.2@sha256:57854dc62fd48daf3fc24629d19f05e58841f152b6a20e677c84d34b7a264934,1151 - pantry-tree: - sha256: e990b24deded845cf13a336037a0a2edbc444290677a18ad81863bca5530a8e2 - size: 360 - original: - hackage: bytestring-progress-1.2 -- completed: - hackage: terminal-progress-bar-0.4.0.1@sha256:ef97018e0a6cf496e2c14f93f29e0c343ff3ffee647505f0fa01e310983a9723,2391 - pantry-tree: - sha256: 856144d2494ca098a6c9af203562861f6a6da8df9d4a7e28c3e6fc9fd2d1a2b0 - size: 393 - original: - hackage: terminal-progress-bar-0.4.0.1 -snapshots: -- completed: - sha256: 60e54c1ba3c1e7163acf6dafa9d56b2d3b23f88a31ad53a1c9d888f32561f8da - size: 639819 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/14.yaml - original: lts-21.14 From 85675c6d540ccdec9ca477fe72847bfa70ff39ce Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Tue, 19 Mar 2024 15:52:44 -0700 Subject: [PATCH 3/5] Update stale comment --- src/Categorize.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Categorize.hs b/src/Categorize.hs index bc277a4..e785785 100644 --- a/src/Categorize.hs +++ b/src/Categorize.hs @@ -355,7 +355,7 @@ 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]. +-- Week of year is an integer in [0..53]. evalWeekOfYear :: CondPrim -> Erring CondPrim evalWeekOfYear (CondDate df) = Right $ CondInteger $ \ctx -> let tz = zonedTimeZone (cCurrentTime ctx) in From 675194b231bd58f308beb28dca01f9fbd7d76a3f Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Tue, 19 Mar 2024 15:54:31 -0700 Subject: [PATCH 4/5] update documentation --- doc/arbtt.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/arbtt.xml b/doc/arbtt.xml index ad70114..7c1e5e1 100644 --- a/doc/arbtt.xml +++ b/doc/arbtt.xml @@ -298,6 +298,9 @@ Expression day of week $date evaluates to an integer, from 1 to 7, corresponding to the day of week, Monday is 1, Sunday is 7. These expressions can be compared to integers. + Expression week of year $date evaluates to an integer, + from 0 to 53, corresponding to the week of year. January 1 falls in week 0. + These expressions can be compared to integers. From f96ff6481dc9ec4400c1613e32d987a3be2706db Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Tue, 19 Mar 2024 15:54:51 -0700 Subject: [PATCH 5/5] add more documentation --- doc/arbtt.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/arbtt.xml b/doc/arbtt.xml index 7c1e5e1..f601cca 100644 --- a/doc/arbtt.xml +++ b/doc/arbtt.xml @@ -455,6 +455,7 @@ $idle day of week day of month + week of year month year number literal