Skip to content

Commit

Permalink
Merge branch 'main' into finalize-2.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Sep 22, 2023
2 parents d94392a + 21a9e24 commit 9bc02f9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 181 deletions.
176 changes: 3 additions & 173 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ yaml-rust = "0.4.*"
tokio = { version = "1", features = ["full"] }
num_cpus = "1.*"
downcast-rs = "1.*"
hhmmss = "*"
indicatif = "*"
hashbrown = "0.14.*"
hex = "0.4.*"
Expand Down
4 changes: 2 additions & 2 deletions src/debug/checkpoint_process_timer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Mutex;

use crate::detections::utils::output_duration;
use chrono::{DateTime, Local};
use hhmmss::Hhmmss;
use lazy_static::lazy_static;
use nested::Nested;

Expand Down Expand Up @@ -38,7 +38,7 @@ impl CheckPointProcessTimer {
self.stocked_results.push(format!(
"{}: {} ",
output_str,
(new_checkpoint - self.prev_checkpoint.unwrap()).hhmmssxxx()
output_duration(new_checkpoint - self.prev_checkpoint.unwrap())
));
self.prev_checkpoint = Some(new_checkpoint);
}
Expand Down
35 changes: 33 additions & 2 deletions src/detections/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use itertools::Itertools;
use nested::Nested;
use std::path::{Path, PathBuf};

use chrono::Local;
use chrono::{Duration, Local};
use termcolor::{Color, ColorChoice};

use tokio::runtime::{Builder, Runtime};
Expand Down Expand Up @@ -676,6 +676,21 @@ pub fn is_filtered_by_computer_name(
false
}

///Durationから出力文字列を作成する関数。絶対値での秒数から算出してhh:mm:ss.fffの形式で出力する。
pub fn output_duration(d: Duration) -> String {
let mut s = d.num_seconds();
let mut ms = d.num_milliseconds() - 1000 * s;
if s < 0 {
s = -s;
ms = -ms;
}
let h = s / 3600;
s %= 3600;
let m = s / 60;
s %= 60;
format!("{h:02}:{m:02}:{s:02}.{ms:03}")
}

#[cfg(test)]
mod tests {
use std::path::Path;
Expand All @@ -691,13 +706,14 @@ mod tests {
},
options::htmlreport::HTML_REPORTER,
};
use chrono::NaiveDate;
use compact_str::CompactString;
use hashbrown::{HashMap, HashSet};
use nested::Nested;
use regex::Regex;
use serde_json::Value;

use super::output_profile_name;
use super::{output_duration, output_profile_name};

#[test]
fn test_create_recordinfos() {
Expand Down Expand Up @@ -1098,4 +1114,19 @@ mod tests {
),
));
}

#[test]
/// Durationから出力文字列を作成する関数のテスト
fn test_output_duration() {
let time1 = NaiveDate::from_ymd_opt(2021, 12, 26)
.unwrap()
.and_hms_milli_opt(2, 34, 49, 0)
.unwrap();
let time2 = NaiveDate::from_ymd_opt(2021, 12, 25)
.unwrap()
.and_hms_milli_opt(1, 23, 45, 678)
.unwrap();
assert_eq!(output_duration(time1 - time2), "25:11:03.322".to_string());
assert_eq!(output_duration(time2 - time1), "25:11:03.322".to_string());
}
}
Loading

0 comments on commit 9bc02f9

Please sign in to comment.