Improve time formatting output to use local time and to hide nanoseconds
This commit is contained in:
parent
5a79895f92
commit
708d2bb049
1 changed files with 7 additions and 4 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -1,6 +1,6 @@
|
||||||
use std::io::{stdin, BufRead};
|
use std::io::{stdin, BufRead};
|
||||||
|
|
||||||
use chrono::{NaiveTime, Duration, Utc};
|
use chrono::{NaiveTime, Duration, Local};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use atty::Stream;
|
use atty::Stream;
|
||||||
|
|
||||||
|
|
@ -51,17 +51,20 @@ fn live_spans() -> Vec<Duration> {
|
||||||
let mut durations = vec![];
|
let mut durations = vec![];
|
||||||
let mut seen: Option<NaiveTime> = None;
|
let mut seen: Option<NaiveTime> = None;
|
||||||
for _line in stdin().lock().lines() {
|
for _line in stdin().lock().lines() {
|
||||||
let mut now = Utc::now().naive_local().time();
|
let mut now = Local::now().naive_local().time();
|
||||||
if let Some(previous) = &seen {
|
if let Some(previous) = &seen {
|
||||||
if now < *previous {
|
if now < *previous {
|
||||||
now = now + Duration::hours(12);
|
now = now + Duration::hours(12);
|
||||||
}
|
}
|
||||||
println!("Closing span from {previous} - {now}");
|
let prev_time = previous.format("%H:%M");
|
||||||
|
let now_time = now.format("%H:%M");
|
||||||
|
println!("Closing span from {prev_time} - {now_time}");
|
||||||
println!("Status: Away");
|
println!("Status: Away");
|
||||||
durations.push(now - *previous);
|
durations.push(now - *previous);
|
||||||
seen = None;
|
seen = None;
|
||||||
} else {
|
} else {
|
||||||
println!("Starting span at {now}");
|
let now_time = now.format("%H:%M");
|
||||||
|
println!("Starting span at {now_time}");
|
||||||
println!("Status: Working");
|
println!("Status: Working");
|
||||||
seen = Some(now);
|
seen = Some(now);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue