Skip to main content

keepass/db/types/
times.rs

1use jiff::civil::DateTime;
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<DateTime>,
9}
10
11impl Times {
12	/// Returns the current UTC time with second precision.
13	pub fn now() -> DateTime {
14		let now = jiff::Timestamp::now().to_zoned(jiff::tz::TimeZone::UTC).datetime();
15		now.date().at(now.hour(), now.minute(), now.second(), 0)
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}