commit 7a996b671b0e0738b989fc72a18b590306d0a30f Author: pjht Date: Fri Oct 4 12:39:56 2024 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..cc6cfdb --- /dev/null +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..fef34dc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "tstamper" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5be9fd4 --- /dev/null +++ b/src/main.rs @@ -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) +}