Search code examples
emacsdateelisp

How do I get the number of days in the month specified by an elisp time?


In elisp I have a time in the (form of three integers), and I can get the month using decode-time. What I'd like to get is the number of days in that month (and year), using elisp functions (rather than write my own).

i.e:

(defun days-in-month-at-time(t)
    ; Figure out month and year with decode-time
    ; return number of days in that month   
)

Solution

  • (require 'timezone)
    
    (defun days-in-month-at-time (time)
      "Return number of days in month at TIME."
      (let ((datetime (decode-time time)))
        (timezone-last-day-of-month (nth 4 datetime) (nth 5 datetime))))