Skip to main content

keepass/db/types/
times.rs

1use chrono::NaiveDateTime;
2
3/// Last modification timestamp for a KeePass entry.
4#[derive(Debug, Default, PartialEq, Eq, Clone)]
5#[non_exhaustive]
6pub struct Times {
7	/// Time of the last modification, in UTC.
8	pub last_modification: Option<NaiveDateTime>,
9}
10
11impl Times {
12	/// Returns the current UTC time with second precision.
13	pub fn now() -> NaiveDateTime {
14		let timestamp = chrono::Utc::now().timestamp();
15		chrono::DateTime::from_timestamp(timestamp, 0).map_or(chrono::DateTime::UNIX_EPOCH.naive_utc(), |dt| dt.naive_utc())
16	}
17
18	/// Creates a new Times instance with the last modification time set to now.
19	pub fn new() -> Self {
20		Self { last_modification: Some(Self::now()) }
21	}
22}