aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-04-24 20:03:44 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-04-24 20:03:44 +0200
commit61c4bec8346882b9d77c24c9022fcd0172daa969 (patch)
treec1c20c22e8e28dab72f310bff3bf254a85aee02b
parentRecurrence rule WKST properly parsed again. (diff)
downloadcalp-61c4bec8346882b9d77c24c9022fcd0172daa969.tar.gz
calp-61c4bec8346882b9d77c24c9022fcd0172daa969.tar.xz
Update (start|end)-of-week to work as expected.
-rw-r--r--module/datetime/util.scm26
-rw-r--r--module/entry-points/server.scm2
2 files changed, 14 insertions, 14 deletions
diff --git a/module/datetime/util.scm b/module/datetime/util.scm
index 2a85c928..e40e6559 100644
--- a/module/datetime/util.scm
+++ b/module/datetime/util.scm
@@ -13,6 +13,9 @@
(define-public (start-of-month date)
(set (day date) 1))
+(define-public (end-of-month date)
+ (set (day date) (days-in-month date)))
+
(define-public (start-of-year date)
(set-> date
(day 1)
@@ -252,21 +255,18 @@
week-start)
7))
-;; given start of month, returns the date that week started on.
-;; (start-of-week #2020-05-01 mon)
-;; => 2020-04-27
-;; TODO update these two week-methods to do what they ostensibly do.
-(define*-public (start-of-week date optional: (week-start mon))
- (let* ((prev-month-len (days-in-month (month- date)))
- (month-start (modulo (- (week-day date) week-start) 7)))
- (set (day (month- date)) (1+ (- prev-month-len month-start)))))
+;; returns the date the week containing d started.
+;; (start-of-week #2020-04-02 sun) ; => 2020-03-29
+(define*-public (start-of-week d optional: (week-start mon))
+ (date- d (date day: (modulo (- (week-day d)
+ week-start)
+ 7))))
;; (end-of-week #2020-04-01 mon)
-;; => 2020-05-03
-(define*-public (end-of-week date optional: (week-start mon))
- (let* ((month-len (days-in-month date))
- (month-start (modulo (- (week-day date) week-start) 7)))
- (set (day (month+ date)) (modulo (- (* 7 5) month-len month-start) 7))))
+;; => 2020-04-05
+(define*-public (end-of-week d optional: (week-start mon))
+ (date+ (start-of-week d week-start)
+ (date day: 6)))
;; Given a month and and which day the week starts on,
diff --git a/module/entry-points/server.scm b/module/entry-points/server.scm
index 146028ee..3730b8a5 100644
--- a/module/entry-points/server.scm
+++ b/module/entry-points/server.scm
@@ -72,7 +72,7 @@
prev-start: month-
render-calendar: render-calendar-table
pre-start: (start-of-week start-date)
- post-end: (end-of-week start-date)
+ post-end: (end-of-week (end-of-month start-date))
))))))
(GET "/static" ()