Implement the timestamp function
This commit is contained in:
parent
0e0d67a9ac
commit
83a4839b1d
|
@ -976,8 +976,6 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6"
|
|||
name = "fitnesstrax"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"chrono-tz",
|
||||
"gio",
|
||||
"glib",
|
||||
"glib-build-tools 0.18.0",
|
||||
|
@ -1134,6 +1132,8 @@ dependencies = [
|
|||
name = "ft-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"chrono-tz",
|
||||
"dimensioned 0.8.0",
|
||||
"emseries",
|
||||
"serde 1.0.188",
|
||||
|
|
|
@ -7,8 +7,6 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] }
|
||||
chrono = { version = "0.4" }
|
||||
chrono-tz = { version = "0.8" }
|
||||
gio = { version = "0.18" }
|
||||
glib = { version = "0.18" }
|
||||
gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] }
|
||||
|
|
|
@ -6,6 +6,8 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = { version = "0.4" }
|
||||
chrono-tz = { version = "0.8" }
|
||||
dimensioned = { version = "0.8", features = [ "serde" ] }
|
||||
emseries = { path = "../../emseries" }
|
||||
serde = { version = "1", features = [ "derive" ] }
|
||||
|
|
|
@ -69,7 +69,18 @@ pub enum TraxRecord {
|
|||
|
||||
impl Recordable for TraxRecord {
|
||||
fn timestamp(&self) -> Timestamp {
|
||||
unimplemented!()
|
||||
match self {
|
||||
TraxRecord::BikeRide(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Pushups => unimplemented!(),
|
||||
TraxRecord::Row(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Run(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Situps => unimplemented!(),
|
||||
TraxRecord::Squats => unimplemented!(),
|
||||
TraxRecord::Steps(rec) => Timestamp::Date(rec.date),
|
||||
TraxRecord::Swim(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Walk(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Weight(rec) => Timestamp::Date(rec.date),
|
||||
}
|
||||
}
|
||||
|
||||
fn tags(&self) -> Vec<String> {
|
||||
|
@ -86,6 +97,16 @@ mod test {
|
|||
fn can_record_records() {
|
||||
let file = tempfile::NamedTempFile::new().expect("a temporary file");
|
||||
let path = file.into_temp_path();
|
||||
let series: Series<TraxRecord> = Series::open(&path).unwrap();
|
||||
let mut series: Series<TraxRecord> = Series::open(&path).unwrap();
|
||||
|
||||
let record = TraxRecord::Steps(Steps {
|
||||
date: NaiveDate::from_ymd_opt(2023, 1, 1).unwrap(),
|
||||
count: 1000,
|
||||
});
|
||||
|
||||
let id = series.put(record.clone()).unwrap();
|
||||
|
||||
let record_ = series.get(&id).unwrap();
|
||||
assert_eq!(record_, record);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue