Struct unix_ts::Timestamp[][src]

pub struct Timestamp { /* fields omitted */ }
Expand description

A representation of a timestamp (seconds and nanos since the Unix epoch).

Timestamps are able to be easily converted into chrono DateTimes.

Implementations

Create a new timestamp from the given number of seconds and nanos (nanoseconds).

The use of the ts!() macro in the unix-ts-macros crate is advised in lieu of calling this method directly for most situations.

Note: For negative timestamps, the nanos argument is always a positive offset. Therefore, the correct way to represent a timestamp of -0.25 seconds is to call new(-1, 750_000_000).

Return the seconds since the Unix epoch. Sub-second values are discarded.

Examples

use unix_ts::Timestamp;

let t = Timestamp::from(1335020400);
assert_eq!(t.seconds(), 1335020400);

Return the time since the Unix epoch, as an integer, with the given precision.

Arguments

  • e (u8) - The precision for the returned integer, as a power of 10. (ex. 3 for milliseconds, 6 for microseconds, etc.). Must be a value between 0 and 9.

Examples

use unix_ts::Timestamp;

let t = Timestamp::from(1335020400);
assert_eq!(t.at_precision(3), 1335020400_000);
assert_eq!(t.at_precision(6), 1335020400_000_000);

Return the subsecond component at the specified precision (ex. 3 for milliseconds, 6 for microseconds); max precision is 9.

Arguments

  • e (u8) - The precision for the returned subsecond value, as a power of 10 (ex. 3 for milliseconds, 6 for microseconds, etc.). Must be a value between 0 and 9.

Examples

use unix_ts::Timestamp;

let t = Timestamp::new(1335020400, 500_000_000);
assert_eq!(t.subsec(1), 5);
assert_eq!(t.subsec(3), 500);

Trait Implementations

Add the provided duration to the timestamp.

The resulting type after applying the + operator.

Add the provided duration to the timestamp.

The resulting type after applying the + operator.

Add two timestamps to one another and return the result.

The resulting type after applying the + operator.

Add the provided duration to the timestamp, in-place.

Add the provided duration to the timestamp, in-place.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Create a new timestamp from the given std::time::Duration.

Create a new timestamp for the given number of seconds.

Create a new Duration from the given timestamp.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Subtract the provided duration from the timestamp.

The resulting type after applying the - operator.

Subtract the provided duration to the timestamp.

The resulting type after applying the - operator.

Subtract the provided timestamp from this one and return the result.

The resulting type after applying the - operator.

Subtract the provided duration to the timestamp, in-place.

Subtract the provided duration to the timestamp, in-place.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.