MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / duration_display

Method duration_display

atomic-core/src/change/envelope.rs:365–385  ·  view source on GitHub ↗

Returns the turn duration as a human-readable string. # Example ```rust use atomic_core::change::envelope::SessionEnvelope; let e = SessionEnvelope::builder("s", "a") .turn_duration_ms(125_400) .build(); assert_eq!(e.duration_display(), "2m 5s"); let e = SessionEnvelope::builder("s", "a") .turn_duration_ms(800) .build(); assert_eq!(e.duration_display(), "800ms"); ```

(&self)

Source from the content-addressed store, hash-verified

363 /// assert_eq!(e.duration_display(), "800ms");
364 /// ```
365 pub fn duration_display(&self) -> String {
366 let ms = self.turn_duration_ms;
367 if ms < 1_000 {
368 format!("{}ms", ms)
369 } else if ms < 60_000 {
370 let secs = ms as f64 / 1_000.0;
371 if secs == secs.floor() {
372 format!("{}s", secs as u64)
373 } else {
374 format!("{:.1}s", secs)
375 }
376 } else {
377 let minutes = ms / 60_000;
378 let seconds = (ms % 60_000) / 1_000;
379 if seconds == 0 {
380 format!("{}m", minutes)
381 } else {
382 format!("{}m {}s", minutes, seconds)
383 }
384 }
385 }
386}
387
388impl std::fmt::Display for SessionEnvelope {

Callers 1

to_jsonMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected