std:datetime/Duration
std:datetime/Duration
Section titled “std:datetime/Duration”Canonical occurrence:
protos/lib/datetime/Duration.protos· Protos revision:e99b712ecf658a527b1fe82c8beba2c1286d8dc9.
Fixed elapsed amounts of time with nanosecond precision. A duration is a
frozen ordinary object with one Integer nanoseconds slot holding the
exact signed total amount; zero and negative durations exist. Integers are
exact and unbounded, so no host integer limit applies and no Float is
involved.
A duration is independent of calendars, months, years, offsets, zones, and
clocks: one day of 24 hours is exactly 86400 seconds of elapsed time. It is
not a calendar amount, so no operation applies a duration to a
std:datetime/Date, std:datetime/Time, or std:datetime/LocalDateTime;
calendar-relative amounts are std:datetime/Period values.
Every duration’s immediate delegation parent is this module, the canonical
duration factory and prototype. recognizes accepts exactly the durations
of this family: objects whose immediate parent is this module and whose
local slots are exactly the duration state and behavior slots with an
Integer amount. A nanoseconds slot under another parent, such as a
std:datetime/Instant, is not a duration.
Durations answer semantic equality through ==: two durations are equal
when both are durations and their total amounts are equal. hash is coherent with that equality,
so independently constructed equal durations work as the same Map key.
=== remains ordinary object identity. compare is the natural total
order of the amounts and answers 0 exactly for equal durations.
Observable top-level slots
Section titled “Observable top-level slots”This page lists the complete mechanically observable top-level slot inventory required by D067. Authored documentation, when present, is canonical D062 prose; mechanical presence alone does not create a stability or compatibility promise.
Answers a fresh duration whose amount is exactly the sum of the amounts of
durations left and right. Non-duration arguments signal an Error.
Mechanical facts
Section titled “Mechanical facts”-
Fixed parameters:
left,right -
Rest parameter: none
-
Source occurrence:
protos/lib/datetime/Duration.protos:115 -
Exact source page: open in the source browser
Answers a fresh frozen duration of exactly nanoseconds nanoseconds.
nanoseconds must be an Integer and may be positive, zero, or negative;
any other argument signals an Error.
Mechanical facts
Section titled “Mechanical facts”-
Fixed parameters:
nanoseconds -
Rest parameter: none
-
Source occurrence:
protos/lib/datetime/Duration.protos:44 -
Exact source page: open in the source browser
compare
Section titled “compare”Answers -1, 0, or 1 as duration left is shorter than, equal to, or
longer than duration right, comparing signed total amounts. The result is
0 exactly when left == right. Arguments must be durations recognized by
this module; otherwise an Error is signalled.
Mechanical facts
Section titled “Mechanical facts”-
Fixed parameters:
left,right -
Rest parameter: none
-
Source occurrence:
protos/lib/datetime/Duration.protos:96 -
Exact source page: open in the source browser
negate
Section titled “negate”Answers a fresh duration with the exact opposite amount of duration.
A non-duration argument signals an Error.
Mechanical facts
Section titled “Mechanical facts”-
Fixed parameters:
duration -
Rest parameter: none
-
Source occurrence:
protos/lib/datetime/Duration.protos:134 -
Exact source page: open in the source browser
recognizes
Section titled “recognizes”Answers true exactly when value is a duration of this family: its
immediate delegation parent is this module, its local slots are exactly
nanoseconds, equals, ==, and hash, and nanoseconds is an Integer.
Answers false for any other value.
Mechanical facts
Section titled “Mechanical facts”-
Fixed parameters:
value -
Rest parameter: none
-
Source occurrence:
protos/lib/datetime/Duration.protos:79 -
Exact source page: open in the source browser
subtract
Section titled “subtract”Answers a fresh duration whose amount is exactly the amount of left minus
the amount of right; equivalent to add(left, negate(right)).
Non-duration arguments signal an Error.
Mechanical facts
Section titled “Mechanical facts”-
Fixed parameters:
left,right -
Rest parameter: none
-
Source occurrence:
protos/lib/datetime/Duration.protos:127 -
Exact source page: open in the source browser
Exact module source · Standard-library API · Standard library overview