sys_datetime

Struct Datetime

Source
pub struct Datetime { /* private fields */ }
Expand description

Datetime

§Example

let mut dt = Datetime::default();
dt.add_years(1970).add_months(1).add_days(1);
dt.add_seconds(Datetime::timestamp().as_secs() as i64);

let now = Datetime::now();

assert!(dt == now);

Implementations§

Source§

impl Datetime

Source

pub fn add_years(&mut self, years: i64) -> &mut Self

plus years

Source

pub fn add_months(&mut self, months: i64) -> &mut Self

plus months

Source

pub fn add_days(&mut self, days: i64) -> &mut Self

plus days

Source

pub fn add_hours(&mut self, hours: i64) -> &mut Self

plus hours

let mut dt = Datetime::now();
dt.add_hours(8);
println!("{}", dt);
Source

pub fn add_minutes(&mut self, minutes: i64) -> &mut Self

plus minutes

Source

pub fn add_seconds(&mut self, seconds: i64) -> &mut Self

plus seconds

Source

pub fn year(&self) -> i64

Source

pub fn month(&self) -> i64

Source

pub fn day(&self) -> i64

Source

pub fn hour(&self) -> i64

Source

pub fn minute(&self) -> i64

Source

pub fn second(&self) -> i64

Source

pub fn day_of_week(&self) -> &'static str

may be used to obtain the day of the week for dates on or after 0000-03-01

assert_eq!(
    Datetime::from_rfc3339("1970-01-01").unwrap().day_of_week(),
    "Thursday"
);
Source

pub fn seconds_since(&self, earlier: Datetime) -> i64

the number of seconds between two Datetime

assert_eq!(
    Datetime::now().seconds_since(Datetime::from_rfc3339("1970-01-01").unwrap()),
    Datetime::timestamp().as_secs() as i64
);
Source

pub fn from_str(dt: &str) -> Option<Self>

create from string

Source

pub fn from_rfc3339(rfc: &str) -> Option<Self>

create from rfc3339 string

assert_eq!(
    Datetime::from_rfc3339("2020-01-01 08:00:00+08:00")
        .unwrap()
        .to_string(),
    "2020-01-01 00:00:00"
);
Source

pub fn timestamp() -> Duration

current system timestamp

Source

pub fn now() -> Self

current time

Trait Implementations§

Source§

impl Clone for Datetime

Source§

fn clone(&self) -> Datetime

Returns a copy 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 Debug for Datetime

Source§

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

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

impl Default for Datetime

Source§

fn default() -> Datetime

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Datetime

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Datetime

Source§

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

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

impl PartialEq for Datetime

Source§

fn eq(&self, other: &Datetime) -> 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 PartialOrd for Datetime

Source§

fn partial_cmp(&self, other: &Datetime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Datetime

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Datetime

Source§

impl StructuralPartialEq for Datetime

Auto Trait Implementations§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,