Expand description
Convert between nanoseconds, seconds, days, years… in const.
The timelane crate defines lanes of time where each lane works at a
different scale: yearly, monthly, daily, etc. Each lane has sequentially
numbered marks. The crate implements scaler functions to convert a mark in
one lane into a mark in another lane.
For instance, mark 1 in the month lane is mark 1 in the day lane, mark 2 in the month lane is mark 32 in the day lane.
Mark values are signed integers.
Scaler functions can be composed to convert Mark from non-adjacent
lanes, like converting a year mark into a second mark.
A mark from a small scale lane can also be converted to a mark in a larger scale lane, like second to year, but you need to chose between rounding down or rounding up. Scaling a second mark to a year mark and then back to a second mark will give the beginning or the end of the year, depending on the rounding mode.
All Scaler functions are const functions. Leap seconds are statically
defined.
This library will return incorrect results if the International Earth Rotation and Reference Systems Service declares a new leap second.
However, the last leap second was in 2017 and the General Conference on Weights and Measures resolved to eliminate leap seconds by or before 2035.
- Years before 1AD use the astronomical year numbering: the year 1BC is
mark
0, 2BC is-1… - Leap years follow the proleptic gregorian calendar, and are defined even for negative years: 1BC is a leap year.
- Because of leap seconds, some minutes will contain 61 seconds.
- Before using this library, make sure you actually want to work with UTC. Many systems use GPS or TAI, which do not include leap seconds.
Modules§
- subsecond
- Extra
crate::Scalerfunctions to handle sub-second resolutions: milli, micro and nanoseconds.
Constants§
- EPOCH_
YEAR - This year is the one where the first second of January 1st is the
Mark0. - LEAP_
SECONDS_ MARKS - All known leap seconds, as minute
Mark.
Functions§
- day_
to_ hour - Converts a day
Markto an hourMark. - day_
to_ month - Converts a day
Markto a rounded down monthMark. - day_
to_ month_ up - Converts a day
Markto a rounded up monthMark. - hour_
to_ day - Converts an hour
Markto a rounded down dayMark. - hour_
to_ day_ up - Converts an hour
Markto a rounded up dayMark. - hour_
to_ minute - Converts an hour
Markto a minuteMark. - leap_
days_ before_ year - Returns the number of leap days between year 1 and a given year according to the proleptic gregorian calendar.
- leap_
seconds_ before_ minute - Returns the number of leap seconds between day 1 of
EPOCH_YEARand a given year according to UTC. - minute_
to_ hour - Converts a minute
Markto a rounded down hourMark. - minute_
to_ hour_ up - Converts a minute
Markto a rounded up hourMark. - minute_
to_ second - Converts a minute
Markto a secondMark. - month_
to_ day - Converts a month
Markto a dayMark. - month_
to_ year - Converts a month
Markto a rounded down yearMark. - month_
to_ year_ up - Converts a month
Markto a rounded up yearMark. - second_
to_ minute - Converts a second
Markto a rounded down minuteMark. - second_
to_ minute_ up - Converts a second
Markto a rounded up minuteMark. - year_
to_ month - Converts a year
Markto a monthMark.