Skip to main content

IntoTimestamp

Trait IntoTimestamp 

Source
pub trait IntoTimestamp {
    // Required method
    fn into_timestamp_string(self) -> String;
}
Expand description

Converts a user-supplied timestamp value into the wire form accepted by the API (a nanosecond count encoded as a JSON string).

Implemented for:

  • i64 — treated as nanoseconds since the Unix epoch.
  • &str and String — passed through verbatim (caller’s responsibility to supply a format the API accepts: ISO 8601 or a nanosecond string).
  • Nanos.
  • chrono::DateTime<Utc> when the chrono feature is enabled.
  • time::OffsetDateTime when the time feature is enabled.

§Panics

The chrono::DateTime<Utc> impl panics if the datetime falls outside the i64 nanosecond range (roughly 1677-09-21 to 2262-04-11). Any realistic trading-data timestamp is comfortably within range.

§Examples

use ticksupply::IntoTimestamp;
assert_eq!(1_704_067_200_000_000_000_i64.into_timestamp_string(), "1704067200000000000");
assert_eq!("2024-01-01T00:00:00Z".into_timestamp_string(), "2024-01-01T00:00:00Z");

Required Methods§

Source

fn into_timestamp_string(self) -> String

Encodes the timestamp as a string suitable for the API.

§Examples
use ticksupply::IntoTimestamp;
assert_eq!(123_i64.into_timestamp_string(), "123");

Implementations on Foreign Types§

Source§

impl IntoTimestamp for &str

Source§

impl IntoTimestamp for i64

Source§

impl IntoTimestamp for String

Source§

impl IntoTimestamp for DateTime<Utc>

Available on crate feature chrono only.
Source§

impl IntoTimestamp for OffsetDateTime

Available on crate feature time only.

Implementors§