Skip to content

Instantly share code, notes, and snippets.

@juan-reynoso
Created July 7, 2021 21:49
Show Gist options
  • Save juan-reynoso/2c8a2882b8ac75b54c694b7048a8de7a to your computer and use it in GitHub Desktop.
Save juan-reynoso/2c8a2882b8ac75b54c694b7048a8de7a to your computer and use it in GitHub Desktop.
Some examples: local-time
(in-package #:local-time)
(defun get-previous-day (&key (timestamp (now)))
"Returns the timestamp of the previous day of the timestamp"
(adjust-timestamp timestamp (offset :day -1)))
(defun get-next-day (&key (timestamp (now)))
"Returns the timestamp of the next day of the timestamp"
(adjust-timestamp timestamp (offset :day 1)))
(defun get-previous-month (year month)
"Returns a list with the year and month as number which are
the previous month of the year."
(let ((new-year nil)
(new-month nil))
(if (= month 1)
(setf new-month 12
new-year (- year 1))
(setf new-month (- month 1)
new-year year))
(list new-year new-month)))
(defun get-next-month (year month)
"Returns a list with the year and month as number which are
the previous next of the year."
(let ((new-year nil)
(new-month nil))
(if (= month 12)
(setf new-month 1
new-year (+ 1 year))
(setf new-month (+ 1 month)
new-year year))
(list new-year new-month)))
(defun get-month-period (year month)
"Returns the start and end date of the month"
(let ((last-day (days-in-month month year)))
(list (ucw::strcat year "/" month "/" 1)
(ucw::strcat year "/" month "/" last-day))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment