-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtimestamp.lisp
25 lines (22 loc) · 1.13 KB
/
timestamp.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(in-package :ltd)
(defun timestamp-difference (time-a time-b)
"Returns a duration representing the time elapsed between the timestamps `TIME-A` and `TIME-B`. This duration may be negative if `TIME-B` is later than `TIME-A`."
(let ((day (- (local-time:day-of time-a)
(local-time:day-of time-b)))
(sec (- (local-time:sec-of time-a)
(local-time:sec-of time-b)))
(nsec (- (local-time:nsec-of time-a)
(local-time:nsec-of time-b))))
(duration :day day :sec sec :nsec nsec)))
(defun timestamp-duration+ (timestamp duration)
"Returns a fresh timestamp representing the time when `DURATION` has elapsed after `TIMESTAMP`."
(local-time:adjust-timestamp timestamp
(offset :day (day-of duration))
(offset :sec (sec-of duration))
(offset :nsec (nsec-of duration))))
(defun timestamp-duration- (timestamp duration)
"Returns a fresh timestamp representing the time when `DURATION` will elapse before `TIMESTAMP`."
(local-time:adjust-timestamp timestamp
(offset :day (- (day-of duration)))
(offset :sec (- (sec-of duration)))
(offset :nsec (- (nsec-of duration)))))