Skip to content

Commit

Permalink
Use ISO-8601 representation in print-object for durations
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-coram committed Jul 4, 2023
1 parent 403d8f2 commit 238deab
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions duration.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@
(and (eql (seconds d1) (seconds d2))
(eql (nanos d1) (nanos d2)))))

(defmethod print-object ((duration duration) stream)
(print-unreadable-object (duration stream :type t)
(format stream ":SECONDS ~d :NANOS ~d"
(seconds duration)
(nanos duration))))

(defmethod plus ((d1 duration) (d2 duration))
(duration-of-seconds (+ (seconds d1) (seconds d2))
(+ (nanos d1) (nanos d2))))

(defmethod to-string ((d duration))
(if (duration= d *zero-duration*)
"PT0S"
Expand Down Expand Up @@ -88,6 +78,14 @@
(list #\. fraction))
s))))))))

(defmethod print-object ((duration duration) stream)
(print-unreadable-object (duration stream :type t)
(format stream "~s" (to-string duration))))

(defmethod plus ((d1 duration) (d2 duration))
(duration-of-seconds (+ (seconds d1) (seconds d2))
(+ (nanos d1) (nanos d2))))

(defun duration-of-days (days)
(make-instance 'duration :seconds (* days +seconds-per-day+)))

Expand Down

0 comments on commit 238deab

Please sign in to comment.