(calendar-absolute-from-gregorian '(1 1 1970))
"Absolute date of starting date of system clock.")
-(defun calendar-/ (a b)
- "Floor(A/B) = the greatest integer not greater than A divided by B.
-A and B be must both be integers, and B must be positive."
- (if (< a 0)
- (- (/ (- b 1 a) b))
- (/ a b)))
-
-(defun calendar-% (a b)
- "A modulo B; always nonnegative.
-A and B be must both be integers, and B must be positive."
- (let ((m (% a b)))
- (if (< m 0)
- (+ m b)
- m)))
-
(defun calendar-absolute-from-time (x utc-diff)
"Absolute local date of time X; local time is UTC-DIFF seconds from UTC.
(let* ((h (car x))
(xtail (cdr x))
(l (+ utc-diff (if (numberp xtail) xtail (car xtail))))
- (u (+ (* 512 (calendar-% h 675)) (calendar-/ l 128))))
+ (u (+ (* 512 (mod h 675)) (floor l 128))))
;; Overflow is a terrible thing!
(cons (+ calendar-system-time-basis
;; floor((2^16 h +l) / (60*60*24))
- (* 512 (calendar-/ h 675)) (calendar-/ u 675))
+ (* 512 (mod h 675)) (floor u 675))
;; (2^16 h +l) % (60*60*24)
- (+ (* (calendar-% u 675) 128) (calendar-% l 128)))))
+ (+ (* (mod u 675) 128) (floor l 128)))))
(defun calendar-time-from-absolute (abs-date s)
"Time of absolute date ABS-DATE, S seconds after midnight.
ignoring leap seconds, that is the equivalent moment to S seconds after
midnight UTC on absolute date ABS-DATE."
(let* ((a (- abs-date calendar-system-time-basis))
- (u (+ (* 163 (calendar-% a 512)) (calendar-/ s 128))))
+ (u (+ (* 163 (mod a 512)) (floor s 128))))
;; Overflow is a terrible thing!
(cons
;; (60*60*24*a + s) / 2^16
- (+ a (* 163 (calendar-/ a 512)) (calendar-/ u 512))
+ (+ a (* 163 (floor a 512)) (floor u 512))
;; (60*60*24*a + s) % 2^16
- (+ (* 128 (calendar-% u 512)) (calendar-% s 128)))))
+ (+ (* 128 (mod u 512)) (mod s 128)))))
(defun calendar-next-time-zone-transition (time)
"Return the time of the next time zone transition after TIME.
(require 'calendar)
-(defun mayan-mod (m n)
- "Returns M mod N; value is *always* non-negative when N>0."
- (let ((v (% m n)))
- (if (and (> 0 v) (> n 0))
- (+ v n)
- v)))
-
(defun mayan-adjusted-mod (m n)
"Non-negative remainder of M/N with N instead of 0."
- (1+ (mayan-mod (1- m) n)))
+ (1+ (mod (1- m) n)))
(defconst calendar-mayan-days-before-absolute-zero 1137140
"Number of days of the Mayan calendar epoch before absolute day 0.
(defun calendar-mayan-haab-difference (date1 date2)
"Number of days from Mayan haab DATE1 to next occurrence of haab date DATE2."
- (mayan-mod (+ (* 20 (- (cdr date2) (cdr date1)))
- (- (car date2) (car date1)))
- 365))
+ (mod (+ (* 20 (- (cdr date2) (cdr date1)))
+ (- (car date2) (car date1)))
+ 365))
(defun calendar-mayan-haab-on-or-before (haab-date date)
"Absolute date of latest HAAB-DATE on or before absolute DATE."
"Number of days from Mayan tzolkin DATE1 to next occurrence of tzolkin DATE2."
(let ((number-difference (- (car date2) (car date1)))
(name-difference (- (cdr date2) (cdr date1))))
- (mayan-mod (+ number-difference
- (* 13 (mayan-mod (* 3 (- number-difference name-difference))
- 20)))
- 260)))
+ (mod (+ number-difference
+ (* 13 (mod (* 3 (- number-difference name-difference))
+ 20)))
+ 260)))
(defun calendar-mayan-tzolkin-on-or-before (tzolkin-date date)
"Absolute date of latest TZOLKIN-DATE on or before absolute DATE."
(difference (- tzolkin-difference haab-difference)))
(if (= (% difference 5) 0)
(- date
- (mayan-mod (- date
- (+ haab-difference (* 365 difference)))
- 18980))
+ (mod (- date
+ (+ haab-difference (* 365 difference)))
+ 18980))
nil)))
(defun calendar-read-mayan-haab-date ()