Trait ExtTime

Source
pub trait ExtTime {
Show 16 methods // Required methods fn to_shorten(&self) -> String; fn from_str(time_str: &str) -> Result<Time, TimeError>; fn sub_ext(&self, right: Time) -> Duration; fn reset_minute(&self) -> Result<Time, TimeError>; fn is_same_minute(&self, other: &Time) -> bool; fn is_between(&self, start: Time, end: Time) -> bool; fn add_minutes(&self, minutes: i64) -> Time; fn from_seconds(seconds: i64) -> Result<Time, TimeError>; fn to_seconds(&self) -> i64; fn align_to(&self, unit_seconds: u64) -> Result<Time, TimeError>; fn next_day(&self) -> Time; fn next_hour(&self) -> Time; fn next_minute(&self) -> Time; fn next_second(&self) -> Time; fn to_hour_seconds(&self) -> i64; fn to_minute_seconds(&self) -> i64;
}
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, TimeError>

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, TimeError>

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

Source

fn from_seconds(seconds: i64) -> Result<Time, TimeError>

Convert seconds (hours + minutes + seconds) to Time

§Arguments
  • seconds - Total seconds (hours * 3600 + minutes * 60 + seconds)
§Returns
  • Ok(Time) - Converted time
  • Err - If seconds value is invalid
Source

fn to_seconds(&self) -> i64

Convert Time to seconds (hours + minutes + seconds)

§Returns

Total seconds (hours * 3600 + minutes * 60 + seconds)

Source

fn align_to(&self, unit_seconds: u64) -> Result<Time, TimeError>

Align time to the specified unit

§Arguments
  • unit_seconds - The unit to align to in seconds (e.g., 300 for 5 minutes, 5 for 5 seconds)
§Returns
  • Ok(Time) - Aligned time
  • Err - If unit is invalid (must be positive and less than 24 hours)
Source

fn next_day(&self) -> Time

Get next day at the same time

Source

fn next_hour(&self) -> Time

Get next hour at the same minute and second

Source

fn next_minute(&self) -> Time

Get next minute at the same second

Source

fn next_second(&self) -> Time

Get next second

Source

fn to_hour_seconds(&self) -> i64

Convert time to seconds, ignoring minutes and seconds

§Returns

Total seconds of hours (hours * 3600)

Source

fn to_minute_seconds(&self) -> i64

Convert time to seconds, ignoring seconds

§Returns

Total seconds of hours and minutes (hours * 3600 + minutes * 60)

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§