Skip to content

Commit

Permalink
feat!: Allow due date (without time) to be specified for TODO.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Apr 10, 2022
1 parent 9619316 commit 2a4a451
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/components/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ impl DatePerhapsTime {
Some(CalendarDateTime::from_str(property.value())?.into())
}
}

pub(crate) fn to_property(&self, key: &str) -> Property {
match self {
Self::DateTime(date_time) => Property::new(key, &date_time.to_string()),
Self::Date(date) => Property::new(key, &date.format(NAIVE_DATE_FORMAT).to_string())
.append_parameter(ValueType::Date)
.done(),
}
}
}

impl From<CalendarDateTime> for DatePerhapsTime {
Expand Down
13 changes: 10 additions & 3 deletions src/components/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ impl Todo {
/// Set the [`DUE`](https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.2.3) property
///
/// See [`CalendarDateTime`] for info how are different [`chrono`] types converted automatically.
pub fn due<T: Into<CalendarDateTime>>(&mut self, dt: T) -> &mut Self {
let calendar_dt: CalendarDateTime = dt.into();
self.add_property("DUE", &calendar_dt.to_string());
pub fn due<T: Into<DatePerhapsTime>>(&mut self, dt: T) -> &mut Self {
let calendar_dt: DatePerhapsTime = dt.into();
self.append_property(calendar_dt.to_property("DUE"));
self
}

Expand Down Expand Up @@ -129,4 +129,11 @@ mod tests {
assert_eq!(todo.get_due(), Some(utc_date_time.into()));
assert_eq!(todo.get_completed(), Some(utc_date_time));
}

#[test]
fn get_dates_naive() {
let naive_date = NaiveDate::from_ymd(2001, 3, 13);
let todo = Todo::new().due(naive_date).done();
assert_eq!(todo.get_due(), Some(naive_date.into()));
}
}

0 comments on commit 2a4a451

Please sign in to comment.