Skip to content

Commit 88464b5

Browse files
committed
fix(datastore): fixed deprecations in chrono (timestamp_nanos and from_utc)
1 parent 98487bb commit 88464b5

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

aw-datastore/src/datastore.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::collections::HashMap;
33
use chrono::DateTime;
44
use chrono::Duration;
55
use chrono::NaiveDateTime;
6+
use chrono::TimeZone;
67
use chrono::Utc;
78

89
use rusqlite::Connection;
@@ -232,9 +233,9 @@ impl DatastoreInstance {
232233
Some(starttime_ns) => {
233234
let seconds: i64 = starttime_ns / 1_000_000_000;
234235
let subnanos: u32 = (starttime_ns % 1_000_000_000) as u32;
235-
Some(DateTime::<Utc>::from_utc(
236-
NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
237-
Utc,
236+
Some(TimeZone::from_utc_datetime(
237+
&Utc,
238+
&NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
238239
))
239240
}
240241
None => None,
@@ -245,9 +246,9 @@ impl DatastoreInstance {
245246
Some(endtime_ns) => {
246247
let seconds: i64 = endtime_ns / 1_000_000_000;
247248
let subnanos: u32 = (endtime_ns % 1_000_000_000) as u32;
248-
Some(DateTime::<Utc>::from_utc(
249-
NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
250-
Utc,
249+
Some(TimeZone::from_utc_datetime(
250+
&Utc,
251+
&NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
251252
))
252253
}
253254
None => None,
@@ -450,7 +451,7 @@ impl DatastoreInstance {
450451
}
451452
};
452453
for event in &mut events {
453-
let starttime_nanos = event.timestamp.timestamp_nanos();
454+
let starttime_nanos = event.timestamp.timestamp_nanos_opt().unwrap();
454455
let duration_nanos = match event.duration.num_nanoseconds() {
455456
Some(nanos) => nanos,
456457
None => {
@@ -577,7 +578,7 @@ impl DatastoreInstance {
577578
)))
578579
}
579580
};
580-
let starttime_nanos = event.timestamp.timestamp_nanos();
581+
let starttime_nanos = event.timestamp.timestamp_nanos_opt().unwrap();
581582
let duration_nanos = match event.duration.num_nanoseconds() {
582583
Some(nanos) => nanos,
583584
None => {
@@ -688,9 +689,9 @@ impl DatastoreInstance {
688689

689690
Ok(Event {
690691
id: Some(id),
691-
timestamp: DateTime::<Utc>::from_utc(
692-
NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
693-
Utc,
692+
timestamp: TimeZone::from_utc_datetime(
693+
&Utc,
694+
&NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
694695
),
695696
duration: Duration::nanoseconds(duration_ns),
696697
data,
@@ -720,11 +721,11 @@ impl DatastoreInstance {
720721
let mut list = Vec::new();
721722

722723
let starttime_filter_ns: i64 = match starttime_opt {
723-
Some(dt) => dt.timestamp_nanos(),
724+
Some(dt) => dt.timestamp_nanos_opt().unwrap(),
724725
None => 0,
725726
};
726727
let endtime_filter_ns: i64 = match endtime_opt {
727-
Some(dt) => dt.timestamp_nanos(),
728+
Some(dt) => dt.timestamp_nanos_opt().unwrap(),
728729
None => std::i64::MAX,
729730
};
730731
if starttime_filter_ns > endtime_filter_ns {
@@ -783,9 +784,9 @@ impl DatastoreInstance {
783784

784785
Ok(Event {
785786
id: Some(id),
786-
timestamp: DateTime::<Utc>::from_utc(
787-
NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
788-
Utc,
787+
timestamp: TimeZone::from_utc_datetime(
788+
&Utc,
789+
&NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
789790
),
790791
duration: Duration::nanoseconds(duration_ns),
791792
data,
@@ -819,11 +820,11 @@ impl DatastoreInstance {
819820
let bucket = self.get_bucket(bucket_id)?;
820821

821822
let starttime_filter_ns: i64 = match starttime_opt {
822-
Some(dt) => dt.timestamp_nanos(),
823+
Some(dt) => dt.timestamp_nanos_opt().unwrap(),
823824
None => 0,
824825
};
825826
let endtime_filter_ns: i64 = match endtime_opt {
826-
Some(dt) => dt.timestamp_nanos(),
827+
Some(dt) => dt.timestamp_nanos_opt().unwrap(),
827828
None => std::i64::MAX,
828829
};
829830
if starttime_filter_ns >= endtime_filter_ns {

0 commit comments

Comments
 (0)