timelog/
lib.rs

1//! System for logging time entries in a text-log-based format.
2//!
3//! The [`rtimelog`](../rtimelog/index.html) application applies these concepts as a command line
4//! tool.
5//!
6//! This library supports the various concepts that go into making a timelog.
7//! The core functionality is based around the concepts:
8//!
9//! - [`Day`](day::Day) - a container for events that we wish to track
10//! - [`Entry`](entry::Entry) - a task to be accomplished as a continuous chunk of time
11//! - [`Logfile`](logfile::Logfile) - list of all the that events started by the program
12//! - [`Stack`](stack::Stack) - a stack of tasks that we may want to go back to
13//!
14//! Further support for working these events is supplied by:
15//!
16//! - [`Cli`](cli::Cli) - Handles the functionality provided by the command line tool
17//! - [`Config`](config::Config) - Wrap the configuration information in an object
18//! - [`Date`](date::Date) - A utility type that simplifies working with dates (including parsing,
19//! etc.)
20//! - [`DateRange`](date::DateRange) - A pair of [`Date`]s representing a half-open range of days.
21//! - [`DateTime`](date::DateTime) - A utility type that simplifies working with date/times
22//! (including parsing, etc.)
23//! - [`Error`](error::Error) - an enumeration of the errors that can be encountered in processing
24//! timelogs
25//! - [`Result`] - Result specialized for [`Error`](error::Error)
26//! - [`TaskEvent`](task::TaskEvent) - Type representing a single entry tracked by timelog.
27//! - [`TaskLineIter`](task_line_iter::TaskLineIter) - an iterator for walking the entry lines in a
28//! timelog file
29
30#![warn(clippy::cast_lossless)]
31#![warn(clippy::return_self_not_must_use)]
32#![warn(clippy::uninlined_format_args)]
33#![warn(clippy::unwrap_used)]
34
35extern crate chrono;
36extern crate clap;
37extern crate configparser;
38extern crate regex;
39extern crate tilde_expand;
40extern crate xml;
41
42#[cfg(test)]
43extern crate spectral;
44
45#[cfg(test)]
46extern crate tempfile;
47
48pub(crate) mod archive;
49pub mod chart;
50pub mod cli;
51pub mod config;
52pub mod date;
53pub mod day;
54pub mod entry;
55pub mod error;
56pub mod file;
57pub mod logfile;
58pub(crate) mod macros;
59pub mod stack;
60pub mod task;
61pub mod task_line_iter;
62
63/// Command line parser and application driver
64pub use cli::Cli;
65
66/// Wrapper for configuration information
67pub use config::Config;
68
69/// Wrapper for Dates as used in the crate
70pub use date::Date;
71
72/// Wrapper for a range of Dates.
73pub use date::DateRange;
74
75/// Wrapper for Date/Times as used in the crate
76pub use date::DateTime;
77
78/// Represention of a day as a set of times, entries, and durations.
79pub use day::Day;
80
81/// Module representing an entry in the timelog
82pub use entry::Entry;
83
84/// An error that occurs in the working with timelogs
85pub use error::Error;
86
87/// Interface to the logfile for the timelog application.
88pub use logfile::Logfile;
89
90/// Interface to the stack file for the timelog application.
91pub use stack::Stack;
92
93/// Type representing a single task entry.
94pub use task::TaskEvent;
95
96/// Iterator for walking task lines
97pub use task_line_iter::TaskLineIter;
98
99/// Result type for timelog
100pub type Result<T> = std::result::Result<T, Error>;
101
102use std::fs;
103use std::io::{BufRead, BufReader};
104use std::result;
105
106// Utility function for dealing with the mess around the BufReader
107pub(crate) fn buf_reader(file: fs::File) -> impl Iterator<Item = String> {
108    BufReader::new(file)
109        .lines()
110        .map_while(result::Result::ok)
111        .filter(|ln| !Entry::is_comment_line(ln))
112}