Duration
this is a complementary module to be used with Datetime and
is concerned with adding and subtracting time values of the scale from seconds
to weeks from Datetime values.
Example:
(load "git@github.com:carpentry-org/time.carp@0.5.0")
(defn main []
(println*
&(Datetime.strftime
&(Duration.sub &(Datetime.now) &(Duration.days 2))
"%Y-%m-%d %I:%M:%S.%n %p %z")))
<
(Fn [(Ref Duration a), (Ref Duration b)] Bool)
(< a b)
checks whether the delta a is shorter than the delta b.
=
(Fn [(Ref Duration a), (Ref Duration b)] Bool)
(= a b)
checks whether the deltas a and b represent the same duration.
>
(Fn [(Ref Duration a), (Ref Duration b)] Bool)
(> a b)
checks whether the delta a is longer than the delta b.
add
(Fn [(Ref Datetime a), (Ref Duration b)] Datetime)
(add dt delta)
adds a Duration delta to a Datetime dt.
between
(Fn [(Ref Datetime a), (Ref Datetime b)] Duration)
(between a b)
returns the signed difference between the Datetimes a and b
as a Duration.
The result is positive when a is later than b, and negative when a is
earlier, mirroring Datetime.diff.
minus
(Fn [(Ref Duration a), (Ref Duration b)] Duration)
(minus a b)
returns the difference of the deltas a and b.
mul
(Fn [(Ref Duration a), Int] Duration)
(mul d n)
returns the delta d scaled by the integer factor n. An alias for
scale.
neg?
(Fn [(Ref Duration a)] Bool)
(neg? d)
checks whether the delta d represents a negative duration.
plus
(Fn [(Ref Duration a), (Ref Duration b)] Duration)
(plus a b)
returns the sum of the deltas a and b.
pos?
(Fn [(Ref Duration a)] Bool)
(pos? d)
checks whether the delta d represents a positive duration.
scale
(Fn [(Ref Duration a), Int] Duration)
(scale d n)
returns the delta d scaled by the integer factor n.
str
(Fn [(Ref Duration a)] String)
(str d)
renders the delta d in a human-readable form such as 1d 2h 3m 4s.
Components that are zero are omitted, a negative delta is prefixed with a -,
and the zero delta renders as 0s.
sub
(Fn [(Ref Datetime a), (Ref Duration b)] Datetime)
(sub dt delta)
subtracts a Duration delta from a Datetime dt.
to-days
(Fn [(Ref Duration a)] Int)
(to-days d)
returns the total number of whole days represented by the delta
d, truncating any remainder toward zero.
to-hours
(Fn [(Ref Duration a)] Int)
(to-hours d)
returns the total number of whole hours represented by the delta
d, truncating any remainder toward zero.
to-minutes
(Fn [(Ref Duration a)] Int)
(to-minutes d)
returns the total number of whole minutes represented by the
delta d, truncating any remaining seconds toward zero.
to-seconds
(Fn [(Ref Duration a)] Int)
(to-seconds d)
returns the total number of seconds represented by the delta
d.
zero?
(Fn [(Ref Duration a)] Bool)
(zero? d)
checks whether the delta d represents no elapsed time.