diff options
| -rw-r--r-- | crates/vcs_actions/src/actions/local_actions.rs | 5 | ||||
| -rw-r--r-- | crates/vcs_data/src/data/local/latest_info.rs | 47 |
2 files changed, 5 insertions, 47 deletions
diff --git a/crates/vcs_actions/src/actions/local_actions.rs b/crates/vcs_actions/src/actions/local_actions.rs index c8787f5..7eee64d 100644 --- a/crates/vcs_actions/src/actions/local_actions.rs +++ b/crates/vcs_actions/src/actions/local_actions.rs @@ -1,11 +1,10 @@ -use std::{collections::HashMap, io::ErrorKind, net::SocketAddr, path::PathBuf}; +use std::{collections::HashMap, io::ErrorKind, net::SocketAddr, path::PathBuf, time::SystemTime}; use action_system::{action::ActionContext, macros::action_gen}; use cfg_file::config::ConfigFile; use log::info; use serde::{Deserialize, Serialize}; use tcp_connection::error::TcpTargetError; -use tokio::time::Instant; use vcs_data::{ constants::{CLIENT_PATH_CACHED_SHEET, CLIENT_PATH_LOCAL_SHEET}, data::{ @@ -195,7 +194,7 @@ pub async fn update_to_latest_info_action( .await .read_large_msgpack::<LatestInfo>(512_u16) .await?; - latest_info.update_instant = Some(Instant::now()); + latest_info.update_instant = Some(SystemTime::now()); LatestInfo::write_to( &latest_info, LatestInfo::latest_info_path(workspace.local_path(), &member_id), diff --git a/crates/vcs_data/src/data/local/latest_info.rs b/crates/vcs_data/src/data/local/latest_info.rs index 99f423b..ce45372 100644 --- a/crates/vcs_data/src/data/local/latest_info.rs +++ b/crates/vcs_data/src/data/local/latest_info.rs @@ -1,11 +1,10 @@ use std::{ path::{Path, PathBuf}, - time::{SystemTime, UNIX_EPOCH}, + time::SystemTime, }; use cfg_file::ConfigFile; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use tokio::time::Instant; +use serde::{Deserialize, Serialize}; use crate::{ constants::{CLIENT_FILE_LATEST_INFO, CLIENT_FILE_LATEST_INFO_NOSET}, @@ -32,11 +31,7 @@ pub struct LatestInfo { pub ref_sheet_content: SheetData, /// Update instant - #[serde( - serialize_with = "serialize_instant", - deserialize_with = "deserialize_instant" - )] - pub update_instant: Option<Instant>, + pub update_instant: Option<SystemTime>, // Members /// All member information of the vault, allowing me to contact them more conveniently @@ -55,39 +50,3 @@ pub struct SheetInfo { pub sheet_name: SheetName, pub holder_name: Option<MemberId>, } - -fn serialize_instant<S>(instant: &Option<Instant>, serializer: S) -> Result<S::Ok, S::Error> -where - S: Serializer, -{ - let system_now = SystemTime::now(); - let instant_now = Instant::now(); - let duration_since_epoch = instant - .as_ref() - .and_then(|i| i.checked_duration_since(instant_now)) - .map(|d| system_now.checked_add(d)) - .unwrap_or(Some(system_now)) - .and_then(|t| t.duration_since(UNIX_EPOCH).ok()) - .unwrap_or_else(|| SystemTime::now().duration_since(UNIX_EPOCH).unwrap()); - - serializer.serialize_u64(duration_since_epoch.as_millis() as u64) -} - -fn deserialize_instant<'de, D>(deserializer: D) -> Result<Option<Instant>, D::Error> -where - D: Deserializer<'de>, -{ - let millis = u64::deserialize(deserializer)?; - let duration_since_epoch = std::time::Duration::from_millis(millis); - let system_time = UNIX_EPOCH + duration_since_epoch; - let now_system = SystemTime::now(); - let now_instant = Instant::now(); - - if let Ok(elapsed) = system_time.elapsed() { - Ok(Some(now_instant - elapsed)) - } else if let Ok(duration_until) = system_time.duration_since(now_system) { - Ok(Some(now_instant + duration_until)) - } else { - Ok(Some(now_instant)) - } -} |
