Skip to content

Instantly share code, notes, and snippets.

@muihlinn
Last active May 31, 2022 19:13
Show Gist options
  • Save muihlinn/4136f92d9c52c41d8798d7ddfe0900b9 to your computer and use it in GitHub Desktop.
Save muihlinn/4136f92d9c52c41d8798d7ddfe0900b9 to your computer and use it in GitHub Desktop.
elisp last monday date
(defun muihlinn-last-monday()
"Date of last monday."
(let* ( (date (calendar-current-date))
(today (calendar-absolute-from-gregorian date))
(dow (calendar-day-of-week date)))
(cl-destructuring-bind (month day year)
(calendar-gregorian-from-absolute
;; if sunday and our weeks starts on monday
(if (and (eq dow 0) (eq calendar-week-start-day 1))
(- today 6)
(1+ (- today dow))))
(format "%04d-%02d-%02d" year month day))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment