Skip to main content
Version: edge

nanos

Utilities for dealing with nanoseconds

Constants

NANOS_PER_DAY

type: U64

The amount of nanoseconds in a day

NANOS_PER_HOUR

type: U64

The amount of nanoseconds in an hour

NANOS_PER_MICROSECOND

type: U64

The amount of nanoseconds in a microsecond

NANOS_PER_MILLISECOND

type: U64

The amount of nanoseconds in a millisecond

NANOS_PER_MINUTE

type: U64

The amount of nanoseconds in a minute

NANOS_PER_SECOND

type: U64

The amount of nanoseconds in a second

NANOS_PER_WEEK

type: U64

The amount of nanoseconds in a week

Functions

from_days(days)

convert the given days to nanoseconds

use std::time::nanos;
nanos::from_days(1) # 86400000000000

Returns an integer

from_hours(hours)

convert the given hours to nanoseconds

use std::time::nanos;
nanos::from_hours(1) # 3600000000000

Returns an integer

from_micros(micros)

Convert the given microseconds to nanoseconds

use std::time::nanos;
nanos::from_micros(1) # 1000

Returns an integer

from_millis(millis)

Convert the given milliseconds to nanoseconds

use std::time::nanos;
nanos::from_millis(1) # 1000000

Returns an integer

from_minutes(minutes)

convert the given minutes to nanoseconds

use std::time::nanos;
nanos::from_minutes(1) # 60000000000

Returns an integer

from_seconds(secs)

Convert the given seconds to nanoseconds

use std::time::nanos;
nanos::from_seconds(1) # 1000000000

Returns an integer

from_weeks(weeks)

convert the given weeks to nanoseconds

use std::time::nanos;
nanos::from_weeks(1) # 604800000000000

Returns an integer

to_days(nanos)

Convert the given nanoseconds to days

Returns an integer

to_hours(nanos)

Convert the given nanoseconds to hours

Returns an integer

to_micros(nanos)

Convert the given nanoseconds to microseconds

Returns an integer

to_millis(nanos)

Convert the given nanoseconds to milliseconds

Returns an integer

to_minutes(nanos)

Convert the given nanoseconds to minutes

Returns an integer

to_seconds(nanos)

Convert the given nanoseconds to seconds

Returns an integer

to_weeks(nanos)

Convert the given nanoseconds to weeks

Returns an integer

truncate_days(nanos)

Truncate down to the next day

This function does not take leap-seconds or any other datetime fanciness into account. This is plain timestamp math.

use std::time::nanos;
nanos::truncate_days(86_499_999_999_999)
# result: 86_400_000_000_000

truncate_hours(nanos)

Truncate down to the next hour

This function does not take leap-seconds or any other datetime fanciness into account. This is plain timestamp math.

use std::time::nanos;
nanos::truncate_hours(3_699_999_999_999)
# result: 3_600_000_000_000

truncate_micros(nanos)

Truncate down to the next microsecond.

This function does not take leap-seconds or any other datetime fanciness into account. This is plain timestamp math.

use std::time::nanos;
nanos::truncate_micros(9999)
# result: 9000

truncate_millis(nanos)

Truncate down to the next millisecond

This function does not take leap-seconds or any other datetime fanciness into account. This is plain timestamp math.

use std::time::nanos;
nanos::truncate_millis(9_999_999)
# result: 9_000_000

truncate_minutes(nanos)

Truncate down to the next minute

This function does not take leap-seconds or any other datetime fanciness into account. This is plain timestamp math.

use std::time::nanos;
nanos::truncate_minutes(69_999_999_999)
# result: 60_000_000_000

truncate_seconds(nanos)

Truncate down to the next second

This function does not take leap-seconds or any other datetime fanciness into account. This is plain timestamp math.

use std::time::nanos;
nanos::truncate_seconds(9_999_999_999)
# result: 9_000_000_000