Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add LAST_MODIFIED and CREATED getters and setters #116

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,30 @@ pub trait Component {
fn get_url(&self) -> Option<&str> {
self.property_value("URL")
}

/// Set the [`LAST_MODIFIED`](https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.7.3) [`Property`]
///
/// This must be a UTC date-time value.
fn last_modified(&mut self, dt: DateTime<Utc>) -> &mut Self {
self.add_property("LAST_MODIFIED", format_utc_date_time(dt))
}

/// Gets the [`LAST_MODIFIED`](https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.7.3) property.
fn get_last_modified(&self) -> Option<DateTime<Utc>> {
parse_utc_date_time(self.property_value("LAST_MODIFIED")?)
}

/// Set the [`CREATED`](https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.7.1) [`Property`]
///
/// This must be a UTC date-time value.
fn created(&mut self, dt: DateTime<Utc>) -> &mut Self {
self.add_property("CREATED", format_utc_date_time(dt))
}

/// Gets the [`CREATED`](https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.7.1) property.
fn get_created(&self) -> Option<DateTime<Utc>> {
parse_utc_date_time(self.property_value("CREATED")?)
}
}

/// Common trait of [`Event`] and [`Todo`]
Expand Down Expand Up @@ -451,6 +475,8 @@ mod tests {
assert_eq!(event.get_uid(), None);
assert_eq!(event.get_class(), None);
assert_eq!(event.get_timestamp(), None);
assert_eq!(event.get_last_modified(), None);
assert_eq!(event.get_created(), None);
assert_eq!(event.get_url(), None);
}

Expand Down Expand Up @@ -493,10 +519,14 @@ mod tests {
let utc_date_time = Utc.with_ymd_and_hms(2001, 3, 13, 14, 15, 16).unwrap();
let event = Event::new()
.timestamp(utc_date_time)
.last_modified(utc_date_time)
.created(utc_date_time)
.starts(utc_date_time)
.ends(utc_date_time)
.done();
assert_eq!(event.get_timestamp(), Some(utc_date_time));
assert_eq!(event.get_last_modified(), Some(utc_date_time));
assert_eq!(event.get_created(), Some(utc_date_time));
assert_eq!(event.get_start(), Some(utc_date_time.into()));
assert_eq!(event.get_end(), Some(utc_date_time.into()));
}
Expand Down