Compare commits

..

No commits in common. "d2f4ec97c0a787b20ab88c03331fe23a852f5549" and "85e2494c3bbbd12b8a582728a88242b334f1873f" have entirely different histories.

4 changed files with 119 additions and 215 deletions

View File

@ -71,9 +71,11 @@ extern crate thiserror;
extern crate uuid;
mod criteria;
mod date_time_tz;
mod series;
mod types;
pub use criteria::*;
pub use date_time_tz::DateTimeTz;
pub use series::Series;
pub use types::{EmseriesReadError, EmseriesWriteError, RecordId, Recordable, Timestamp};
pub use types::{EmseriesReadError, EmseriesWriteError, Recordable, Timestamp, UniqueId};

View File

@ -24,7 +24,7 @@ use std::io::{BufRead, BufReader, LineWriter, Write};
use std::iter::Iterator;
use criteria::Criteria;
use types::{EmseriesReadError, EmseriesWriteError, Record, RecordId, Recordable};
use types::{EmseriesReadError, EmseriesWriteError, Record, Recordable, UniqueId};
/// An open time series database.
///
@ -33,7 +33,7 @@ use types::{EmseriesReadError, EmseriesWriteError, Record, RecordId, Recordable}
pub struct Series<T: Clone + Recordable + DeserializeOwned + Serialize> {
//path: String,
writer: LineWriter<File>,
records: HashMap<RecordId, T>,
records: HashMap<UniqueId, T>,
}
impl<T> Series<T>
@ -62,8 +62,8 @@ where
}
/// Load a file and return all of the records in it.
fn load_file(f: &File) -> Result<HashMap<RecordId, T>, EmseriesReadError> {
let mut records: HashMap<RecordId, T> = HashMap::new();
fn load_file(f: &File) -> Result<HashMap<UniqueId, T>, EmseriesReadError> {
let mut records: HashMap<UniqueId, T> = HashMap::new();
let reader = BufReader::new(f);
for line in reader.lines() {
match line {
@ -87,14 +87,14 @@ where
/// Put a new record into the database. A unique id will be assigned to the record and
/// returned.
pub fn put(&mut self, entry: T) -> Result<RecordId, EmseriesWriteError> {
let uuid = RecordId::default();
pub fn put(&mut self, entry: T) -> Result<UniqueId, EmseriesWriteError> {
let uuid = UniqueId::default();
self.update(uuid.clone(), entry).map(|_| uuid)
}
/// Update an existing record. The [RecordId] of the record passed into this function must match
/// the [RecordId] of a record already in the database.
pub fn update(&mut self, uuid: RecordId, entry: T) -> Result<(), EmseriesWriteError> {
/// Update an existing record. The `UniqueId` of the record passed into this function must match
/// the `UniqueId` of a record already in the database.
pub fn update(&mut self, uuid: UniqueId, entry: T) -> Result<(), EmseriesWriteError> {
self.records.insert(uuid.clone(), entry.clone());
let write_res = match serde_json::to_string(&Record {
id: uuid,
@ -118,7 +118,7 @@ where
/// Future note: while this deletes a record from the view, it only adds an entry to the
/// database that indicates `data: null`. If record histories ever become important, the record
/// and its entire history (including this delete) will still be available.
pub fn delete(&mut self, uuid: &RecordId) -> Result<(), EmseriesWriteError> {
pub fn delete(&mut self, uuid: &UniqueId) -> Result<(), EmseriesWriteError> {
if !self.records.contains_key(uuid) {
return Ok(());
};
@ -138,7 +138,7 @@ where
}
/// Get all of the records in the database.
pub fn records(&self) -> impl Iterator<Item = (&RecordId, &T)> {
pub fn records(&self) -> impl Iterator<Item = (&UniqueId, &T)> {
self.records.iter()
}
@ -148,29 +148,29 @@ where
pub fn search<'s>(
&'s self,
criteria: impl Criteria + 's,
) -> impl Iterator<Item = (&'s RecordId, &'s T)> + 's {
) -> impl Iterator<Item = (&'s UniqueId, &'s T)> + 's {
self.records().filter(move |&tr| criteria.apply(tr.1))
}
/// Perform a search and sort the resulting records based on the comparison.
pub fn search_sorted<'s, C, CMP>(&'s self, criteria: C, compare: CMP) -> Vec<(&RecordId, &T)>
pub fn search_sorted<'s, C, CMP>(&'s self, criteria: C, compare: CMP) -> Vec<(&UniqueId, &T)>
where
C: Criteria + 's,
CMP: FnMut(&(&RecordId, &T), &(&RecordId, &T)) -> Ordering,
CMP: FnMut(&(&UniqueId, &T), &(&UniqueId, &T)) -> Ordering,
{
let search_iter = self.search(criteria);
let mut records: Vec<(&RecordId, &T)> = search_iter.collect();
let mut records: Vec<(&UniqueId, &T)> = search_iter.collect();
records.sort_by(compare);
records
}
/// Get an exact record from the database based on unique id.
pub fn get(&self, uuid: &RecordId) -> Option<T> {
pub fn get(&self, uuid: &UniqueId) -> Option<T> {
self.records.get(uuid).cloned()
}
/*
pub fn remove(&self, uuid: RecordId) -> Result<(), EmseriesError> {
pub fn remove(&self, uuid: UniqueId) -> Result<(), EmseriesError> {
unimplemented!()
}
*/

View File

@ -10,8 +10,8 @@ Luminescent Dreams Tools is distributed in the hope that it will be useful, but
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
*/
use chrono::{DateTime, FixedOffset, NaiveDate};
use chrono_tz::UTC;
use chrono::NaiveDate;
use date_time_tz::DateTimeTz;
use serde::de::DeserializeOwned;
use serde::ser::Serialize;
use std::{cmp::Ordering, fmt, io, str};
@ -44,79 +44,25 @@ pub enum EmseriesWriteError {
JSONWriteError(serde_json::error::Error),
}
#[derive(Debug, Clone, PartialEq, Eq)]
/// A Timestamp, stored with reference to human reckoning. This could be either a Naive Date or a
/// date and a time with a timezone. The idea of the "human reckoning" is that, no matter what
/// timezone the record was created in, we want to group things based on the date that the human
/// was perceiving at the time it was recorded.
pub enum Timestamp {
DateTime(DateTime<FixedOffset>),
Date(NaiveDate),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TimestampJS {
DateTime(String),
Date(String),
}
impl From<Timestamp> for TimestampJS {
fn from(s: Timestamp) -> TimestampJS {
match s {
Timestamp::DateTime(ts) => TimestampJS::DateTime(ts.to_rfc3339()),
Timestamp::Date(ts) => TimestampJS::Date(ts.to_string()),
}
}
}
impl From<TimestampJS> for Timestamp {
fn from(s: TimestampJS) -> Timestamp {
match s {
TimestampJS::DateTime(ts) => {
Timestamp::DateTime(DateTime::parse_from_rfc3339(&ts).unwrap())
}
TimestampJS::Date(ts) => Timestamp::Date(ts.parse::<NaiveDate>().unwrap()),
}
}
pub enum Timestamp {
DateTime(DateTimeTz),
Date(NaiveDate),
}
impl str::FromStr for Timestamp {
type Err = chrono::ParseError;
fn from_str(line: &str) -> Result<Self, Self::Err> {
DateTime::parse_from_rfc3339(line)
DateTimeTz::from_str(line)
.map(Timestamp::DateTime)
.or(NaiveDate::from_str(line).map(Timestamp::Date))
}
}
/*
impl PartialEq for Timestamp {
fn eq(&self, other: &Timestamp) -> bool {
match (self, other) {
(Timestamp::DateTime(dt1), Timestamp::DateTime(dt2)) => {
dt1.with_timezone(&UTC) == dt2.with_timezone(&UTC)
}
// It's not clear to me what would make sense when I'm comparing a date and a
// timestamp. I'm going with a naive date comparison on the idea that what I'm wanting
// here is human scale, again.
(Timestamp::DateTime(dt1), Timestamp::Date(dt2)) => dt1.date_naive() == *dt2,
(Timestamp::Date(dt1), Timestamp::DateTime(dt2)) => *dt1 == dt2.date_naive(),
(Timestamp::Date(dt1), Timestamp::Date(dt2)) => *dt1 == *dt2,
}
}
}
*/
impl PartialOrd for Timestamp {
fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering> {
// Some(self.cmp(other))
match (self, other) {
(Timestamp::DateTime(dt1), Timestamp::DateTime(dt2)) => dt1.partial_cmp(dt2),
(Timestamp::DateTime(dt1), Timestamp::Date(dt2)) => dt1.date_naive().partial_cmp(dt2),
(Timestamp::Date(dt1), Timestamp::DateTime(dt2)) => dt1.partial_cmp(&dt2.date_naive()),
(Timestamp::Date(dt1), Timestamp::Date(dt2)) => dt1.partial_cmp(dt2),
}
Some(self.cmp(other))
}
}
@ -124,13 +70,25 @@ impl Ord for Timestamp {
fn cmp(&self, other: &Timestamp) -> Ordering {
match (self, other) {
(Timestamp::DateTime(dt1), Timestamp::DateTime(dt2)) => dt1.cmp(dt2),
(Timestamp::DateTime(dt1), Timestamp::Date(dt2)) => dt1.date_naive().cmp(dt2),
(Timestamp::Date(dt1), Timestamp::DateTime(dt2)) => dt1.cmp(&dt2.date_naive()),
(Timestamp::DateTime(dt1), Timestamp::Date(dt2)) => dt1.0.date_naive().cmp(dt2),
(Timestamp::Date(dt1), Timestamp::DateTime(dt2)) => dt1.cmp(&dt2.0.date_naive()),
(Timestamp::Date(dt1), Timestamp::Date(dt2)) => dt1.cmp(dt2),
}
}
}
impl From<DateTimeTz> for Timestamp {
fn from(d: DateTimeTz) -> Self {
Self::DateTime(d)
}
}
impl From<NaiveDate> for Timestamp {
fn from(d: NaiveDate) -> Self {
Self::Date(d)
}
}
/// Any element to be put into the database needs to be Recordable. This is the common API that
/// will aid in searching and later in indexing records.
pub trait Recordable {
@ -145,26 +103,26 @@ pub trait Recordable {
///
/// This is a wrapper around a basic uuid with some extra convenience methods.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
pub struct RecordId(Uuid);
pub struct UniqueId(Uuid);
impl Default for RecordId {
impl Default for UniqueId {
fn default() -> Self {
Self(Uuid::new_v4())
}
}
impl str::FromStr for RecordId {
impl str::FromStr for UniqueId {
type Err = EmseriesReadError;
/// Parse a RecordId from a string. Raise UUIDParseError if the parsing fails.
/// Parse a UniqueId from a string. Raise UUIDParseError if the parsing fails.
fn from_str(val: &str) -> Result<Self, Self::Err> {
Uuid::parse_str(val)
.map(RecordId)
.map(UniqueId)
.map_err(EmseriesReadError::UUIDParseError)
}
}
impl fmt::Display for RecordId {
impl fmt::Display for UniqueId {
/// Convert to a hyphenated string
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(f, "{}", self.0.to_hyphenated())
@ -175,7 +133,7 @@ impl fmt::Display for RecordId {
/// Recordable trait.
#[derive(Clone, Deserialize, Serialize)]
pub struct Record<T: Clone + Recordable> {
pub id: RecordId,
pub id: UniqueId,
pub data: Option<T>,
}
@ -198,20 +156,21 @@ mod test {
use self::dimensioned::si::{Kilogram, KG};
use super::*;
use chrono::TimeZone;
use chrono_tz::Etc::UTC;
use chrono_tz::{Etc::UTC, US::Central};
use date_time_tz::DateTimeTz;
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Weight(Kilogram<f64>);
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct WeightRecord {
pub date: NaiveDate,
pub date: Timestamp,
pub weight: Weight,
}
impl Recordable for WeightRecord {
fn timestamp(&self) -> Timestamp {
Timestamp::Date(self.date.clone())
self.date.clone()
}
fn tags(&self) -> Vec<String> {
@ -220,14 +179,12 @@ mod test {
}
#[test]
fn timestamp_parses_utc_time() {
fn timestamp_parses_datetimetz_without_timezone() {
assert_eq!(
"2003-11-10T06:00:00Z".parse::<Timestamp>().unwrap(),
Timestamp::DateTime(
UTC.with_ymd_and_hms(2003, 11, 10, 6, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap())
),
Timestamp::DateTime(DateTimeTz(
UTC.with_ymd_and_hms(2003, 11, 10, 6, 0, 0).unwrap()
)),
);
}
@ -239,9 +196,9 @@ mod test {
);
}
#[ignore]
#[test]
fn v_alpha_serialization() {
const WEIGHT_ENTRY: &str = "{\"data\":{\"weight\":77.79109},\"date\":\"2003-11-10\",\"id\":\"3330c5b0-783f-4919-b2c4-8169c38f65ff\"}";
const WEIGHT_ENTRY: &str = "{\"data\":{\"weight\":77.79109,\"date\":\"2003-11-10T06:00:00.000000000000Z\"},\"id\":\"3330c5b0-783f-4919-b2c4-8169c38f65ff\"}";
let rec: Record<WeightRecord> = WEIGHT_ENTRY
.parse()
@ -253,7 +210,9 @@ mod test {
assert_eq!(
rec.data,
Some(WeightRecord {
date: NaiveDate::from_ymd_opt(2003, 11, 10).unwrap(),
date: Timestamp::DateTime(DateTimeTz(
UTC.with_ymd_and_hms(2003, 11, 10, 6, 0, 0).unwrap()
)),
weight: Weight(77.79109 * KG),
})
);
@ -262,53 +221,54 @@ mod test {
#[test]
fn serialization_output() {
let rec = WeightRecord {
date: NaiveDate::from_ymd_opt(2003, 11, 10).unwrap(),
date: Timestamp::DateTime(DateTimeTz(
UTC.with_ymd_and_hms(2003, 11, 10, 6, 0, 0).unwrap(),
)),
weight: Weight(77.0 * KG),
};
assert_eq!(
serde_json::to_string(&rec).unwrap(),
"{\"date\":\"2003-11-10\",\"weight\":77.0}"
"{\"date\":\"2003-11-10T06:00:00Z\",\"weight\":77.0}"
);
let rec2 = WeightRecord {
date: NaiveDate::from_ymd_opt(2003, 11, 10).unwrap(),
date: Timestamp::DateTime(
Central
.with_ymd_and_hms(2003, 11, 10, 0, 0, 0)
.unwrap()
.into(),
),
weight: Weight(77.0 * KG),
};
assert_eq!(
serde_json::to_string(&rec2).unwrap(),
"{\"date\":\"2003-11-10\",\"weight\":77.0}"
"{\"date\":\"2003-11-10T06:00:00Z US/Central\",\"weight\":77.0}"
);
}
#[test]
fn two_datetimes_can_be_compared() {
let time1 = Timestamp::DateTime(
UTC.with_ymd_and_hms(2003, 11, 10, 6, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
);
let time2 = Timestamp::DateTime(
UTC.with_ymd_and_hms(2003, 11, 11, 6, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
);
let time1 = Timestamp::DateTime(DateTimeTz(
UTC.with_ymd_and_hms(2003, 11, 10, 6, 0, 0).unwrap(),
));
let time2 = Timestamp::DateTime(DateTimeTz(
UTC.with_ymd_and_hms(2003, 11, 11, 6, 0, 0).unwrap(),
));
assert!(time1 < time2);
}
#[test]
fn two_dates_can_be_compared() {
let time1: Timestamp = Timestamp::Date(NaiveDate::from_ymd_opt(2003, 11, 10).unwrap());
let time2: Timestamp = Timestamp::Date(NaiveDate::from_ymd_opt(2003, 11, 11).unwrap());
let time1 = Timestamp::Date(NaiveDate::from_ymd_opt(2003, 11, 10).unwrap());
let time2 = Timestamp::Date(NaiveDate::from_ymd_opt(2003, 11, 11).unwrap());
assert!(time1 < time2);
}
#[test]
fn datetime_and_date_can_be_compared() {
let time1 = Timestamp::DateTime(
UTC.with_ymd_and_hms(2003, 11, 10, 6, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
);
let time1 = Timestamp::DateTime(DateTimeTz(
UTC.with_ymd_and_hms(2003, 11, 10, 6, 0, 0).unwrap(),
));
let time2 = Timestamp::Date(NaiveDate::from_ymd_opt(2003, 11, 11).unwrap());
assert!(time1 < time2)
}

View File

@ -20,7 +20,7 @@ extern crate emseries;
#[cfg(test)]
mod test {
use chrono::{format::Fixed, prelude::*};
use chrono::prelude::*;
use chrono_tz::Etc::UTC;
use dimensioned::si::{Kilogram, Meter, Second, M, S};
@ -34,7 +34,7 @@ mod test {
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
struct BikeTrip {
datetime: DateTime<FixedOffset>,
datetime: DateTimeTz,
distance: Distance,
duration: Duration,
comments: String,
@ -42,7 +42,7 @@ mod test {
impl Recordable for BikeTrip {
fn timestamp(&self) -> Timestamp {
Timestamp::DateTime(self.datetime.clone())
self.datetime.clone().into()
}
fn tags(&self) -> Vec<String> {
Vec::new()
@ -52,46 +52,31 @@ mod test {
fn mk_trips() -> [BikeTrip; 5] {
[
BikeTrip {
datetime: UTC
.with_ymd_and_hms(2011, 10, 29, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
datetime: DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 29, 0, 0, 0).unwrap()),
distance: Distance(58741.055 * M),
duration: Duration(11040.0 * S),
comments: String::from("long time ago"),
},
BikeTrip {
datetime: UTC
.with_ymd_and_hms(2011, 10, 31, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
datetime: DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()),
distance: Distance(17702.0 * M),
duration: Duration(2880.0 * S),
comments: String::from("day 2"),
},
BikeTrip {
datetime: UTC
.with_ymd_and_hms(2011, 11, 02, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
datetime: DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 02, 0, 0, 0).unwrap()),
distance: Distance(41842.945 * M),
duration: Duration(7020.0 * S),
comments: String::from("Do Some Distance!"),
},
BikeTrip {
datetime: UTC
.with_ymd_and_hms(2011, 11, 04, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
datetime: DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 04, 0, 0, 0).unwrap()),
distance: Distance(34600.895 * M),
duration: Duration(5580.0 * S),
comments: String::from("I did a lot of distance back then"),
},
BikeTrip {
datetime: UTC
.with_ymd_and_hms(2011, 11, 05, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
datetime: DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 05, 0, 0, 0).unwrap()),
distance: Distance(6437.376 * M),
duration: Duration(960.0 * S),
comments: String::from("day 5"),
@ -137,11 +122,7 @@ mod test {
Some(tr) => {
assert_eq!(
tr.timestamp(),
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 10, 29, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap())
)
DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 29, 0, 0, 0).unwrap()).into()
);
assert_eq!(tr.duration, Duration(11040.0 * S));
assert_eq!(tr.comments, String::from("long time ago"));
@ -162,12 +143,10 @@ mod test {
ts.put(trip.clone()).expect("expect a successful put");
}
let v: Vec<(&RecordId, &BikeTrip)> = ts
.search(exact_time(Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
)))
let v: Vec<(&UniqueId, &BikeTrip)> = ts
.search(exact_time(
DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(),
))
.collect();
assert_eq!(v.len(), 1);
assert_eq!(*v[0].1, trips[1]);
@ -185,19 +164,11 @@ mod test {
ts.put(trip.clone()).expect("expect a successful put");
}
let v: Vec<(&RecordId, &BikeTrip)> = ts.search_sorted(
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
time_range(
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
),
DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(),
true,
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 11, 04, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
),
DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 04, 0, 0, 0).unwrap()).into(),
true,
),
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
@ -226,19 +197,11 @@ mod test {
{
let ts: Series<BikeTrip> =
Series::open(&path).expect("expect the time series to open correctly");
let v: Vec<(&RecordId, &BikeTrip)> = ts.search_sorted(
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
time_range(
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
),
DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(),
true,
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 11, 04, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
),
DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 04, 0, 0, 0).unwrap()).into(),
true,
),
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
@ -268,20 +231,11 @@ mod test {
{
let mut ts: Series<BikeTrip> =
Series::open(&path).expect("expect the time series to open correctly");
let v: Vec<(&RecordId, &BikeTrip)> = ts.search_sorted(
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
time_range(
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
),
DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(),
true,
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 11, 04, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
)
.into(),
DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 04, 0, 0, 0).unwrap()).into(),
true,
),
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
@ -296,19 +250,11 @@ mod test {
{
let ts: Series<BikeTrip> =
Series::open(&path).expect("expect the time series to open correctly");
let v: Vec<(&RecordId, &BikeTrip)> = ts.search_sorted(
let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted(
time_range(
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
),
DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(),
true,
Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 11, 05, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
),
DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 05, 0, 0, 0).unwrap()).into(),
true,
),
|l, r| l.1.timestamp().cmp(&r.1.timestamp()),
@ -348,7 +294,7 @@ mod test {
Some(trip) => {
assert_eq!(
trip.datetime,
UTC.with_ymd_and_hms(2011, 11, 02, 0, 0, 0).unwrap()
DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 02, 0, 0, 0).unwrap())
);
assert_eq!(trip.distance, Distance(50000.0 * M));
assert_eq!(trip.duration, Duration(7020.0 * S));
@ -384,22 +330,18 @@ mod test {
let ts: Series<BikeTrip> =
Series::open(&path).expect("expect the time series to open correctly");
let trips: Vec<(&RecordId, &BikeTrip)> = ts.records().collect();
let trips: Vec<(&UniqueId, &BikeTrip)> = ts.records().collect();
assert_eq!(trips.len(), 3);
let trips: Vec<(&RecordId, &BikeTrip)> = ts
.search(exact_time(Timestamp::DateTime(
UTC.with_ymd_and_hms(2011, 11, 02, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap()),
)))
let trips: Vec<(&UniqueId, &BikeTrip)> = ts
.search(exact_time(
DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 02, 0, 0, 0).unwrap()).into(),
))
.collect();
assert_eq!(trips.len(), 1);
assert_eq!(
trips[0].1.datetime,
UTC.with_ymd_and_hms(2011, 11, 02, 0, 0, 0)
.unwrap()
.with_timezone(&FixedOffset::east_opt(0).unwrap())
DateTimeTz(UTC.with_ymd_and_hms(2011, 11, 02, 0, 0, 0).unwrap())
);
assert_eq!(trips[0].1.distance, Distance(50000.0 * M));
assert_eq!(trips[0].1.duration, Duration(7020.0 * S));
@ -421,14 +363,14 @@ mod test {
ts.put(trips[2].clone()).expect("expect a successful put");
ts.delete(&trip_id).expect("successful delete");
let recs: Vec<(&RecordId, &BikeTrip)> = ts.records().collect();
let recs: Vec<(&UniqueId, &BikeTrip)> = ts.records().collect();
assert_eq!(recs.len(), 2);
}
{
let ts: Series<BikeTrip> =
Series::open(&path).expect("expect the time series to open correctly");
let recs: Vec<(&RecordId, &BikeTrip)> = ts.records().collect();
let recs: Vec<(&UniqueId, &BikeTrip)> = ts.records().collect();
assert_eq!(recs.len(), 2);
}
})
@ -445,7 +387,7 @@ mod test {
impl Recordable for WeightRecord {
fn timestamp(&self) -> Timestamp {
Timestamp::Date(self.date)
self.date.into()
}
fn tags(&self) -> Vec<String> {