Struct fastdate::DateTime

source ·
pub struct DateTime {
    pub nano: u32,
    pub sec: u8,
    pub min: u8,
    pub hour: u8,
    pub day: u8,
    pub mon: u8,
    pub year: u16,
}
Expand description

Log timestamp type.

Parse using FromStr impl. Format using the Display trait. Convert timestamp into/from SystemTime to use. Supports compare and sorting.

Fields§

§nano: u32

0…999999999

§sec: u8

0…59

§min: u8

0…59

§hour: u8

0…23

§day: u8

1…31

§mon: u8

1…12

§year: u16

0000…9999

Implementations§

source§

impl DateTime

source

pub fn utc() -> Self

utc time

source

pub fn now() -> Self

local zone time

source

pub fn set_offset(self, offset_sec: i32) -> DateTime

set offset

let mut  dt = fastdate::DateTime::utc();
dt = dt.set_offset(fastdate::offset_sec());
source

pub fn add(self, d: Duration) -> Self

add Duration

source

pub fn sub(self, d: Duration) -> Self

sub Duration

source

pub fn add_sub_sec(self, sec: i64) -> Self

add/sub sec

source

pub fn before(&self, other: &DateTime) -> bool

is self before on other?

source

pub fn after(&self, other: &DateTime) -> bool

is self after on other?

source

pub fn unix_timestamp(&self) -> i64

unix_timestamp sec

source

pub fn unix_timestamp_micros(&self) -> i64

unix_timestamp micros

source

pub fn unix_timestamp_millis(&self) -> i64

unix_timestamp millis

source

pub fn unix_timestamp_nano(&self) -> i128

unix_timestamp nano

source

pub fn from_timestamp(sec: i64) -> DateTime

from timestamp sec

source

pub fn from_timestamp_micros(micros: i64) -> DateTime

from timestamp micros

source

pub fn from_timestamp_millis(ms: i64) -> DateTime

from timestamp millis

source

pub fn from_timestamp_nano(nano: i128) -> DateTime

from timestamp nano

source

pub fn parse(format: &str, arg: &str) -> Result<DateTime, Error>

parse an string by format. format str must be:

 fastdate::DateTime::parse("YYYY-MM-DD hh:mm:ss.000000","2022-12-13 11:12:14.123456").unwrap();

or any position

 fastdate::DateTime::parse("hh:mm:ss.000000,YYYY-MM-DD","11:12:14.123456,2022-12-13").unwrap();
source

pub fn week_day(&self) -> u8

get week_day

source

pub fn set_nano(self, arg: u32) -> Self

0…999999999

source

pub fn get_nano(&self) -> u32

get nano 0…999999999

source

pub fn set_micro(self, arg: u32) -> Self

0…999999

source

pub fn set_sec(self, arg: u8) -> Self

0…59

source

pub fn set_min(self, arg: u8) -> Self

0…59

source

pub fn set_hour(self, arg: u8) -> Self

0…23

source

pub fn set_day(self, arg: u8) -> Self

1…31

source

pub fn set_mon(self, arg: u8) -> Self

1…12

source

pub fn set_year(self, arg: u16) -> Self

0000…9999

source

pub fn get_micro(&self) -> u32

get micro secs

source

pub fn get_sec(&self) -> u8

get sec

source

pub fn get_min(&self) -> u8

get sec

source

pub fn get_hour(&self) -> u8

get hour

source

pub fn get_day(&self) -> u8

get day

source

pub fn get_mon(&self) -> u8

get mon

source

pub fn get_year(&self) -> u16

get year

source§

impl DateTime

Trait Implementations§

source§

impl Add<&Duration> for DateTime

§

type Output = DateTime

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Duration) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Duration> for DateTime

§

type Output = DateTime

The resulting type after applying the + operator.
source§

fn add(self, rhs: Duration) -> Self::Output

Performs the + operation. Read more
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<'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

fmt RFC3339Nano = “2006-01-02T15:04:05.999999999”

source§

impl From<Date> for DateTime

source§

fn from(arg: Date) -> Self

Converts to this type from the input type.
source§

impl From<DateTime> for Date

source§

fn from(arg: DateTime) -> Self

Converts to this type from the input type.
source§

impl From<DateTime> for SystemTime

source§

fn from(v: DateTime) -> SystemTime

Converts to this type from the input type.
source§

impl From<DateTime> for Time

source§

fn from(arg: DateTime) -> Self

Converts to this type from the input type.
source§

impl From<SystemTime> for DateTime

source§

fn from(v: SystemTime) -> DateTime

Converts to this type from the input type.
source§

impl From<Time> for DateTime

source§

fn from(arg: Time) -> Self

Converts to this type from the input type.
source§

impl FromStr for DateTime

source§

fn from_str(s: &str) -> Result<DateTime, Error>

from RFC3339Nano = “0000-00-00 00:00:00.000000000”

§

type Err = Error

The associated error which can be returned from parsing.
source§

impl Hash for DateTime

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for DateTime

source§

fn cmp(&self, other: &DateTime) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<DateTime> for DateTime

source§

fn eq(&self, other: &DateTime) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<DateTime> 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

This method 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

This method 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

This method 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

This method 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 Sub<&Duration> for DateTime

§

type Output = DateTime

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Duration) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<DateTime> for DateTime

§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: DateTime) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Duration> for DateTime

§

type Output = DateTime

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Duration) -> Self::Output

Performs the - operation. Read more
source§

impl Eq for DateTime

source§

impl StructuralEq for DateTime

source§

impl StructuralPartialEq for DateTime

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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 Twhere T: for<'de> Deserialize<'de>,