Skip to content

Commit

Permalink
fixup! feat(prover): store time taken by prover with ms precision
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniolocascio committed Jul 25, 2024
1 parent 8d2e87a commit c4973a3
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions core/lib/db_connection/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,20 @@ const MICROSECONDS_IN_A_SECOND: i64 = 1_000_000;
const MICROSECONDS_IN_A_MINUTE: i64 = MICROSECONDS_IN_A_SECOND * 60;
const MICROSECONDS_IN_AN_HOUR: i64 = MICROSECONDS_IN_A_MINUTE * 60;

fn duration_to_naive_time_common(duration: Duration, use_ms: bool) -> NaiveTime {
let total_ms = duration.as_millis();
let total_seconds = (total_ms / 1_000) as u32;
let hours = total_seconds / 3_600;
let minutes = (total_seconds / 60) % 60;
let seconds = total_seconds % 60;
let ms = (total_ms % 1_000) as u32;

if use_ms {
NaiveTime::from_hms_milli_opt(hours, minutes, seconds, ms).unwrap()
} else {
NaiveTime::from_hms_opt(hours, minutes, seconds).unwrap()
}
}
pub fn duration_to_naive_time(duration: Duration) -> NaiveTime {
duration_to_naive_time_common(duration, false)
let total_seconds = duration.as_secs() as u32;
NaiveTime::from_hms_opt(
total_seconds / 3600,
(total_seconds / 60) % 60,
total_seconds % 60,
)
.expect("failed to convert Duration to NaiveTime")
}

pub fn duration_to_naive_time_ms(duration: Duration) -> NaiveTime {
duration_to_naive_time_common(duration, true)
let total_ms = duration.as_millis();
let ms = (total_ms % 1_000) as u64;
duration_to_naive_time(duration) + Duration::from_millis(ms)
}

pub const fn pg_interval_from_duration(processing_timeout: Duration) -> PgInterval {
Expand Down

0 comments on commit c4973a3

Please sign in to comment.