Skip to content

Commit

Permalink
fix(datastore): fixed deprecations in chrono (timestamp_nanos and fro…
Browse files Browse the repository at this point in the history
…m_utc)
  • Loading branch information
ErikBjare committed Oct 29, 2023
1 parent 98487bb commit 88464b5
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions aw-datastore/src/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::HashMap;
use chrono::DateTime;
use chrono::Duration;
use chrono::NaiveDateTime;
use chrono::TimeZone;
use chrono::Utc;

use rusqlite::Connection;
Expand Down Expand Up @@ -232,9 +233,9 @@ impl DatastoreInstance {
Some(starttime_ns) => {
let seconds: i64 = starttime_ns / 1_000_000_000;
let subnanos: u32 = (starttime_ns % 1_000_000_000) as u32;
Some(DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
Utc,
Some(TimeZone::from_utc_datetime(
&Utc,
&NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
))
}
None => None,
Expand All @@ -245,9 +246,9 @@ impl DatastoreInstance {
Some(endtime_ns) => {
let seconds: i64 = endtime_ns / 1_000_000_000;
let subnanos: u32 = (endtime_ns % 1_000_000_000) as u32;
Some(DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
Utc,
Some(TimeZone::from_utc_datetime(
&Utc,
&NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
))
}
None => None,
Expand Down Expand Up @@ -450,7 +451,7 @@ impl DatastoreInstance {
}
};
for event in &mut events {
let starttime_nanos = event.timestamp.timestamp_nanos();
let starttime_nanos = event.timestamp.timestamp_nanos_opt().unwrap();
let duration_nanos = match event.duration.num_nanoseconds() {
Some(nanos) => nanos,
None => {
Expand Down Expand Up @@ -577,7 +578,7 @@ impl DatastoreInstance {
)))
}
};
let starttime_nanos = event.timestamp.timestamp_nanos();
let starttime_nanos = event.timestamp.timestamp_nanos_opt().unwrap();
let duration_nanos = match event.duration.num_nanoseconds() {
Some(nanos) => nanos,
None => {
Expand Down Expand Up @@ -688,9 +689,9 @@ impl DatastoreInstance {

Ok(Event {
id: Some(id),
timestamp: DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
Utc,
timestamp: TimeZone::from_utc_datetime(
&Utc,
&NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
),
duration: Duration::nanoseconds(duration_ns),
data,
Expand Down Expand Up @@ -720,11 +721,11 @@ impl DatastoreInstance {
let mut list = Vec::new();

let starttime_filter_ns: i64 = match starttime_opt {
Some(dt) => dt.timestamp_nanos(),
Some(dt) => dt.timestamp_nanos_opt().unwrap(),
None => 0,
};
let endtime_filter_ns: i64 = match endtime_opt {
Some(dt) => dt.timestamp_nanos(),
Some(dt) => dt.timestamp_nanos_opt().unwrap(),
None => std::i64::MAX,
};
if starttime_filter_ns > endtime_filter_ns {
Expand Down Expand Up @@ -783,9 +784,9 @@ impl DatastoreInstance {

Ok(Event {
id: Some(id),
timestamp: DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
Utc,
timestamp: TimeZone::from_utc_datetime(
&Utc,
&NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
),
duration: Duration::nanoseconds(duration_ns),
data,
Expand Down Expand Up @@ -819,11 +820,11 @@ impl DatastoreInstance {
let bucket = self.get_bucket(bucket_id)?;

let starttime_filter_ns: i64 = match starttime_opt {
Some(dt) => dt.timestamp_nanos(),
Some(dt) => dt.timestamp_nanos_opt().unwrap(),
None => 0,
};
let endtime_filter_ns: i64 = match endtime_opt {
Some(dt) => dt.timestamp_nanos(),
Some(dt) => dt.timestamp_nanos_opt().unwrap(),
None => std::i64::MAX,
};
if starttime_filter_ns >= endtime_filter_ns {
Expand Down

0 comments on commit 88464b5

Please sign in to comment.