Skip to content

Instantly share code, notes, and snippets.

@juan-reynoso
Created September 29, 2021 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juan-reynoso/1bdee3bd87c7bc729f9a234236ba8e92 to your computer and use it in GitHub Desktop.
Save juan-reynoso/1bdee3bd87c7bc729f9a234236ba8e92 to your computer and use it in GitHub Desktop.
Compare dates
(defun date-compare (time-a time-b)
"Returns the symbols <, >, or =, describing the relationship between TIME-A and TIME-B."
(declare (type timestamp time-a time-b))
(cond
((< (day-of time-a) (day-of time-b)) '<)
((> (day-of time-a) (day-of time-b)) '>)
(t '=)))
(defun date= (time-a time-b)
"Return T if date of TIME-A is equal to date of TIME-B, NIL otherwise."
(eql (date-compare time-a time-b) '=))
(defun date> (time-a time-b)
"Return T if date of TIME-A is greater than date of TIME-B, NIL otherwise."
(eql (date-compare time-a time-b) '>))
(defun date< (time-a time-b)
"Return T if date of TIME-A is less than date of TIME-B, NIL otherwise."
(eql (date-compare time-a time-b) '<))
(defun date>= (time-a time-b)
"Return T if date of TIME-A is greater than or equal to date of TIME-B, NIL otherwise."
(not (null (member (date-compare time-a time-b) '(> =)))))
(defun date<= (time-a time-b)
"Return T if date of TIME-A is less than or equal to date of TIME-B, NIL otherwise."
(not (null (member (date-compare time-a time-b) '(< =)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment