Esc

span_to_duration

procedureextension3 overloadssince 0.36.1Source
  • macOS: span_to_duration works on macOS
  • Linux: span_to_duration works on Linux
  • Windows: span_to_duration works on Windows
  • Wasm: span_to_duration works on Wasm

overload 1

span_to_duration :: (value: Span) -> (Signed_Duration, Time_Error)

Converts clock units to elapsed time; calendar units require a relative value.

Example↗
d, error := span_to_duration(.{ minutes = 2, seconds = 3 });
assert(error.kind == .NONE && d.seconds == 123);

overload 2

span_to_duration :: (
    value: Span,
    relative: Date
) -> (Signed_Duration, Time_Error)

Uses a relative Date.

Example↗
d, error := span_to_duration(.{ days = 2 }, Date.{ 2024, 3, 10 });
assert(error.kind == .NONE && d.seconds == 2 * 86400);

overload 3

span_to_duration :: (
    value: Span,
    relative: Zoned
) -> (Signed_Duration, Time_Error)

Uses a relative Zoned.

Example↗
zone, zone_error := time_zone_from_posix("EST5EDT,M3.2.0,M11.1.0");
assert(zone_error.kind == .NONE);
defer time_zone_free(*zone);
start, _ := to_zoned(.{ .{ 2024, 3, 10 }, .{ 0, 0, 0, 0 } }, zone);
d, error := span_to_duration(.{ days = 1 }, start);
assert(error.kind == .NONE && d.seconds == 23 * 3600);

See also