about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRicky Kresslein <rk@lakoliu.com>2023-06-01 11:53:33 +0200
committerRicky Kresslein <rk@lakoliu.com>2023-06-01 11:57:16 +0200
commit05ba763ff95f9ce0c91716d8da77a0bea8f1b6e3 (patch)
treea983e2396a26fe94d7de1cf956b8a1b8e6873722 /src
parent8d9ce19efb850aa44b367e0ad06432fa5150f057 (diff)
downloadFurtherance-05ba763ff95f9ce0c91716d8da77a0bea8f1b6e3.tar.zst
#105: Total seconds in CSV
Diffstat (limited to 'src')
-rw-r--r--src/database.rs22
1 files changed, 21 insertions, 1 deletions
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<Vec<Task>, 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<String> {
+    #[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()?;