Initial commit
This commit is contained in:
commit
7a996b671b
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "tstamper"
|
||||
version = "0.1.0"
|
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "tstamper"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
43
src/main.rs
Normal file
43
src/main.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use std::io::{self, BufRead};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let mut lines = io::stdin().lock().lines();
|
||||
|
||||
let start_time = loop {
|
||||
if let Some(line) = lines.next() {
|
||||
let start_time = Instant::now();
|
||||
|
||||
let line = line?;
|
||||
|
||||
if line.starts_with("[PMM]") {
|
||||
println!("{} {line}", format_timestamp(Duration::new(0, 0)));
|
||||
break start_time;
|
||||
} else {
|
||||
println!("FIRM {line}");
|
||||
}
|
||||
} else {
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
for line in lines {
|
||||
let line = line?;
|
||||
let elapsed = Instant::now().duration_since(start_time);
|
||||
println!("{} {line}", format_timestamp(elapsed));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn format_timestamp(duration: Duration) -> String {
|
||||
let micros = duration.as_micros();
|
||||
let secs = micros / 1_000_000;
|
||||
let micros = micros % 1_000_000;
|
||||
|
||||
let hours = secs / 3600;
|
||||
let mins = (secs % 3600) / 60;
|
||||
let secs = secs % 60;
|
||||
|
||||
format!("{:02}:{:02}:{:02}.{:06}", hours, mins, secs, micros)
|
||||
}
|
Loading…
Reference in New Issue
Block a user