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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
//! Module representing an entry in the timelog.
//!
//! # Examples
//!
//! ```rust
//! use timelog::entry::Entry;
//! use std::fs::File;
//! use std::io::{BufRead, BufReader};
//!
//! fn day_entrys(date: &str, file: &mut File) -> Vec<Entry> {
//!     let mut reader = BufReader::new(file);
//!     reader.lines()
//!           .filter_map(|line| Entry::from_line(&line.ok()?).ok())
//!           .filter(|ev| ev.stamp() == String::from(date))
//!           .collect::<Vec<Entry>>()
//! }
//! ```
//!
//! # Description
//!
//! Objects of this type represent the individual lines in the `timelog.txt` file.
//! Each [`Entry`] has a date and time stamp, an optional project, and a task.

use std::cmp::{Ordering, PartialOrd};

use lazy_static::lazy_static;
use regex::Regex;
use std::fmt::{self, Debug, Display};

const STOP_CMD: &str = "stop";

lazy_static! {
    // These should not be able to fail, hardcoded input strings.
    // Still using expect() in case the regex strings ever get changed.

    /// Regular expression to match a time stamp
    static ref TIMESTAMP_RE: Regex = Regex::new(r"\A(\d{4}[-/](?:0[1-9]|1[0-2])[-/](?:0[1-9]|[12][0-9]|3[01]) (?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-6][0-9])").expect("Date time Regex failed.");
    /// A somewhat lax regular expression to match an entry line.
    static ref LAX_LINE_RE: Regex = Regex::new(r"\A(\d{4}[-/](?:0[1-9]|1[0-2])[-/](?:0[1-9]|[12][0-9]|3[01]) (?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-6][0-9])(.)(.+)").expect("Entry line Regex failed.");
    /// A regular expression matching the project part of an entry line.
    pub static ref PROJECT_RE: Regex = Regex::new(r"\+(\S+)").expect("Entry project regex failed.");
    /// A regular expression matching the task part of an entry line.
    static ref TASKNAME_RE: Regex = Regex::new(r"@(\S+)").expect("Task name Regex failed.");
    /// A regular expression matching a stop line
    static ref STOP_LINE: Regex = Regex::new(r"\A(\d{4}[-/](?:0[1-9]|1[0-2])[-/](?:0[1-9]|[12][0-9]|3[01]) (?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-6][0-9]) stop").expect("Stop line Regex failed");
    /// Regular expression matching the year portion of an entry line.
    pub static ref YEAR_RE: Regex = Regex::new(r"^(\d\d\d\d)").expect("Date regex failed");
    /// Regular expression extracting the marker from the line.
    pub static ref MARKER_RE: Regex = Regex::new(r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d(.)").expect("Marker regex failed");
}

#[doc(inline)]
use crate::date::{Date, DateTime};

pub mod kind;
pub mod error;

/// The kind of entry
pub type EntryKind = kind::EntryKind;
/// Errors associated with the entry.
pub type EntryError = error::EntryError;

/// Representation of an entry in the log
///
/// Objects of this type represent individual lines in the `timelog.txt` file.
/// Each [`Entry`] has a date and time stamp, an optional project, and a task.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Entry {
    /// Time that this entry began
    time: DateTime,
    /// An optional project name
    project: Option<String>,
    /// The text of the entry from the entry line
    text: String,
    /// The type of the entry
    kind: EntryKind,
}

/// # Line parsing tools
impl Entry {
    /// Parse the entry line text into the task name and detail parts if they exist.
    pub fn task_breakdown(entry_text: &str) -> (Option<String>, Option<String>) {
        if entry_text.is_empty() {
            return (None, None);
        }

        let task = PROJECT_RE.replace(entry_text, "").trim().to_string();
        if let Some(caps) = TASKNAME_RE.captures(&task) {
            if let Some(tname) = caps.get(1) {
                let detail = TASKNAME_RE.replace(&task, "").trim().to_string();
                let tname = tname.as_str().to_string();
                return (Some(tname), (!detail.is_empty()).then(|| detail));
            }
        }
        (None, (!task.is_empty()).then(|| task))
    }

    /// Return `true` if the supplied string looks like a stop line.
    pub fn is_stop_line(line: &str) -> bool { STOP_LINE.is_match(line) }

    /// Extract a date/time string from a task line
    pub fn datetime_from_line(line: &str) -> Option<&str> {
        if line.is_empty() || Self::is_comment_line(line) {
            return None;
        }

        if let Some(caps) = LAX_LINE_RE.captures(line) {
            return caps.get(1).map(|s| s.as_str());
        }
        None
    }

    /// Extract a date string from a task line
    pub fn date_from_line(line: &str) -> Option<&str> {
        Self::datetime_from_line(line).and_then(|s| s.split_whitespace().next())
    }


    /// Return the year for the supplied entry line, if any.
    pub fn extract_year(line: &str) -> Option<u32> {
        if Self::is_comment_line(line) {
            return None;
        }

        YEAR_RE
            .captures(line)
            .map(|cap| cap[0].parse::<u32>().unwrap())
    }

    /// Return `true` if the supplied line is a comment.
    pub fn is_comment_line(line: &str) -> bool {
        line.starts_with('#')
    }
}

/// # Constructors
impl Entry {
    /// Create a new [`Entry`] representing the supplied task at the supplied time.
    pub fn new(entry_text: &str, time: DateTime) -> Self {
        Self::new_marked(entry_text, time, EntryKind::Start)
    }

    /// Create a new [`Entry`] representing the supplied task at the supplied time and optional
    /// mark.
    pub fn new_marked(entry_text: &str, time: DateTime, kind: EntryKind) -> Self {
        let kind = if kind == EntryKind::Start && entry_text == STOP_CMD {
            EntryKind::Stop
        }
        else {
            kind
        };
        let oproject = PROJECT_RE.captures(entry_text)
            .and_then(|caps| caps.get(1).map(|m| String::from(m.as_str())));
        Self { time, project: oproject, text: String::from(entry_text), kind }
    }

    /// Create a new [`Entry`] representing a stop entry for the supplied [`DateTime`]
    pub fn new_stop(time: DateTime) -> Self {
        Self::new_marked(STOP_CMD, time, EntryKind::Stop)
    }

    /// Create a new [`Entry`] representing the entry from the supplied line.
    ///
    /// This entry must be formatted as described in Format.md.
    ///
    /// ## Errors
    ///
    /// Return an [`EntryError`] if the line is empty or formatted incorrectly.
    pub fn from_line(line: &str) -> std::result::Result<Self, EntryError> {
        if line.is_empty() {
            return Err(EntryError::BlankLine);
        }

        match LAX_LINE_RE.captures(line) {
            Some(caps) => {
                let stamp = caps.get(1).ok_or(EntryError::InvalidTimeStamp)?.as_str();
                let time = DateTime::try_from(stamp).map_err(|_| EntryError::InvalidTimeStamp)?;
                let kind = EntryKind::try_new(
                    caps.get(2)
                        .and_then(|m| m.as_str().chars().next())
                )?;
                Ok(Entry::new_marked(
                    caps.get(3).map(|m| m.as_str()).unwrap_or(""),
                    time,
                    kind
                ))
            },
            None => Err(TIMESTAMP_RE.is_match(line)
                            .then(|| EntryError::MissingTask)
                            .unwrap_or(EntryError::InvalidTimeStamp)),
        }
    }
}

/// # Accessors
impl Entry {
    /// Return the [`String`] designated as the project, if any, from the [`Entry`].
    pub fn project(&self) -> Option<String> { self.project.as_ref().map(|p| p.to_owned()) }

    /// Return the [`String`] containing all of the [`Entry`] except the time and date.
    pub fn entry_text(&self) -> String { self.text.to_owned() }

    /// Return the [`String`] containing all of the [`Entry`] except the time and date.
    pub fn task(&self) -> Option<String> { Self::task_breakdown(&self.text).0 }

    /// Return the [`String`] containing all of the [`Entry`] except the time and date.
    pub fn detail(&self) -> Option<String> { Self::task_breakdown(&self.text).1 }

    /// Return the [`String`] containing all of the [`Entry`] except the time and date.
    pub fn task_and_detail(&self) -> (Option<String>, Option<String>) {
        Self::task_breakdown(&self.text)
    }

    /// Return the time for the start of the [`Entry`] in epoch seconds.
    pub fn epoch(&self) -> i64 { self.time.timestamp() }

    /// Return the date for the start of the [`Entry`] as a [`Date`]
    pub fn date(&self) -> Date { self.time.date() }

    /// Return the time for the start of the [`Entry`] as a [`DateTime`]
    pub fn date_time(&self) -> DateTime { self.time }

    /// Return the date stamp of the [`Entry`] in 'YYYY-MM-DD' format.
    pub fn stamp(&self) -> String { self.date().to_string() }

    /// Return `true` if this a start [`Entry`].
    pub fn is_start(&self) -> bool { self.kind == EntryKind::Start }

    /// Return `true` if this was a stop [`Entry`].
    pub fn is_stop(&self) -> bool { self.kind == EntryKind::Stop }

    /// Return `true` if this was an ignored [`Entry`].
    pub fn is_ignore(&self) -> bool { self.kind == EntryKind::Ignored }

    /// Return an ignored [`Entry`] converted from this one.
    pub fn ignore(self) -> Self {
        Self { kind: EntryKind::Ignored, ..self }
    }

    /// Return `true` if this was a event [`Entry`].
    pub fn is_event(&self) -> bool { self.kind == EntryKind::Event }
}

impl Display for Entry {
    /// Format the [`Entry`] formatted as described in Format.md.
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mark = match self.kind {
            EntryKind::Ignored => '!',
            EntryKind::Event => '^',
            _ => ' ',
        };
        write!(f, "{}{}{}", self.time, mark, self.text)
    }
}

impl PartialOrd for Entry {
    /// This method returns an ordering between self and other values if one exists.
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.time.cmp(&other.time)
            .then_with(|| self.text.cmp(&other.text)))
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use spectral::prelude::*;

    const CANONICAL_LINE: &str = "2013-06-05 10:00:02 +proj1 @do something";
    const IGNORED_LINE: &str = "2013-06-05 10:00:02!+proj1 @do something";
    const EVENT_LINE: &str = "2013-06-05 10:00:02^+proj1 @do something";
    const STOP_LINE: &str = "2013-06-05 10:00:02 stop";

    fn reference_time() -> i64 {
        DateTime::new((2013, 6, 5), (10, 0, 2)).unwrap().timestamp()
    }

    #[test]
    fn from_line_error_if_empty() {
        assert_that!(Entry::from_line("")).is_err_containing(EntryError::BlankLine);
    }

    #[test]
    fn is_comment_on_comment() {
        assert_that!(Entry::is_comment_line("# Random comment")).is_true();
        assert_that!(Entry::is_comment_line("#2013-06-05 10:00:02 +test @Commented")).is_true();
    }

    #[test]
    fn is_comment_on_empty() {
        assert_that!(Entry::is_comment_line("")).is_false();
    }

    #[test]
    fn is_comment_on_entry() {
        assert_that!(Entry::is_comment_line("2013-06-05 10:00:02 +test @Commented")).is_false();
    }

    #[test]
    fn test_datetime_from_empty_line() {
        assert_that!(Entry::datetime_from_line("")).is_none()
    }

    #[test]
    fn test_datetime_from_commented_line() {
        assert_that!(Entry::datetime_from_line("# Random comment")).is_none();
        assert_that!(Entry::datetime_from_line("#2013-06-05 10:00:02 +test @Commented")).is_none()
    }

    #[test]
    fn test_datetime_from_line() {
        assert_that!(Entry::datetime_from_line(CANONICAL_LINE)).contains("2013-06-05 10:00:02");
    }

    #[test]
    fn test_datetime_from_ignored_line() {
        assert_that!(Entry::datetime_from_line(IGNORED_LINE)).contains("2013-06-05 10:00:02");
    }

    #[test]
    fn test_date_from_empty_line() {
        assert_that!(Entry::date_from_line("")).is_none()
    }

    #[test]
    fn test_date_from_commented_line() {
        assert_that!(Entry::date_from_line("# Random comment")).is_none();
        assert_that!(Entry::date_from_line("#2013-06-05 10:00:02 +test @Commented")).is_none()
    }

    #[test]
    fn test_date_from_line() {
        assert_that!(Entry::date_from_line(CANONICAL_LINE)).contains("2013-06-05");
    }

    #[test]
    fn test_date_from_ignored_line() {
        assert_that!(Entry::date_from_line(IGNORED_LINE)).contains("2013-06-05");
    }

    #[test]
    fn from_line_error_if_not_entry() {
        assert_that!(Entry::from_line("This is not an entry"))
            .is_err_containing(EntryError::InvalidTimeStamp);
    }

    #[test]
    fn from_line_canonical_entry() {
        let entry = Entry::from_line(CANONICAL_LINE).unwrap();
        assert_that!(&entry.stamp()).is_equal_to(&String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1 @do something"));
        assert_that!(&entry.task()).contains_value(String::from("do"));
        assert_that!(&entry.detail()).contains_value(String::from("something"));
        assert_that!(&entry.task_and_detail())
            .is_equal_to((Some(String::from("do")), Some(String::from("something"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&CANONICAL_LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn new_canonical_entry() {
        let canonical_time = DateTime::try_from("2013-06-05 10:00:02").unwrap();
        let entry = Entry::new("+proj1 @do something", canonical_time);
        assert_that!(&entry.stamp()).is_equal_to(String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1 @do something"));
        assert_that!(&entry.task()).contains_value(String::from("do"));
        assert_that!(&entry.detail()).contains_value(String::from("something"));
        assert_that!(&entry.task_and_detail())
            .is_equal_to((Some(String::from("do")), Some(String::from("something"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&CANONICAL_LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn from_line_no_task_entry() {
        const LINE: &str = "2013-06-05 10:00:02 +proj1 do something";
        let entry = Entry::from_line(LINE).unwrap();
        assert_that!(&entry.stamp()).is_equal_to(&String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1 do something"));
        assert_that!(&entry.task()).is_none();
        assert_that!(&entry.detail()).contains_value(String::from("do something"));
        assert_that!(&entry.task_and_detail())
            .is_equal_to((None, Some(String::from("do something"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn from_line_no_detail_entry() {
        const LINE: &str = "2013-06-05 10:00:02 +proj1 @something";
        let entry = Entry::from_line(LINE).unwrap();
        assert_that!(&entry.stamp()).is_equal_to(&String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1 @something"));
        assert_that!(&entry.task()).contains_value(String::from("something"));
        assert_that!(&entry.detail()).is_none();
        assert_that!(&entry.task_and_detail()).is_equal_to((Some(String::from("something")), None));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn from_line_no_entry_text() {
        const LINE: &str = "2013-06-05 10:00:02 +proj1";
        let entry = Entry::from_line(LINE).unwrap();
        assert_that!(&entry.stamp()).is_equal_to(&String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1"));
        assert_that!(&entry.task()).is_none();
        assert_that!(&entry.detail()).is_none();
        assert_that!(&entry.task_and_detail()).is_equal_to((None, None));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn from_line_stop_entry() {
        let entry = Entry::from_line(STOP_LINE).unwrap();
        assert_that!(&entry.stamp()).is_equal_to(String::from("2013-06-05"));
        assert_that!(&entry.project()).is_none();
        assert_that!(&entry.entry_text()).is_equal_to(String::from("stop"));
        assert_that!(&entry.task()).is_none();
        assert_that!(&entry.detail()).contains_value(String::from("stop"));
        assert_that!(&entry.task_and_detail()).is_equal_to((None, Some(String::from("stop"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&STOP_LINE);
        assert_that!(&entry.is_stop()).is_true();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn test_extract_year() {
        let line = "2018-11-20 12:34:43 +test @Event";
        assert_that!(Entry::extract_year(line)).contains(2018);
    }

    #[test]
    fn test_extract_year_fail() {
        let line = "xyzzy 2018-11-20 12:34:43 +test @Event";
        assert_that!(Entry::extract_year(line)).is_none();
    }

    #[test]
    fn new_stop_entry() {
        let canonical_time = DateTime::try_from("2013-06-05 10:00:02").unwrap();
        let entry = Entry::new("stop", canonical_time);
        assert_that!(&entry.stamp()).is_equal_to(String::from("2013-06-05"));
        assert_that!(&entry.project()).is_none();
        assert_that!(&entry.entry_text()).is_equal_to(String::from("stop"));
        assert_that!(&entry.task()).is_none();
        assert_that!(&entry.detail()).contains_value(String::from("stop"));
        assert_that!(&entry.task_and_detail()).is_equal_to((None, Some(String::from("stop"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&STOP_LINE);
        assert_that!(&entry.is_stop()).is_true();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn from_line_ignored_entry() {
        let entry = Entry::from_line(IGNORED_LINE).unwrap();
        assert_that!(&entry.stamp()).is_equal_to(&String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1 @do something"));
        assert_that!(&entry.task()).contains_value(String::from("do"));
        assert_that!(&entry.detail()).contains_value(String::from("something"));
        assert_that!(&entry.task_and_detail())
            .is_equal_to((Some(String::from("do")), Some(String::from("something"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&IGNORED_LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_true();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn new_ignored_entry() {
        let canonical_time = DateTime::try_from("2013-06-05 10:00:02").unwrap();
        let entry = Entry::new_marked("+proj1 @do something", canonical_time, EntryKind::Ignored);
        assert_that!(&entry.stamp()).is_equal_to(String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1 @do something"));
        assert_that!(&entry.task()).contains_value(String::from("do"));
        assert_that!(&entry.detail()).contains_value(String::from("something"));
        assert_that!(&entry.task_and_detail())
            .is_equal_to((Some(String::from("do")), Some(String::from("something"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&IGNORED_LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_true();
        assert_that!(&entry.is_event()).is_false();
    }

    #[test]
    fn from_line_event_entry() {
        let entry = Entry::from_line(EVENT_LINE).unwrap();
        assert_that!(&entry.stamp()).is_equal_to(&String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1 @do something"));
        assert_that!(&entry.task()).contains_value(String::from("do"));
        assert_that!(&entry.detail()).contains_value(String::from("something"));
        assert_that!(&entry.task_and_detail())
            .is_equal_to((Some(String::from("do")), Some(String::from("something"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&EVENT_LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_true();
    }

    #[test]
    fn new_event_entry() {
        let canonical_time = DateTime::try_from("2013-06-05 10:00:02").unwrap();
        let entry = Entry::new_marked("+proj1 @do something", canonical_time, EntryKind::Event);
        assert_that!(&entry.stamp()).is_equal_to(String::from("2013-06-05"));
        assert_that!(&entry.project()).contains_value(String::from("proj1"));
        assert_that!(&entry.entry_text()).is_equal_to(String::from("+proj1 @do something"));
        assert_that!(&entry.task()).contains_value(String::from("do"));
        assert_that!(&entry.detail()).contains_value(String::from("something"));
        assert_that!(&entry.task_and_detail())
            .is_equal_to((Some(String::from("do")), Some(String::from("something"))));
        assert_that!(&entry.epoch()).is_equal_to(&reference_time());
        assert_that!(&entry.to_string().as_str()).is_equal_to(&EVENT_LINE);
        assert_that!(&entry.is_stop()).is_false();
        assert_that!(&entry.is_ignore()).is_false();
        assert_that!(&entry.is_event()).is_true();
    }

    #[test]
    fn compare_entry() {
        const LINE1: &str = "2013-06-05 10:00:02 +proj1";
        const LINE2: &str = "2013-06-05 11:00:02 +proj1";
        let entry1 = Entry::from_line(LINE1).unwrap();
        let entry2 = Entry::from_line(LINE2).unwrap();
        assert_that!(entry2 > entry1).is_true();
        assert_that!(entry1 < entry2).is_true();
        assert_that!(entry1 == entry1).is_true();
    }
}