From 05ba763ff95f9ce0c91716d8da77a0bea8f1b6e3 Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Thu, 1 Jun 2023 11:53:33 +0200 Subject: #105: Total seconds in CSV --- ...0e39f3b6bcbf1aa42fc3bbbcfb950a0bf4539430.commit | Bin 0 -> 324 bytes ...62f77125e655473aa9b41d7e6f0db18896a6a87c.commit | Bin 324 -> 0 bytes .../x86_64-com.lakoliu.Furtherance.Devel.json/init | 2 +- src/database.rs | 22 ++++++++++++++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .flatpak-builder/cache/objects/7b/4e4c09b0bc406e51d17e190e39f3b6bcbf1aa42fc3bbbcfb950a0bf4539430.commit delete mode 100644 .flatpak-builder/cache/objects/f0/cc690b56fe98a4764ec43262f77125e655473aa9b41d7e6f0db18896a6a87c.commit diff --git a/.flatpak-builder/cache/objects/7b/4e4c09b0bc406e51d17e190e39f3b6bcbf1aa42fc3bbbcfb950a0bf4539430.commit b/.flatpak-builder/cache/objects/7b/4e4c09b0bc406e51d17e190e39f3b6bcbf1aa42fc3bbbcfb950a0bf4539430.commit new file mode 100644 index 0000000..0085763 Binary files /dev/null and b/.flatpak-builder/cache/objects/7b/4e4c09b0bc406e51d17e190e39f3b6bcbf1aa42fc3bbbcfb950a0bf4539430.commit differ diff --git a/.flatpak-builder/cache/objects/f0/cc690b56fe98a4764ec43262f77125e655473aa9b41d7e6f0db18896a6a87c.commit b/.flatpak-builder/cache/objects/f0/cc690b56fe98a4764ec43262f77125e655473aa9b41d7e6f0db18896a6a87c.commit deleted file mode 100644 index 6c33e47..0000000 Binary files a/.flatpak-builder/cache/objects/f0/cc690b56fe98a4764ec43262f77125e655473aa9b41d7e6f0db18896a6a87c.commit and /dev/null differ diff --git a/.flatpak-builder/cache/refs/heads/x86_64-com.lakoliu.Furtherance.Devel.json/init b/.flatpak-builder/cache/refs/heads/x86_64-com.lakoliu.Furtherance.Devel.json/init index 9f93685..d07bc28 100644 --- a/.flatpak-builder/cache/refs/heads/x86_64-com.lakoliu.Furtherance.Devel.json/init +++ b/.flatpak-builder/cache/refs/heads/x86_64-com.lakoliu.Furtherance.Devel.json/init @@ -1 +1 @@ -f0cc690b56fe98a4764ec43262f77125e655473aa9b41d7e6f0db18896a6a87c +7b4e4c09b0bc406e51d17e190e39f3b6bcbf1aa42fc3bbbcfb950a0bf4539430 diff --git a/src/database.rs b/src/database.rs index 589ff2d..7050cbb 100644 --- a/src/database.rs +++ b/src/database.rs @@ -241,13 +241,33 @@ pub fn retrieve(sort: TaskSort, order: SortOrder) -> Result, rusqlite: /// Exports the database as CSV. /// The delimiter parameter is interpreted as a ASCII character. pub fn export_as_csv(sort: TaskSort, order: SortOrder, delimiter: u8) -> anyhow::Result { + #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] + struct CSVTask { + pub id: i32, + pub task_name: String, + pub start_time: String, + pub stop_time: String, + pub tags: String, + pub seconds: i64, + } + let mut csv_writer = csv::WriterBuilder::new() .delimiter(delimiter) .from_writer(vec![]); let tasks = retrieve(sort, order)?; for task in tasks { - csv_writer.serialize(task)?; + let start_time = DateTime::parse_from_rfc3339(&task.start_time).unwrap(); + let stop_time = DateTime::parse_from_rfc3339(&task.stop_time).unwrap(); + let duration = stop_time - start_time; + csv_writer.serialize(CSVTask{ + id: task.id, + task_name: task.task_name, + start_time: task.start_time, + stop_time: task.stop_time, + tags: task.tags, + seconds: duration.num_seconds(), + })?; } csv_writer.flush()?; -- cgit 1.4.1