Skip to content

Commit

Permalink
extract leap-year-p from code
Browse files Browse the repository at this point in the history
  • Loading branch information
vindarel committed Jun 25, 2021
1 parent cd7661d commit 7796383
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/local-time.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,18 @@ In other words:
(values (1+ month-minus-one)
(+ year year-offset))))

(defun leap-year-p (year)
"Returns T if the given year is a leap year."
(or (and (zerop (mod year 4))
(plusp (mod year 100)))
(zerop (mod year 400))))

(defun days-in-month (month year)
"Returns the number of days in the given month of the specified year."
(let ((normal-days (aref +rotated-month-days-without-leap-day+
(mod (+ month 9) 12))))
(if (and (= month 2)
(or (and (zerop (mod year 4))
(plusp (mod year 100)))
(zerop (mod year 400))))
(leap-year-p year))
(1+ normal-days) ; February on a leap year
normal-days)))

Expand Down
1 change: 1 addition & 0 deletions src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#:adjust-timestamp
#:adjust-timestamp!
#:timestamp-whole-year-difference
#:leap-year-p
#:days-in-month
#:weeks-in-year
#:timestamp-
Expand Down

0 comments on commit 7796383

Please sign in to comment.