From a642c05620e33ca89ecc7d8fe1ccf76d7e07df46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 31 Mar 2020 00:38:41 +0200 Subject: Add {start,end}-of-week. --- module/datetime/util.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'module') diff --git a/module/datetime/util.scm b/module/datetime/util.scm index 46f9bbbc..0d4699c6 100644 --- a/module/datetime/util.scm +++ b/module/datetime/util.scm @@ -270,6 +270,22 @@ 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))))) + +;; (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)))) + ;; Given a month and and which day the week starts on, ;; returns three lists, which are: -- cgit v1.2.3