precision also affects displaying timestamp on log
parent
5e832956db
commit
f9f3fa5212
22
src/main.rs
22
src/main.rs
|
|
@ -90,7 +90,7 @@ fn log(f: &String, enabled: &bool, since: &Option<String>, verbose: &bool, preci
|
||||||
}
|
}
|
||||||
let since = parse_time(since)?;
|
let since = parse_time(since)?;
|
||||||
if *verbose {
|
if *verbose {
|
||||||
eprintln!("since = {} ({})", system_time_to_unix_seconds(&since), timestamp(&system_time_to_unix_seconds(&since)));
|
eprintln!("since = {} ({})", system_time_to_unix_seconds(&since), timestamp(&system_time_to_unix_seconds(&since), &2));
|
||||||
}
|
}
|
||||||
|
|
||||||
let tsheet = load(&f)?;
|
let tsheet = load(&f)?;
|
||||||
|
|
@ -105,9 +105,9 @@ fn log(f: &String, enabled: &bool, since: &Option<String>, verbose: &bool, preci
|
||||||
for i in 0..tsheet.xs.len() {
|
for i in 0..tsheet.xs.len() {
|
||||||
let x = &tsheet.xs[i];
|
let x = &tsheet.xs[i];
|
||||||
if *verbose {
|
if *verbose {
|
||||||
eprintln!("{} != {}?", &curr.t, x.timestamp());
|
eprintln!("{} != {}?", &curr.t, x.timestamp(&precision));
|
||||||
}
|
}
|
||||||
if curr.t != x.timestamp() {
|
if curr.t != x.timestamp(&precision) {
|
||||||
if curr.xs.len() > 0 {
|
if curr.xs.len() > 0 {
|
||||||
if *verbose {
|
if *verbose {
|
||||||
eprintln!("push {:?}", &curr.xs);
|
eprintln!("push {:?}", &curr.xs);
|
||||||
|
|
@ -115,7 +115,7 @@ fn log(f: &String, enabled: &bool, since: &Option<String>, verbose: &bool, preci
|
||||||
result.push(curr.clone());
|
result.push(curr.clone());
|
||||||
}
|
}
|
||||||
curr.xs.truncate(0);
|
curr.xs.truncate(0);
|
||||||
curr.t = x.timestamp();
|
curr.t = x.timestamp(&precision);
|
||||||
curr.d = 0.0;
|
curr.d = 0.0;
|
||||||
}
|
}
|
||||||
let mut d = 1.0;
|
let mut d = 1.0;
|
||||||
|
|
@ -130,7 +130,7 @@ fn log(f: &String, enabled: &bool, since: &Option<String>, verbose: &bool, preci
|
||||||
match x.x.len() {
|
match x.x.len() {
|
||||||
0 => {},
|
0 => {},
|
||||||
_ => {
|
_ => {
|
||||||
curr.t = x.timestamp();
|
curr.t = x.timestamp(&precision);
|
||||||
curr.xs.push(LogX{d: d, x: x.x.clone()});
|
curr.xs.push(LogX{d: d, x: x.x.clone()});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -339,8 +339,8 @@ impl X {
|
||||||
UNIX_EPOCH.add(Duration::from_secs(self.t.try_into().unwrap()))
|
UNIX_EPOCH.add(Duration::from_secs(self.t.try_into().unwrap()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp(&self) -> String {
|
fn timestamp(&self, precision: &u32) -> String {
|
||||||
timestamp(&self.t)
|
timestamp(&self.t, &precision)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -348,9 +348,13 @@ fn system_time_to_unix_seconds(st: &SystemTime) -> i64 {
|
||||||
st.duration_since(UNIX_EPOCH).unwrap().as_secs() as i64
|
st.duration_since(UNIX_EPOCH).unwrap().as_secs() as i64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp(t: &i64) -> String {
|
fn timestamp(t: &i64, precision: &u32) -> String {
|
||||||
let dt = Local.timestamp_opt(*t, 0).unwrap();
|
let dt = Local.timestamp_opt(*t, 0).unwrap();
|
||||||
dt.format("%Y-%m-%d").to_string()
|
match precision {
|
||||||
|
0 => dt.format("%Y-%m-%d").to_string(),
|
||||||
|
1 => dt.format("%Y-%m-%dT%H:%M").to_string(),
|
||||||
|
_ => dt.format("%Y-%m-%dT%H:%M:%S").to_string(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_x(t: i64, x: String, tag: String) -> X {
|
fn new_x(t: i64, x: String, tag: String) -> X {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue