Skip to main content

Module convert

Module convert 

Expand description

Exact numeric conversions for calendar quantities.

Date arithmetic hands back i64 day counts and u32 year/month/day components; day-count fractions and schedule maths need them as f64 or i32. Every such conversion in this crate is provably exact, but written as a bare cast it is indistinguishable from one that is not โ€” so the casts live here, once, with the bound that makes them safe stated alongside.

Functionsยง

count_to_f64 ๐Ÿ”’
A count of periods as a float โ€” a fixed leg has tens of periods, never more than a mantissa holds, so the widening is exact.
count_to_i64 ๐Ÿ”’
Converts a count of elements to i64.
days_to_f64 ๐Ÿ”’
Converts a whole-day count to f64.
days_to_index ๐Ÿ”’
Converts a non-negative day count to u32, for indexing a per-day table.
days_to_offset ๐Ÿ”’
Converts a non-negative day count to u64, for chronoโ€™s Days.
months_to_offset ๐Ÿ”’
Converts a non-negative span in months to u32, for chronoโ€™s Months.
seconds_to_f64 ๐Ÿ”’
Converts an elapsed-seconds count to f64.
week_index ๐Ÿ”’
Converts a non-negative weekday offset to an index into a week mask.
ymd_from_i32 ๐Ÿ”’
Converts a year, month, or day-of-month component computed in i32 back to u32.
ymd_to_i32 ๐Ÿ”’
Converts a year, month, or day-of-month component โ€” or a span in months โ€” to i32.