Struct DateTime

Source
pub struct DateTime {
    pub inner: OffsetDateTime,
}
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§

§inner: OffsetDateTime

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 format(&self, fmt: &str) -> String

format support token = [“YYYY”,“MM”,“DD”,“hh”,“mm”,“ss”,“.000000”,“.000000000”,“+00:00”]

let dt = fastdate::DateTime::from((
        fastdate::Date {
            day: 1,
            mon: 1,
            year: 2000,
        },
        fastdate::Time {
            nano: 123456000,
            sec: 11,
            minute: 1,
            hour: 1,
        })).set_offset(8 * 60 * 60);
  println!("{}",dt.format("YYYY-MM-DD hh:mm:ss"));
  println!("{}",dt.format("YYYY-MM-DD hh:mm:ss.000000"));
  println!("{}",dt.format("YYYY-MM-DD hh:mm:ss.000000+00:00"));
  println!("{}",dt.format("YYYY/MM/DD/hh/mm/ss/.000000/+00:00"));
  println!("{}",dt.format("YYYY-MM-DD/hh/mm/ss"));
Source

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

parse an string by format. format support token = [“YYYY”,“MM”,“DD”,“hh”,“mm”,“ss”,“.000000”,“+00:00”,“Z”] format str must be example: parse nano

 fastdate::DateTime::parse("YYYY-MM-DD hh:mm:ss.000000000Z", "2022-12-13 11:12:14.123456789Z").unwrap();
 fastdate::DateTime::parse("YYYY-MM-DD hh:mm:ss.000000000+00:00", "2022-12-13 11:12:14.123456789+06:00").unwrap();

or time zone(UTC+Hour)

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

or time zone(UTC)

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

parse local time

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

or any position

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

or time zone(UTC)

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

or time zone(UTC+Hour)

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

pub fn week_day(&self) -> u8

get week_day

Source

pub fn nano(&self) -> u32

Source

pub fn ms(&self) -> u16

Source

pub fn micro(&self) -> u32

get micro secs

Source

pub fn sec(&self) -> u8

get sec

Source

pub fn minute(&self) -> u8

minute

Source

pub fn hour(&self) -> u8

get hour

Source

pub fn day(&self) -> u8

get day

Source

pub fn mon(&self) -> u8

get mon

Source

pub fn year(&self) -> i32

get year

Source

pub fn offset(&self) -> i32

offset sec

Source

pub fn offset_hms(&self) -> (i8, i8, i8)

offset_hms: hour,minute,sec

Source

pub fn from_system_time(s: SystemTime, offset: i32) -> Self

Source

pub fn display_stand(&self) -> String

stand “0000-00-00 00:00:00.000000000”

Source

pub fn display(&self, zone: bool) -> String

RFC3339 “0000-00-00T00:00:00.000000000Z” RFC3339 “0000-00-00T00:00:00.000000000+00:00:00”

Source

pub fn do_display(&self, buf: &mut [u8; 38], add_zone: bool) -> usize

let mut buf: [u8; 38] = *b“0000-00-00T00:00:00.000000000+00:00:00“; than print this: RFC3339 “0000-00-00T00:00:00.000000000Z” RFC3339 “0000-00-00T00:00:00.000000000+00:00:00”

Source

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

Source

pub fn from_str_default( arg: &str, default_offset: i32, ) -> Result<DateTime, Error>

Trait Implementations§

Source§

impl Add<&Duration> for DateTime

Source§

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

Source§

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 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 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, Time)> for DateTime

Source§

fn from(arg: (Date, Time)) -> Self

Converts to this type from the input type.
Source§

impl From<(Date, Time, i32)> for DateTime

from(Date{},Time{},offset_sec())

Source§

fn from(arg: (Date, Time, i32)) -> Self

Converts to this type from the input type.
Source§

impl From<(Date, i32)> for DateTime

from((Date{},offset_sec()))

Source§

fn from(arg: (Date, i32)) -> Self

Converts to this type from the input type.
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(arg: &str) -> Result<DateTime, Error>

parse_from_str

“2019-10-12T07:20:50.52Z” (UTC+0) “2019-10-12T07:20:50.52+00:00” (UTC+0) “2019-10-12T14:20:50.52+07:00” (UTC+7) “2019-10-12T03:20:50.52-04:00” (UTC-4)

Source§

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) -> Self
where Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. 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 Sub<&Duration> for DateTime

Source§

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<Duration> for DateTime

Source§

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 for DateTime

Source§

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 Eq 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, 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> 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>,