1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
use chrono::*;
use super::*;
/// VTODO [(RFC 5545, Section 3.6.2 )](https://tools.ietf.org/html/rfc5545#section-3.6.2)
#[derive(Debug, Default, PartialEq, Eq)]
pub struct Todo {
pub(super) inner: InnerComponent,
}
impl Todo {
/// Creates a new Todo.
pub fn new() -> Self {
Default::default()
}
/// End of builder pattern.
/// copies over everything
pub fn done(&mut self) -> Self {
Todo {
inner: self.inner.done(),
}
}
/// Set the [`PERCENT-COMPLETE`](https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.1.8) property
///
/// Ranges between 0 - 100
pub fn percent_complete(&mut self, percent: u8) -> &mut Self {
self.add_property("PERCENT-COMPLETE", &percent.to_string());
self
}
/// 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());
self
}
/// Set the [`COMPLETED`](https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.2.1) property
///
/// Per [RFC 5545, Section 3.8.2.1](https://tools.ietf.org/html/rfc5545#section-3.8.2.1), this
/// must be a date-time in UTC format.
pub fn completed(&mut self, dt: DateTime<Utc>) -> &mut Self {
self.add_property("COMPLETED", &CalendarDateTime::Utc(dt).to_string());
self
}
/// Defines the overall status or confirmation
///
pub fn status(&mut self, status: TodoStatus) -> &mut Self {
self.append_property(status.into());
self
}
//pub fn repeats<R:Repeater+?Sized>(&mut self, repeat: R) -> &mut Self {
// unimplemented!()
//}
}