Trait ExtTime

Source
pub trait ExtTime {
    // Required methods
    fn to_shorten(&self) -> String;
    fn from_str(time_str: &str) -> Result<Time>;
    fn sub_ext(&self, right: Time) -> Duration;
    fn reset_minute(&self) -> Result<Time>;
    fn is_same_minute(&self, other: &Time) -> bool;
    fn is_between(&self, start: Time, end: Time) -> bool;
    fn add_minutes(&self, minutes: i64) -> Time;
}
Expand description

Extension trait for Time struct providing additional utility methods

Required Methods§

Source

fn to_shorten(&self) -> String

Format time as HH:MM, padding minutes with zero if needed

§Example
use time::macros::time;
use ext_time::ExtTime;
 
let t = time!(9:05);
assert_eq!(t.to_shorten(), "9:05");
Source

fn from_str(time_str: &str) -> Result<Time>

Parse time string in HH:MM format

§Arguments
  • time_str - Time string in “HH:MM” format
§Returns
  • Ok(Time) - Parsed time
  • Err - If parsing fails
Source

fn sub_ext(&self, right: Time) -> Duration

Calculate duration between two times, handling cross-day scenarios

§Arguments
  • right - The time to subtract from self
§Returns

Duration between times, always positive by adding 24 hours if needed

Source

fn reset_minute(&self) -> Result<Time>

Reset seconds to zero, keeping hours and minutes

Source

fn is_same_minute(&self, other: &Time) -> bool

Check if two times are in the same minute

Source

fn is_between(&self, start: Time, end: Time) -> bool

Check if time is between start and end (inclusive) Handles cross-day ranges (e.g., 23:00 to 01:00)

Source

fn add_minutes(&self, minutes: i64) -> Time

Add minutes to time, wrapping around midnight if needed

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§