pub struct EasyTime<F: TimeZone> { /* private fields */ }Expand description
The main struct for time operations.
EasyTime provides convenient static methods for calculating dates in the future or past.
It is generic over any timezone F that implements chrono::TimeZone.
§Type Parameters
F- A timezone type that implementschrono::TimeZone
§Example
use easy_time::EasyTime;
use chrono::{Local, Utc};
// Simple time calculations with Local timezone
let five_days_from_now = EasyTime::<Local>::days_from_now(5);
let five_days_ago = EasyTime::<Local>::days_ago(5);
// Using UTC timezone
let ten_hours_from_now = EasyTime::<Utc>::hours_from_now(10);
// Convenience UTC methods
let utc_future = EasyTime::<Local>::utc_days_from_now(7);Implementations§
Source§impl EasyTime<Local>
impl EasyTime<Local>
Sourcepub fn seconds_from_now(value: i64) -> DateTime<Local>
pub fn seconds_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value seconds in the future from now.
§Example
use easy_time::EasyTime;
use chrono::Local;
let future = EasyTime::<Local>::seconds_from_now(30);Sourcepub fn seconds_ago(value: i64) -> DateTime<Local>
pub fn seconds_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value seconds in the past from now.
Sourcepub fn minutes_from_now(value: i64) -> DateTime<Local>
pub fn minutes_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value minutes in the future from now.
Sourcepub fn minutes_ago(value: i64) -> DateTime<Local>
pub fn minutes_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value minutes in the past from now.
Sourcepub fn hours_from_now(value: i64) -> DateTime<Local>
pub fn hours_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value hours in the future from now.
Sourcepub fn hours_ago(value: i64) -> DateTime<Local>
pub fn hours_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value hours in the past from now.
Sourcepub fn days_from_now(value: i64) -> DateTime<Local>
pub fn days_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value days in the future from now.
Sourcepub fn days_ago(value: i64) -> DateTime<Local>
pub fn days_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value days in the past from now.
Sourcepub fn weeks_from_now(value: i64) -> DateTime<Local>
pub fn weeks_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value weeks in the future from now.
Sourcepub fn weeks_ago(value: i64) -> DateTime<Local>
pub fn weeks_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value weeks in the past from now.
Sourcepub fn months_from_now(value: i64) -> DateTime<Local>
pub fn months_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value months in the future from now.
Handles edge cases like months with different numbers of days.
Sourcepub fn months_ago(value: i64) -> DateTime<Local>
pub fn months_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value months in the past from now.
Sourcepub fn years_from_now(value: i64) -> DateTime<Local>
pub fn years_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value years in the future from now.
Sourcepub fn years_ago(value: i64) -> DateTime<Local>
pub fn years_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value years in the past from now.
Sourcepub fn decades_from_now(value: i64) -> DateTime<Local>
pub fn decades_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value decades (10 years) in the future from now.
Sourcepub fn decades_ago(value: i64) -> DateTime<Local>
pub fn decades_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value decades (10 years) in the past from now.
Sourcepub fn centuries_from_now(value: i64) -> DateTime<Local>
pub fn centuries_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value centuries (100 years) in the future from now.
Sourcepub fn centuries_ago(value: i64) -> DateTime<Local>
pub fn centuries_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value centuries (100 years) in the past from now.
Sourcepub fn millenniums_from_now(value: i64) -> DateTime<Local>
pub fn millenniums_from_now(value: i64) -> DateTime<Local>
Returns a datetime that is value millenniums (1000 years) in the future from now.
Sourcepub fn millenniums_ago(value: i64) -> DateTime<Local>
pub fn millenniums_ago(value: i64) -> DateTime<Local>
Returns a datetime that is value millenniums (1000 years) in the past from now.
Sourcepub fn seconds_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn seconds_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value seconds from the given base time.
Sourcepub fn seconds_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn seconds_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value seconds before the given base time.
Sourcepub fn minutes_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn minutes_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value minutes from the given base time.
Sourcepub fn minutes_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn minutes_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value minutes before the given base time.
Sourcepub fn hours_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn hours_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value hours from the given base time.
Sourcepub fn hours_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn hours_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value hours before the given base time.
Sourcepub fn days_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn days_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value days from the given base time.
Sourcepub fn days_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn days_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value days before the given base time.
Sourcepub fn weeks_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn weeks_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value weeks from the given base time.
Sourcepub fn weeks_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn weeks_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value weeks before the given base time.
Sourcepub fn months_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn months_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value months from the given base time.
Sourcepub fn months_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn months_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value months before the given base time.
Sourcepub fn years_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn years_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value years from the given base time.
Sourcepub fn years_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn years_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value years before the given base time.
Sourcepub fn decades_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn decades_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value decades from the given base time.
Sourcepub fn decades_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn decades_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value decades before the given base time.
Sourcepub fn centuries_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn centuries_from(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value centuries from the given base time.
Sourcepub fn centuries_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
pub fn centuries_before(base: DateTime<Local>, value: i64) -> DateTime<Local>
Returns a datetime that is value centuries before the given base time.
Source§impl EasyTime<Utc>
impl EasyTime<Utc>
Sourcepub fn seconds_from_now(value: i64) -> DateTime<Utc>
pub fn seconds_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value seconds in the future from now.
Sourcepub fn seconds_ago(value: i64) -> DateTime<Utc>
pub fn seconds_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value seconds in the past from now.
Sourcepub fn minutes_from_now(value: i64) -> DateTime<Utc>
pub fn minutes_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value minutes in the future from now.
Sourcepub fn minutes_ago(value: i64) -> DateTime<Utc>
pub fn minutes_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value minutes in the past from now.
Sourcepub fn hours_from_now(value: i64) -> DateTime<Utc>
pub fn hours_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value hours in the future from now.
Sourcepub fn hours_ago(value: i64) -> DateTime<Utc>
pub fn hours_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value hours in the past from now.
Sourcepub fn days_from_now(value: i64) -> DateTime<Utc>
pub fn days_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value days in the future from now.
Sourcepub fn days_ago(value: i64) -> DateTime<Utc>
pub fn days_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value days in the past from now.
Sourcepub fn weeks_from_now(value: i64) -> DateTime<Utc>
pub fn weeks_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value weeks in the future from now.
Sourcepub fn weeks_ago(value: i64) -> DateTime<Utc>
pub fn weeks_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value weeks in the past from now.
Sourcepub fn months_from_now(value: i64) -> DateTime<Utc>
pub fn months_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value months in the future from now.
Sourcepub fn months_ago(value: i64) -> DateTime<Utc>
pub fn months_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value months in the past from now.
Sourcepub fn years_from_now(value: i64) -> DateTime<Utc>
pub fn years_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value years in the future from now.
Sourcepub fn years_ago(value: i64) -> DateTime<Utc>
pub fn years_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value years in the past from now.
Sourcepub fn decades_from_now(value: i64) -> DateTime<Utc>
pub fn decades_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value decades (10 years) in the future from now.
Sourcepub fn decades_ago(value: i64) -> DateTime<Utc>
pub fn decades_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value decades (10 years) in the past from now.
Sourcepub fn centuries_from_now(value: i64) -> DateTime<Utc>
pub fn centuries_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value centuries (100 years) in the future from now.
Sourcepub fn centuries_ago(value: i64) -> DateTime<Utc>
pub fn centuries_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value centuries (100 years) in the past from now.
Sourcepub fn millenniums_from_now(value: i64) -> DateTime<Utc>
pub fn millenniums_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value millenniums (1000 years) in the future from now.
Sourcepub fn millenniums_ago(value: i64) -> DateTime<Utc>
pub fn millenniums_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value millenniums (1000 years) in the past from now.
Sourcepub fn seconds_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn seconds_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value seconds from the given base time.
Sourcepub fn seconds_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn seconds_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value seconds before the given base time.
Sourcepub fn minutes_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn minutes_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value minutes from the given base time.
Sourcepub fn minutes_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn minutes_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value minutes before the given base time.
Sourcepub fn hours_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn hours_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value hours from the given base time.
Sourcepub fn hours_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn hours_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value hours before the given base time.
Sourcepub fn days_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn days_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value days from the given base time.
Sourcepub fn days_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn days_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value days before the given base time.
Sourcepub fn weeks_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn weeks_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value weeks from the given base time.
Sourcepub fn weeks_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn weeks_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value weeks before the given base time.
Sourcepub fn months_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn months_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value months from the given base time.
Sourcepub fn months_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn months_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value months before the given base time.
Sourcepub fn years_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn years_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value years from the given base time.
Sourcepub fn years_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn years_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value years before the given base time.
Sourcepub fn decades_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn decades_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value decades from the given base time.
Sourcepub fn decades_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn decades_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value decades before the given base time.
Sourcepub fn centuries_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn centuries_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value centuries from the given base time.
Sourcepub fn centuries_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
pub fn centuries_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value centuries before the given base time.
Source§impl<F: TimeZone> EasyTime<F>
impl<F: TimeZone> EasyTime<F>
Sourcepub fn utc_seconds_from_now(value: i64) -> DateTime<Utc>
pub fn utc_seconds_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value seconds in the future from now.
Convenience method that doesn’t require specifying a type parameter.
§Example
use easy_time::EasyTime;
use chrono::Local;
let future = EasyTime::<Local>::utc_seconds_from_now(30);Sourcepub fn utc_seconds_ago(value: i64) -> DateTime<Utc>
pub fn utc_seconds_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value seconds in the past from now.
Sourcepub fn utc_minutes_from_now(value: i64) -> DateTime<Utc>
pub fn utc_minutes_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value minutes in the future from now.
Sourcepub fn utc_minutes_ago(value: i64) -> DateTime<Utc>
pub fn utc_minutes_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value minutes in the past from now.
Sourcepub fn utc_hours_from_now(value: i64) -> DateTime<Utc>
pub fn utc_hours_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value hours in the future from now.
Sourcepub fn utc_hours_ago(value: i64) -> DateTime<Utc>
pub fn utc_hours_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value hours in the past from now.
Sourcepub fn utc_days_from_now(value: i64) -> DateTime<Utc>
pub fn utc_days_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value days in the future from now.
Sourcepub fn utc_days_ago(value: i64) -> DateTime<Utc>
pub fn utc_days_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value days in the past from now.
Sourcepub fn utc_weeks_from_now(value: i64) -> DateTime<Utc>
pub fn utc_weeks_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value weeks in the future from now.
Sourcepub fn utc_weeks_ago(value: i64) -> DateTime<Utc>
pub fn utc_weeks_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value weeks in the past from now.
Sourcepub fn utc_months_from_now(value: i64) -> DateTime<Utc>
pub fn utc_months_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value months in the future from now.
Sourcepub fn utc_months_ago(value: i64) -> DateTime<Utc>
pub fn utc_months_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value months in the past from now.
Sourcepub fn utc_years_from_now(value: i64) -> DateTime<Utc>
pub fn utc_years_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value years in the future from now.
Sourcepub fn utc_years_ago(value: i64) -> DateTime<Utc>
pub fn utc_years_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value years in the past from now.
Sourcepub fn utc_decades_from_now(value: i64) -> DateTime<Utc>
pub fn utc_decades_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value decades in the future from now.
Sourcepub fn utc_decades_ago(value: i64) -> DateTime<Utc>
pub fn utc_decades_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value decades in the past from now.
Sourcepub fn utc_centuries_from_now(value: i64) -> DateTime<Utc>
pub fn utc_centuries_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value centuries in the future from now.
Sourcepub fn utc_centuries_ago(value: i64) -> DateTime<Utc>
pub fn utc_centuries_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value centuries in the past from now.
Sourcepub fn utc_millenniums_from_now(value: i64) -> DateTime<Utc>
pub fn utc_millenniums_from_now(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value millenniums in the future from now.
Sourcepub fn utc_millenniums_ago(value: i64) -> DateTime<Utc>
pub fn utc_millenniums_ago(value: i64) -> DateTime<Utc>
Returns a UTC datetime that is value millenniums in the past from now.
Sourcepub fn is_leap_year(year: i32) -> bool
pub fn is_leap_year(year: i32) -> bool
Checks if a year is a leap year.
§Example
use easy_time::EasyTime;
use chrono::Local;
assert!(EasyTime::<Local>::is_leap_year(2024));
assert!(!EasyTime::<Local>::is_leap_year(2023));Sourcepub fn days_in_month(year: i32, month: u32) -> u32
pub fn days_in_month(year: i32, month: u32) -> u32
Returns the number of days in a given month.
§Example
use easy_time::EasyTime;
use chrono::Local;
assert_eq!(EasyTime::<Local>::days_in_month(2024, 2), 29); // Leap year
assert_eq!(EasyTime::<Local>::days_in_month(2023, 2), 28); // Non-leap year