docs: some doc comments
This commit is contained in:
parent
2467cb3db3
commit
0101612029
9 changed files with 182 additions and 120 deletions
|
|
@ -1,18 +1,23 @@
|
|||
use crate::objects::timestamp::{Datetime, Delay, Repeater, Timestamp};
|
||||
use memchr::memchr;
|
||||
|
||||
/// clock elements
|
||||
///
|
||||
/// there are two types of clock: *closed* clock and *running* clock.
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[derive(Debug)]
|
||||
pub enum Clock<'a> {
|
||||
/// closed Clock
|
||||
Closed {
|
||||
start: Datetime,
|
||||
end: Datetime,
|
||||
start: Datetime<'a>,
|
||||
end: Datetime<'a>,
|
||||
repeater: Option<Repeater>,
|
||||
delay: Option<Delay>,
|
||||
duration: &'a str,
|
||||
},
|
||||
/// running Clock
|
||||
Running {
|
||||
start: Datetime,
|
||||
start: Datetime<'a>,
|
||||
repeater: Option<Repeater>,
|
||||
delay: Option<Delay>,
|
||||
},
|
||||
|
|
@ -88,6 +93,7 @@ impl<'a> Clock<'a> {
|
|||
None
|
||||
}
|
||||
|
||||
/// returns `true` if the clock is running
|
||||
pub fn is_running(&self) -> bool {
|
||||
match self {
|
||||
Clock::Closed { .. } => false,
|
||||
|
|
@ -95,6 +101,7 @@ impl<'a> Clock<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// returns `true` if the clock is closed
|
||||
pub fn is_closed(&self) -> bool {
|
||||
match self {
|
||||
Clock::Closed { .. } => true,
|
||||
|
|
@ -102,6 +109,7 @@ impl<'a> Clock<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// returns `Some` if the clock is closed, `None` if running
|
||||
pub fn duration(&self) -> Option<&'a str> {
|
||||
match self {
|
||||
Clock::Closed { duration, .. } => Some(duration),
|
||||
|
|
@ -109,6 +117,7 @@ impl<'a> Clock<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// constructs a new timestamp object from the clock
|
||||
pub fn value(&self) -> Timestamp<'_> {
|
||||
match *self {
|
||||
Clock::Closed {
|
||||
|
|
@ -150,7 +159,8 @@ mod tests {
|
|||
Clock::Running {
|
||||
start: Datetime {
|
||||
date: (2003, 9, 16),
|
||||
time: Some((9, 39))
|
||||
time: Some((9, 39)),
|
||||
dayname: "Tue"
|
||||
},
|
||||
repeater: None,
|
||||
delay: None,
|
||||
|
|
@ -164,11 +174,13 @@ mod tests {
|
|||
Clock::Closed {
|
||||
start: Datetime {
|
||||
date: (2003, 9, 16),
|
||||
time: Some((9, 39))
|
||||
time: Some((9, 39)),
|
||||
dayname: "Tue"
|
||||
},
|
||||
end: Datetime {
|
||||
date: (2003, 9, 16),
|
||||
time: Some((10, 39))
|
||||
time: Some((10, 39)),
|
||||
dayname: "Tue"
|
||||
},
|
||||
repeater: None,
|
||||
delay: None,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
/// elements
|
||||
///
|
||||
/// elements means some syntactical parts that have the same level with paragraph.
|
||||
pub(crate) mod block;
|
||||
pub(crate) mod clock;
|
||||
pub(crate) mod drawer;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
use crate::objects::timestamp::Timestamp;
|
||||
use memchr::memchr;
|
||||
|
||||
/// palnning elements
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[derive(Debug)]
|
||||
pub struct Planning<'a> {
|
||||
/// the date when the task should be done
|
||||
pub deadline: Option<Timestamp<'a>>,
|
||||
/// the date when you should start working on the task
|
||||
pub scheduled: Option<Timestamp<'a>>,
|
||||
/// the date when the task is closed
|
||||
pub closed: Option<Timestamp<'a>>,
|
||||
}
|
||||
|
||||
|
|
@ -22,18 +26,9 @@ impl<'a> Planning<'a> {
|
|||
macro_rules! set_timestamp {
|
||||
($timestamp:expr) => {
|
||||
if $timestamp.is_none() {
|
||||
if next.starts_with('<') {
|
||||
let (timestamp, off) = Timestamp::parse_active(next)
|
||||
.or_else(|| Timestamp::parse_diary(next))?;
|
||||
$timestamp = Some(timestamp);
|
||||
tail = &next[off..].trim_start();
|
||||
} else if next.starts_with('<') {
|
||||
let (timestamp, off) = Timestamp::parse_active(next)?;
|
||||
$timestamp = Some(timestamp);
|
||||
tail = &next[off..].trim_start();
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
let (timestamp, off) = Timestamp::parse(next)?;
|
||||
$timestamp = Some(timestamp);
|
||||
tail = &next[off..].trim_start();
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -77,7 +72,8 @@ mod tests {
|
|||
scheduled: Some(Timestamp::Active {
|
||||
start: Datetime {
|
||||
date: (2019, 4, 8),
|
||||
time: None
|
||||
time: None,
|
||||
dayname: "Mon"
|
||||
},
|
||||
repeater: None,
|
||||
delay: None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue