Просмотр исходного кода

tau: replaced Timestamp with NanoTimestamp

aggstam 3 лет назад
Родитель
Сommit
679e7b5f4a
4 измененных файлов с 33 добавлено и 30 удалено
  1. 4 4
      bin/tau/tau-cli/src/primitives.rs
  2. 4 4
      bin/tau/taud/src/jsonrpc.rs
  3. 14 11
      bin/tau/taud/src/month_tasks.rs
  4. 11 11
      bin/tau/taud/src/task_info.rs

+ 4 - 4
bin/tau/tau-cli/src/primitives.rs

@@ -18,7 +18,7 @@
 
 
 use std::{fmt, str::FromStr};
 use std::{fmt, str::FromStr};
 
 
-use darkfi::{util::time::Timestamp, Error, Result};
+use darkfi::{util::time::NanoTimestamp, Error, Result};
 
 
 use crate::due_as_timestamp;
 use crate::due_as_timestamp;
 
 
@@ -124,7 +124,7 @@ pub struct TaskEvent {
     pub action: String,
     pub action: String,
     pub author: String,
     pub author: String,
     pub content: String,
     pub content: String,
-    pub timestamp: Timestamp,
+    pub timestamp: NanoTimestamp,
 }
 }
 
 
 impl std::fmt::Display for TaskEvent {
 impl std::fmt::Display for TaskEvent {
@@ -139,7 +139,7 @@ impl Default for TaskEvent {
             action: State::Open.to_string(),
             action: State::Open.to_string(),
             author: "".to_string(),
             author: "".to_string(),
             content: "".to_string(),
             content: "".to_string(),
-            timestamp: Timestamp::current_time(),
+            timestamp: NanoTimestamp::current_time(),
         }
         }
     }
     }
 }
 }
@@ -148,7 +148,7 @@ impl Default for TaskEvent {
 pub struct Comment {
 pub struct Comment {
     content: String,
     content: String,
     author: String,
     author: String,
-    timestamp: Timestamp,
+    timestamp: NanoTimestamp,
 }
 }
 
 
 impl std::fmt::Display for Comment {
 impl std::fmt::Display for Comment {

+ 4 - 4
bin/tau/taud/src/jsonrpc.rs

@@ -31,7 +31,7 @@ use darkfi::{
         jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResult},
         jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResult},
         server::RequestHandler,
         server::RequestHandler,
     },
     },
-    util::{path::expand_path, time::Timestamp},
+    util::{path::expand_path, time::NanoTimestamp},
     Error,
     Error,
 };
 };
 
 
@@ -58,7 +58,7 @@ struct BaseTaskInfo {
     desc: String,
     desc: String,
     assign: Vec<String>,
     assign: Vec<String>,
     project: Vec<String>,
     project: Vec<String>,
-    due: Option<Timestamp>,
+    due: Option<NanoTimestamp>,
     rank: Option<f32>,
     rank: Option<f32>,
 }
 }
 
 
@@ -271,7 +271,7 @@ impl JsonRpcInterface {
         if params.len() != 1 {
         if params.len() != 1 {
             return Err(TaudError::InvalidData("len of params should be 1".into()))
             return Err(TaudError::InvalidData("len of params should be 1".into()))
         }
         }
-        let month = params[0].as_i64().map(Timestamp);
+        let month = params[0].as_i64().map(NanoTimestamp);
         let ws = self.workspace.lock().await.clone();
         let ws = self.workspace.lock().await.clone();
 
 
         let tasks = MonthTasks::load_stop_tasks(&self.dataset_path, ws, month.as_ref())?;
         let tasks = MonthTasks::load_stop_tasks(&self.dataset_path, ws, month.as_ref())?;
@@ -448,7 +448,7 @@ impl JsonRpcInterface {
 
 
         if fields.contains_key("due") {
         if fields.contains_key("due") {
             let due = fields.get("due").unwrap().clone();
             let due = fields.get("due").unwrap().clone();
-            let due: Option<Option<Timestamp>> = serde_json::from_value(due)?;
+            let due: Option<Option<NanoTimestamp>> = serde_json::from_value(due)?;
             if let Some(d) = due {
             if let Some(d) = due {
                 task.set_due(d);
                 task.set_due(d);
                 match d {
                 match d {

+ 14 - 11
bin/tau/taud/src/month_tasks.rs

@@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize};
 
 
 use darkfi::util::{
 use darkfi::util::{
     file::{load_json_file, save_json_file},
     file::{load_json_file, save_json_file},
-    time::Timestamp,
+    time::NanoTimestamp,
 };
 };
 
 
 use crate::{
 use crate::{
@@ -37,7 +37,7 @@ use crate::{
 
 
 #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
 #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
 pub struct MonthTasks {
 pub struct MonthTasks {
-    created_at: Timestamp,
+    created_at: NanoTimestamp,
     active_tks: Vec<String>,
     active_tks: Vec<String>,
     deactive_tks: Vec<String>,
     deactive_tks: Vec<String>,
 }
 }
@@ -45,7 +45,7 @@ pub struct MonthTasks {
 impl MonthTasks {
 impl MonthTasks {
     pub fn new(active_tks: &[String], deactive_tks: &[String]) -> Self {
     pub fn new(active_tks: &[String], deactive_tks: &[String]) -> Self {
         Self {
         Self {
-            created_at: Timestamp::current_time(),
+            created_at: NanoTimestamp::current_time(),
             active_tks: active_tks.to_owned(),
             active_tks: active_tks.to_owned(),
             deactive_tks: deactive_tks.to_owned(),
             deactive_tks: deactive_tks.to_owned(),
         }
         }
@@ -84,12 +84,12 @@ impl MonthTasks {
         }
         }
     }
     }
 
 
-    pub fn set_date(&mut self, date: &Timestamp) {
+    pub fn set_date(&mut self, date: &NanoTimestamp) {
         debug!(target: "tau", "MonthTasks::set_date()");
         debug!(target: "tau", "MonthTasks::set_date()");
         self.created_at = *date;
         self.created_at = *date;
     }
     }
 
 
-    fn get_path(date: &Timestamp, dataset_path: &Path) -> PathBuf {
+    fn get_path(date: &NanoTimestamp, dataset_path: &Path) -> PathBuf {
         debug!(target: "tau", "MonthTasks::get_path()");
         debug!(target: "tau", "MonthTasks::get_path()");
         dataset_path
         dataset_path
             .join("month")
             .join("month")
@@ -114,7 +114,7 @@ impl MonthTasks {
         Ok(entries)
         Ok(entries)
     }
     }
 
 
-    fn create(date: &Timestamp, dataset_path: &Path) -> TaudResult<Self> {
+    fn create(date: &NanoTimestamp, dataset_path: &Path) -> TaudResult<Self> {
         debug!(target: "tau", "MonthTasks::create()");
         debug!(target: "tau", "MonthTasks::create()");
 
 
         let mut mt = Self::new(&[], &[]);
         let mut mt = Self::new(&[], &[]);
@@ -123,7 +123,7 @@ impl MonthTasks {
         Ok(mt)
         Ok(mt)
     }
     }
 
 
-    pub fn load_or_create(date: Option<&Timestamp>, dataset_path: &Path) -> TaudResult<Self> {
+    pub fn load_or_create(date: Option<&NanoTimestamp>, dataset_path: &Path) -> TaudResult<Self> {
         debug!(target: "tau", "MonthTasks::load_or_create()");
         debug!(target: "tau", "MonthTasks::load_or_create()");
 
 
         // if a date is given we load that date's month tasks
         // if a date is given we load that date's month tasks
@@ -181,7 +181,7 @@ impl MonthTasks {
     pub fn load_stop_tasks(
     pub fn load_stop_tasks(
         dataset_path: &Path,
         dataset_path: &Path,
         ws: String,
         ws: String,
-        date: Option<&Timestamp>,
+        date: Option<&NanoTimestamp>,
     ) -> TaudResult<Vec<TaskInfo>> {
     ) -> TaudResult<Vec<TaskInfo>> {
         let mt = Self::load_or_create(date, dataset_path)?;
         let mt = Self::load_or_create(date, dataset_path)?;
         Ok(mt
         Ok(mt
@@ -255,7 +255,8 @@ mod tests {
 
 
         mt.save(&dataset_path)?;
         mt.save(&dataset_path)?;
 
 
-        let mt_load = MonthTasks::load_or_create(Some(&Timestamp::current_time()), &dataset_path)?;
+        let mt_load =
+            MonthTasks::load_or_create(Some(&NanoTimestamp::current_time()), &dataset_path)?;
 
 
         assert_eq!(mt, mt_load);
         assert_eq!(mt, mt_load);
 
 
@@ -263,7 +264,8 @@ mod tests {
 
 
         mt.save(&dataset_path)?;
         mt.save(&dataset_path)?;
 
 
-        let mt_load = MonthTasks::load_or_create(Some(&Timestamp::current_time()), &dataset_path)?;
+        let mt_load =
+            MonthTasks::load_or_create(Some(&NanoTimestamp::current_time()), &dataset_path)?;
 
 
         assert_eq!(mt, mt_load);
         assert_eq!(mt, mt_load);
 
 
@@ -282,7 +284,8 @@ mod tests {
 
 
         task.save(&dataset_path)?;
         task.save(&dataset_path)?;
 
 
-        let mt_load = MonthTasks::load_or_create(Some(&Timestamp::current_time()), &dataset_path)?;
+        let mt_load =
+            MonthTasks::load_or_create(Some(&NanoTimestamp::current_time()), &dataset_path)?;
 
 
         assert!(mt_load.active_tks.contains(&task.ref_id));
         assert!(mt_load.active_tks.contains(&task.ref_id));
 
 

+ 11 - 11
bin/tau/taud/src/task_info.rs

@@ -26,7 +26,7 @@ use darkfi::{
     event_graph::gen_id,
     event_graph::gen_id,
     util::{
     util::{
         file::{load_json_file, save_json_file},
         file::{load_json_file, save_json_file},
-        time::Timestamp,
+        time::NanoTimestamp,
     },
     },
 };
 };
 
 
@@ -41,12 +41,12 @@ pub struct TaskEvent {
     pub action: String,
     pub action: String,
     pub author: String,
     pub author: String,
     pub content: String,
     pub content: String,
-    pub timestamp: Timestamp,
+    pub timestamp: NanoTimestamp,
 }
 }
 
 
 impl TaskEvent {
 impl TaskEvent {
     pub fn new(action: String, author: String, content: String) -> Self {
     pub fn new(action: String, author: String, content: String) -> Self {
-        Self { action, author, content, timestamp: Timestamp::current_time() }
+        Self { action, author, content, timestamp: NanoTimestamp::current_time() }
     }
     }
 }
 }
 
 
@@ -54,7 +54,7 @@ impl TaskEvent {
 pub struct Comment {
 pub struct Comment {
     content: String,
     content: String,
     author: String,
     author: String,
-    timestamp: Timestamp,
+    timestamp: NanoTimestamp,
 }
 }
 
 
 impl Comment {
 impl Comment {
@@ -62,7 +62,7 @@ impl Comment {
         Self {
         Self {
             content: content.into(),
             content: content.into(),
             author: author.into(),
             author: author.into(),
-            timestamp: Timestamp::current_time(),
+            timestamp: NanoTimestamp::current_time(),
         }
         }
     }
     }
 }
 }
@@ -89,9 +89,9 @@ pub struct TaskInfo {
     pub(crate) owner: String,
     pub(crate) owner: String,
     assign: TaskAssigns,
     assign: TaskAssigns,
     project: TaskProjects,
     project: TaskProjects,
-    due: Option<Timestamp>,
+    due: Option<NanoTimestamp>,
     rank: Option<f32>,
     rank: Option<f32>,
-    created_at: Timestamp,
+    created_at: NanoTimestamp,
     state: String,
     state: String,
     pub(crate) events: TaskEvents,
     pub(crate) events: TaskEvents,
     comments: TaskComments,
     comments: TaskComments,
@@ -103,14 +103,14 @@ impl TaskInfo {
         title: &str,
         title: &str,
         desc: &str,
         desc: &str,
         owner: &str,
         owner: &str,
-        due: Option<Timestamp>,
+        due: Option<NanoTimestamp>,
         rank: Option<f32>,
         rank: Option<f32>,
         dataset_path: &Path,
         dataset_path: &Path,
     ) -> TaudResult<Self> {
     ) -> TaudResult<Self> {
         // generate ref_id
         // generate ref_id
         let ref_id = gen_id(30);
         let ref_id = gen_id(30);
 
 
-        let created_at = Timestamp::current_time();
+        let created_at = NanoTimestamp::current_time();
 
 
         let task_ids: Vec<u32> =
         let task_ids: Vec<u32> =
             MonthTasks::load_current_tasks(dataset_path, workspace.clone(), false)?
             MonthTasks::load_current_tasks(dataset_path, workspace.clone(), false)?
@@ -121,7 +121,7 @@ impl TaskInfo {
         let id: u32 = find_free_id(&task_ids);
         let id: u32 = find_free_id(&task_ids);
 
 
         if let Some(d) = &due {
         if let Some(d) = &due {
-            if *d < Timestamp::current_time() {
+            if *d < NanoTimestamp::current_time() {
                 return Err(TaudError::InvalidDueTime)
                 return Err(TaudError::InvalidDueTime)
             }
             }
         }
         }
@@ -237,7 +237,7 @@ impl TaskInfo {
         self.rank = r;
         self.rank = r;
     }
     }
 
 
-    pub fn set_due(&mut self, d: Option<Timestamp>) {
+    pub fn set_due(&mut self, d: Option<NanoTimestamp>) {
         debug!(target: "tau", "TaskInfo::set_due()");
         debug!(target: "tau", "TaskInfo::set_due()");
         self.due = d;
         self.due = d;
     }
     }