Skip to content

Commit

Permalink
Use Utc to construct DateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Lun4m committed May 29, 2024
1 parent 6961308 commit fc59c5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions ingestion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl FromRef<IngestorState> for Arc<RwLock<(ParamPermitTable, StationPermitTable
}

/// Generic container for a piece of data ready to be inserted into the DB
#[derive(Clone)]
pub struct Datum {
timeseries_id: i32,
timestamp: DateTime<Utc>,
Expand Down
22 changes: 9 additions & 13 deletions lard_tests/tests/ingestion_integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// use std::fs;
use std::str::FromStr;

use chrono::DateTime;
use chrono::{TimeZone, Utc};
use lard_ingestion::{insert_data, Datum};
mod common;

Expand All @@ -11,19 +8,18 @@ async fn test_insert_data() {
let mut conn = pool.get().await.unwrap();

// Prepare data
let fromtime = DateTime::from_str("2024-05-28T11:06:00Z").unwrap();
let totime = DateTime::from_str("2024-05-28T15:06:00Z").unwrap();

let data = vec![
Datum::new(1, fromtime, 1.),
Datum::new(1, DateTime::from_str("2024-05-28T12:06:00Z").unwrap(), 2.),
Datum::new(1, DateTime::from_str("2024-05-28T13:06:00Z").unwrap(), 3.),
Datum::new(1, DateTime::from_str("2024-05-28T14:06:00Z").unwrap(), 4.),
Datum::new(1, totime, 6.),
Datum::new(1, Utc.with_ymd_and_hms(2024, 5, 28, 11, 6, 00).unwrap(), 1.),
Datum::new(1, Utc.with_ymd_and_hms(2024, 5, 28, 12, 6, 00).unwrap(), 2.),
Datum::new(1, Utc.with_ymd_and_hms(2024, 5, 28, 13, 6, 00).unwrap(), 3.),
Datum::new(1, Utc.with_ymd_and_hms(2024, 5, 28, 14, 6, 00).unwrap(), 4.),
Datum::new(1, Utc.with_ymd_and_hms(2024, 5, 28, 15, 6, 00).unwrap(), 5.),
];
let data_len = data.len();

// No error if inserting same data?
insert_data(data.clone(), &mut conn).await.unwrap();

// No error or warning if overwriting data?
if let Err(e) = insert_data(data, &mut conn).await {
eprintln!("{}", e);
}
Expand Down

0 comments on commit fc59c5d

Please sign in to comment.