Track space timestamps
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use crate::{ProfileId, SpaceId};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
@@ -14,6 +16,8 @@ pub struct Space {
|
||||
accent_hex: u32,
|
||||
default_profile_id: ProfileId,
|
||||
archive_policy: ArchivePolicy,
|
||||
created_at: SystemTime,
|
||||
updated_at: SystemTime,
|
||||
}
|
||||
|
||||
impl Space {
|
||||
@@ -24,6 +28,7 @@ impl Space {
|
||||
accent_hex: u32,
|
||||
default_profile_id: ProfileId,
|
||||
) -> Self {
|
||||
let created_at = SystemTime::now();
|
||||
Self {
|
||||
id: SpaceId::new(),
|
||||
name: name.into(),
|
||||
@@ -31,6 +36,8 @@ impl Space {
|
||||
accent_hex,
|
||||
default_profile_id,
|
||||
archive_policy: ArchivePolicy::Manual,
|
||||
created_at,
|
||||
updated_at: created_at,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +68,7 @@ impl Space {
|
||||
|
||||
pub fn set_default_profile_id(&mut self, profile_id: ProfileId) {
|
||||
self.default_profile_id = profile_id;
|
||||
self.record_update();
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -70,5 +78,22 @@ impl Space {
|
||||
|
||||
pub fn set_archive_policy(&mut self, archive_policy: ArchivePolicy) {
|
||||
self.archive_policy = archive_policy;
|
||||
self.record_update();
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn created_at(&self) -> SystemTime {
|
||||
self.created_at
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn updated_at(&self) -> SystemTime {
|
||||
self.updated_at
|
||||
}
|
||||
|
||||
fn record_update(&mut self) {
|
||||
let now = SystemTime::now();
|
||||
self.updated_at =
|
||||
if now > self.updated_at { now } else { self.updated_at + Duration::from_nanos(1) };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user