Crate timelane

Crate timelane 

Source
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::Scaler functions 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 Mark 0.
LEAP_SECONDS_MARKS
All known leap seconds, as minute Mark.

Functions§

day_to_hour
Converts a day Mark to an hour Mark.
day_to_month
Converts a day Mark to a rounded down month Mark.
day_to_month_up
Converts a day Mark to a rounded up month Mark.
hour_to_day
Converts an hour Mark to a rounded down day Mark.
hour_to_day_up
Converts an hour Mark to a rounded up day Mark.
hour_to_minute
Converts an hour Mark to a minute Mark.
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_YEAR and a given year according to UTC.
minute_to_hour
Converts a minute Mark to a rounded down hour Mark.
minute_to_hour_up
Converts a minute Mark to a rounded up hour Mark.
minute_to_second
Converts a minute Mark to a second Mark.
month_to_day
Converts a month Mark to a day Mark.
month_to_year
Converts a month Mark to a rounded down year Mark.
month_to_year_up
Converts a month Mark to a rounded up year Mark.
second_to_minute
Converts a second Mark to a rounded down minute Mark.
second_to_minute_up
Converts a second Mark to a rounded up minute Mark.
year_to_month
Converts a year Mark to a month Mark.

Type Aliases§

Mark
A specific point on a time lane.
Scaler
A function to convert a Mark from one lane to another.