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, interval: i64) -> 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§
Sourcefn to_shorten(&self) -> String
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");Sourcefn reset_minute(&self) -> Result<Time, TimeError>
fn reset_minute(&self) -> Result<Time, TimeError>
Reset seconds to zero, keeping hours and minutes
Sourcefn is_same_minute(&self, other: &Time) -> bool
fn is_same_minute(&self, other: &Time) -> bool
Check if two times are in the same minute
Sourcefn is_between(&self, start: Time, end: Time) -> bool
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)
Sourcefn add_minutes(&self, minutes: i64) -> Time
fn add_minutes(&self, minutes: i64) -> Time
Add minutes to time, wrapping around midnight if needed
Sourcefn to_seconds(&self) -> i64
fn to_seconds(&self) -> i64
Convert Time to seconds (hours + minutes + seconds)
§Returns
Total seconds (hours * 3600 + minutes * 60 + seconds)
Sourcefn next_minute(&self) -> Time
fn next_minute(&self) -> Time
Get next minute at the same second
Sourcefn next_second(&self) -> Time
fn next_second(&self) -> Time
Get next second
Sourcefn to_hour_seconds(&self) -> i64
fn to_hour_seconds(&self) -> i64
Convert time to seconds, ignoring minutes and seconds
§Returns
Total seconds of hours (hours * 3600)
Note: Returns i64 to support time differences and negative values
Sourcefn to_minute_seconds(&self) -> i64
fn to_minute_seconds(&self) -> i64
Convert time to seconds, ignoring seconds
§Returns
Total seconds of hours and minutes (hours * 3600 + minutes * 60)
Note: Returns i64 to support time differences and negative values
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.