Skip to content

Commit

Permalink
Introduce UnixNanos newtype in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 14, 2024
1 parent 59e5834 commit 9f9e689
Show file tree
Hide file tree
Showing 153 changed files with 1,271 additions and 1,054 deletions.
10 changes: 5 additions & 5 deletions nautilus_core/adapters/src/databento/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
//! Common functions to support Databento adapter operations.
use databento::historical::DateTimeRange;
use nautilus_core::time::UnixNanos;
use nautilus_core::nanos::UnixNanos;
use time::OffsetDateTime;

pub const DATABENTO: &str = "DATABENTO";
pub const ALL_SYMBOLS: &str = "ALL_SYMBOLS";

pub fn get_date_time_range(start: UnixNanos, end: UnixNanos) -> anyhow::Result<DateTimeRange> {
Ok(DateTimeRange::from((
OffsetDateTime::from_unix_timestamp_nanos(i128::from(start))?,
OffsetDateTime::from_unix_timestamp_nanos(i128::from(end))?,
OffsetDateTime::from_unix_timestamp_nanos(i128::from(start.as_u64()))?,
OffsetDateTime::from_unix_timestamp_nanos(i128::from(end.as_u64()))?,
)))
}

Expand All @@ -39,8 +39,8 @@ mod tests {
use super::*;

#[rstest]
#[case(0, 0, "DateTimeRange { start: 1970-01-01 0:00:00.0 +00:00:00, end: 1970-01-01 0:00:00.0 +00:00:00 }")]
#[case(0, 1_000_000_000, "DateTimeRange { start: 1970-01-01 0:00:00.0 +00:00:00, end: 1970-01-01 0:00:01.0 +00:00:00 }")]
#[case(UnixNanos::default(), UnixNanos::default(), "DateTimeRange { start: 1970-01-01 0:00:00.0 +00:00:00, end: 1970-01-01 0:00:00.0 +00:00:00 }")]
#[case(UnixNanos::default(), 1_000_000_000.into(), "DateTimeRange { start: 1970-01-01 0:00:00.0 +00:00:00, end: 1970-01-01 0:00:01.0 +00:00:00 }")]
fn test_get_date_time_range(
#[case] start: UnixNanos,
#[case] end: UnixNanos,
Expand Down
Loading

0 comments on commit 9f9e689

Please sign in to comment.