Initial commit

This commit is contained in:
pjht 2024-10-04 12:39:56 -05:00
commit 7a996b671b
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
4 changed files with 57 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View 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
View File

@ -0,0 +1,6 @@
[package]
name = "tstamper"
version = "0.1.0"
edition = "2021"
[dependencies]

43
src/main.rs Normal file
View 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)
}