Skip to content

Commit

Permalink
Compute runtime when adding stop_time to record in pyauditor
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-k committed Feb 23, 2023
1 parent 796f906 commit 592c4c0
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions pyauditor/src/domain/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ impl Record {
let stop_time: NaiveDateTime = stop_time.extract()?;
let stop_time = Utc.from_utc_datetime(&stop_time.into());
self_.inner.stop_time = Some(stop_time);
if let Some(start_time) = self_.inner.start_time.as_ref() {
self_.inner.runtime = Some((stop_time - *start_time).num_seconds())
}
Ok(self_)
}

Expand Down Expand Up @@ -161,19 +164,10 @@ impl Record {

/// Returns the runtime of a record.
#[getter]
fn get_runtime(&self) -> Option<i64> {
fn runtime(&self) -> Option<i64> {
self.inner.runtime
}

/// Set runtime of a record.
///
/// Note: Should only be used for mocking records received from an Auditor instance.
#[setter]
fn set_runtime(&mut self, value: i64) -> PyResult<()> {
self.inner.runtime = Some(value);
Ok(())
}

/// Output content of Record as JSON-encoded string
fn to_json(&self) -> Result<String, Error> {
Ok(format!("{}", serde_json::to_value(&self.inner)?))
Expand Down

0 comments on commit 592c4c0

Please sign in to comment.