Skip to content

Commit 35456c2

Browse files
authored
Cleanup error handling and everything in general (#20)
- Better error handling - Add settings file to enabling storing data file in separate location - Add some basic docs and example tests
1 parent 8827525 commit 35456c2

File tree

6 files changed

+717
-252
lines changed

6 files changed

+717
-252
lines changed

Cargo.lock

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ serde = "1.0.15"
1616
serde_derive = "1.0.15"
1717
serde_json = "1.0.4"
1818
colored = "1.5"
19+
chrono-english = "0.1.3"
20+
21+
[dev-dependencies]
22+
tempfile = "3.0.4"

src/format.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use chrono::{DateTime, Duration, Local, Utc};
2+
3+
pub fn datetime(time: DateTime<Utc>) -> String {
4+
time.with_timezone(&Local).format("%F %H:%M").to_string()
5+
}
6+
7+
pub fn time(time: DateTime<Utc>) -> String {
8+
time.with_timezone(&Local).format("%H:%M").to_string()
9+
}
10+
11+
pub fn duration(duration: Duration) -> String {
12+
let hours = duration.num_hours();
13+
let minutes = duration.num_minutes() % 60;
14+
let seconds = duration.num_seconds() % 60;
15+
16+
if duration.num_minutes() == 0 {
17+
format!("{}s", seconds)
18+
} else if duration.num_hours() == 0 {
19+
format!(
20+
"{minutes}m {seconds:>2}s",
21+
minutes = minutes,
22+
seconds = seconds
23+
)
24+
} else {
25+
format!(
26+
"{hours}h {minutes:>2}m {seconds:>2}s",
27+
hours = hours,
28+
minutes = minutes,
29+
seconds = seconds
30+
)
31+
}
32+
}

0 commit comments

Comments
 (0)