EasyTime

Struct EasyTime 

Source
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

§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>

Source

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);
Source

pub fn seconds_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value seconds in the past from now.

Source

pub fn minutes_from_now(value: i64) -> DateTime<Local>

Returns a datetime that is value minutes in the future from now.

Source

pub fn minutes_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value minutes in the past from now.

Source

pub fn hours_from_now(value: i64) -> DateTime<Local>

Returns a datetime that is value hours in the future from now.

Source

pub fn hours_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value hours in the past from now.

Source

pub fn days_from_now(value: i64) -> DateTime<Local>

Returns a datetime that is value days in the future from now.

Source

pub fn days_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value days in the past from now.

Source

pub fn weeks_from_now(value: i64) -> DateTime<Local>

Returns a datetime that is value weeks in the future from now.

Source

pub fn weeks_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value weeks in the past from now.

Source

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.

Source

pub fn months_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value months in the past from now.

Source

pub fn years_from_now(value: i64) -> DateTime<Local>

Returns a datetime that is value years in the future from now.

Source

pub fn years_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value years in the past from now.

Source

pub fn decades_from_now(value: i64) -> DateTime<Local>

Returns a datetime that is value decades (10 years) in the future from now.

Source

pub fn decades_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value decades (10 years) in the past from now.

Source

pub fn centuries_from_now(value: i64) -> DateTime<Local>

Returns a datetime that is value centuries (100 years) in the future from now.

Source

pub fn centuries_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value centuries (100 years) in the past from now.

Source

pub fn millenniums_from_now(value: i64) -> DateTime<Local>

Returns a datetime that is value millenniums (1000 years) in the future from now.

Source

pub fn millenniums_ago(value: i64) -> DateTime<Local>

Returns a datetime that is value millenniums (1000 years) in the past from now.

Source

pub fn seconds_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value seconds from the given base time.

Source

pub fn seconds_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value seconds before the given base time.

Source

pub fn minutes_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value minutes from the given base time.

Source

pub fn minutes_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value minutes before the given base time.

Source

pub fn hours_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value hours from the given base time.

Source

pub fn hours_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value hours before the given base time.

Source

pub fn days_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value days from the given base time.

Source

pub fn days_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value days before the given base time.

Source

pub fn weeks_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value weeks from the given base time.

Source

pub fn weeks_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value weeks before the given base time.

Source

pub fn months_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value months from the given base time.

Source

pub fn months_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value months before the given base time.

Source

pub fn years_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value years from the given base time.

Source

pub fn years_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value years before the given base time.

Source

pub fn decades_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value decades from the given base time.

Source

pub fn decades_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value decades before the given base time.

Source

pub fn centuries_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value centuries from the given base time.

Source

pub fn centuries_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value centuries before the given base time.

Source

pub fn millenniums_from(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value millenniums from the given base time.

Source

pub fn millenniums_before(base: DateTime<Local>, value: i64) -> DateTime<Local>

Returns a datetime that is value millenniums before the given base time.

Source§

impl EasyTime<Utc>

Source

pub fn seconds_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value seconds in the future from now.

Source

pub fn seconds_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value seconds in the past from now.

Source

pub fn minutes_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value minutes in the future from now.

Source

pub fn minutes_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value minutes in the past from now.

Source

pub fn hours_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value hours in the future from now.

Source

pub fn hours_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value hours in the past from now.

Source

pub fn days_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value days in the future from now.

Source

pub fn days_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value days in the past from now.

Source

pub fn weeks_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value weeks in the future from now.

Source

pub fn weeks_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value weeks in the past from now.

Source

pub fn months_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value months in the future from now.

Source

pub fn months_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value months in the past from now.

Source

pub fn years_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value years in the future from now.

Source

pub fn years_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value years in the past from now.

Source

pub fn decades_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value decades (10 years) in the future from now.

Source

pub fn decades_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value decades (10 years) in the past from now.

Source

pub fn centuries_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value centuries (100 years) in the future from now.

Source

pub fn centuries_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value centuries (100 years) in the past from now.

Source

pub fn millenniums_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value millenniums (1000 years) in the future from now.

Source

pub fn millenniums_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value millenniums (1000 years) in the past from now.

Source

pub fn seconds_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value seconds from the given base time.

Source

pub fn seconds_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value seconds before the given base time.

Source

pub fn minutes_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value minutes from the given base time.

Source

pub fn minutes_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value minutes before the given base time.

Source

pub fn hours_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value hours from the given base time.

Source

pub fn hours_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value hours before the given base time.

Source

pub fn days_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value days from the given base time.

Source

pub fn days_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value days before the given base time.

Source

pub fn weeks_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value weeks from the given base time.

Source

pub fn weeks_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value weeks before the given base time.

Source

pub fn months_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value months from the given base time.

Source

pub fn months_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value months before the given base time.

Source

pub fn years_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value years from the given base time.

Source

pub fn years_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value years before the given base time.

Source

pub fn decades_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value decades from the given base time.

Source

pub fn decades_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value decades before the given base time.

Source

pub fn centuries_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value centuries from the given base time.

Source

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

pub fn millenniums_from(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value millenniums from the given base time.

Source

pub fn millenniums_before(base: DateTime<Utc>, value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value millenniums before the given base time.

Source§

impl<F: TimeZone> EasyTime<F>

Source

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);
Source

pub fn utc_seconds_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value seconds in the past from now.

Source

pub fn utc_minutes_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value minutes in the future from now.

Source

pub fn utc_minutes_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value minutes in the past from now.

Source

pub fn utc_hours_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value hours in the future from now.

Source

pub fn utc_hours_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value hours in the past from now.

Source

pub fn utc_days_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value days in the future from now.

Source

pub fn utc_days_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value days in the past from now.

Source

pub fn utc_weeks_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value weeks in the future from now.

Source

pub fn utc_weeks_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value weeks in the past from now.

Source

pub fn utc_months_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value months in the future from now.

Source

pub fn utc_months_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value months in the past from now.

Source

pub fn utc_years_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value years in the future from now.

Source

pub fn utc_years_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value years in the past from now.

Source

pub fn utc_decades_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value decades in the future from now.

Source

pub fn utc_decades_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value decades in the past from now.

Source

pub fn utc_centuries_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value centuries in the future from now.

Source

pub fn utc_centuries_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value centuries in the past from now.

Source

pub fn utc_millenniums_from_now(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value millenniums in the future from now.

Source

pub fn utc_millenniums_ago(value: i64) -> DateTime<Utc>

Returns a UTC datetime that is value millenniums in the past from now.

Source

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));
Source

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

Trait Implementations§

Source§

impl<F: Clone + TimeZone> Clone for EasyTime<F>

Source§

fn clone(&self) -> EasyTime<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + TimeZone> Debug for EasyTime<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: PartialEq + TimeZone> PartialEq for EasyTime<F>

Source§

fn eq(&self, other: &EasyTime<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Eq + TimeZone> Eq for EasyTime<F>

Source§

impl<F: TimeZone> StructuralPartialEq for EasyTime<F>

Auto Trait Implementations§

§

impl<F> Freeze for EasyTime<F>

§

impl<F> RefUnwindSafe for EasyTime<F>
where F: RefUnwindSafe,

§

impl<F> Send for EasyTime<F>
where F: Send,

§

impl<F> Sync for EasyTime<F>
where F: Sync,

§

impl<F> Unpin for EasyTime<F>
where F: Unpin,

§

impl<F> UnwindSafe for EasyTime<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.