Skip to main content

JsDate

Struct JsDate 

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

A JS Date: a millisecond time value, or None for an invalid date (JS NaN). Deliberately not Ord: compare get_time() values, so NaN comparisons stay explicit.

Implementations§

Source§

impl JsDate

Source

pub const INVALID: JsDate

new Date(NaN).

Source

pub fn from_millis(ms: i64) -> JsDate

new Date(ms).

Source

pub fn now() -> JsDate

new Date().

Source

pub fn local( year: i64, month: i64, day: i64, hour: i64, minute: i64, second: i64, ms: i64, ) -> JsDate

new Date(y, m, d, h, mi, s, ms) (local time = UTC here). Like JS, years 0–99 mean 1900–1999.

Source

pub fn utc( year: i64, month: i64, day: i64, hour: i64, minute: i64, second: i64, ms: i64, ) -> JsDate

Date.UTC(...). Same as JsDate::local because the system time zone is UTC.

Source

pub fn is_valid(&self) -> bool

Source

pub fn get_time(&self) -> Option<i64>

getTime(); None is JS NaN.

Source

pub fn get_full_year(&self) -> i64

Source

pub fn get_month(&self) -> i64

0-based, like JS.

Source

pub fn get_date(&self) -> i64

Source

pub fn get_day(&self) -> i64

0 = Sunday.

Source

pub fn get_hours(&self) -> i64

Source

pub fn get_minutes(&self) -> i64

Source

pub fn get_seconds(&self) -> i64

Source

pub fn get_milliseconds(&self) -> i64

Source

pub fn get_timezone_offset(&self) -> i64

Always 0: the system time zone is UTC.

Source

pub fn set_full_year(&mut self, year: i64)

setFullYear(y). Like JS, an invalid date is treated as time 0 first.

Source

pub fn set_month(&mut self, month: i64)

setMonth(m) (0-based). Keeps the day of month, so Jan 31 + 1 month overflows into March.

Source

pub fn set_date(&mut self, day: i64)

setDate(d).

Source

pub fn set_hours(&mut self, hour: i64)

Source

pub fn set_minutes(&mut self, minute: i64)

Source

pub fn set_seconds(&mut self, second: i64)

Source

pub fn set_milliseconds(&mut self, ms: i64)

Source

pub fn to_iso_string(&self) -> Option<String>

toISOString(). None where JS would throw (invalid date).

Source

pub fn parse_iso(s: &str) -> Option<JsDate>

Parses the toISOString() format (YYYY-MM-DDTHH:mm:ss.sssZ, or ±YYYYYY-...).

Trait Implementations§

Source§

impl Clone for JsDate

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for JsDate

Source§

impl Debug for JsDate

Source§

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

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

impl Eq for JsDate

Source§

impl From<JsDate> for ReferenceInput

Source§

fn from(date: JsDate) -> Self

Converts to this type from the input type.
Source§

impl Hash for JsDate

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 PartialEq for JsDate

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for JsDate

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.