Skip to content

Instantly share code, notes, and snippets.

@juan-reynoso
Created September 27, 2021 16:10
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/679e1a1305aef2f17f3c864793561ba0 to your computer and use it in GitHub Desktop.
Save juan-reynoso/679e1a1305aef2f17f3c864793561ba0 to your computer and use it in GitHub Desktop.
Returns a list with weekday, day, month, year and total days of the month of local-time object
(defun get-timestamp-data (timestamp)
"Returns a list with weekday, day, month, year and total days of the month.
*ISO compatible weekday number (monday=1, sunday=7)
*day of month
*numeric month
*year
*numeric total-days-of-month"
(let ((day-of-week nil)
(day nil)
(month nil)
(year nil)
(total-days-of-month nil)
(date-data nil))
;; Create a list of subsequences in seq delimited by #\Space
(setf date-data (split-sequence:split-sequence #\Space
(format-timestring nil
timestamp
:format
'((:iso-week-day)
" "
(:day)
" "
(:month)
" "
(:year)))))
;; string to integer
(setf day-of-week (read-from-string (first date-data))
day (read-from-string (second date-data))
month (read-from-string (third date-data))
year (read-from-string (fourth date-data)))
;; get the total day of month
(setf total-days-of-month (days-in-month month year))
;; finally return the information.
(list day-of-week day month year total-days-of-month)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment