Struct scrypto::time::UtcDateTime
source · pub struct UtcDateTime {
year: u32,
month: u8,
day_of_month: u8,
hour: u8,
minute: u8,
second: u8,
}
Expand description
A UtcDateTime
represents a Unix timestamp on the UTC Calendar.
It can represent any date between 1-1-1 00:00:00
and [u32::MAX]-12-31 23:59:59
(inclusive).
In terms of indexing:
- Months and days of month are 1-based (i.e.
Dec 15th 2022
corresponds to2022-12-15
). - Hour, minute and second are 0-based, based on the 24-hour clock.
Midnight is represented as
00:00:00
and23:59:59
is the last second before midnight. Following Unix timstamp conventions, leap seconds are not supported.
UtcDateTime
supports methods for easy conversion to and from the Instant
type, which
can be queried from the Radix Engine.
Fields§
§year: u32
§month: u8
§day_of_month: u8
§hour: u8
§minute: u8
§second: u8
Implementations§
source§impl UtcDateTime
impl UtcDateTime
sourcepub fn new(
year: u32,
month: u8,
day_of_month: u8,
hour: u8,
minute: u8,
second: u8
) -> Result<UtcDateTime, DateTimeError>
pub fn new( year: u32, month: u8, day_of_month: u8, hour: u8, minute: u8, second: u8 ) -> Result<UtcDateTime, DateTimeError>
Creates a UtcDateTime
from its individual components.
Months and days of month are 1-based, with the following limits:
- Valid year range is:
1
tou32::MAX
inclusive. - Valid month values are:
1
to12
inclusive. - Valid day of month values are:
1
to{28, 29, 30, 31}
inclusive. The upper limit depends on the month and year, as per the Gregorian calendar.
An attempt to create an invalid date (e.g. 2022-04-31
or 2023-02-29
)
will result in a corresponding Err(DateTimeError)
.
Hour, minute and second constitute a 0-based 24-hour clock.
Midnight is represented as 00:00:00
and 23:59:59
is the maximum possible time (a second before midnight).
Following Unix time conventions, leap seconds are not represented in this system.
sourcepub fn from_instant(instant: &Instant) -> Result<UtcDateTime, DateTimeError>
pub fn from_instant(instant: &Instant) -> Result<UtcDateTime, DateTimeError>
Creates a UtcDateTime
from an Instant
.
The minimum supported seconds_since_unix_epoch
value is -62135596800
(corresponding to 1-1-1 00:00:00
)
and the maximum value is 135536014634284799
(corresponding to [u32::Max]-12-31 23:59:59
).
sourcepub fn to_instant(&self) -> Instant
pub fn to_instant(&self) -> Instant
Creates an Instant
from this UtcDateTime
pub fn year(&self) -> u32
pub fn month(&self) -> u8
pub fn day_of_month(&self) -> u8
pub fn hour(&self) -> u8
pub fn minute(&self) -> u8
pub fn second(&self) -> u8
pub fn add_days(&self, days_to_add: i64) -> Option<UtcDateTime>
pub fn add_hours(&self, hours_to_add: i64) -> Option<UtcDateTime>
pub fn add_minutes(&self, minutes_to_add: i64) -> Option<UtcDateTime>
pub fn add_seconds(&self, seconds_to_add: i64) -> Option<UtcDateTime>
Trait Implementations§
source§impl<X> Categorize<X> for UtcDateTimewhere
X: CustomValueKind,
impl<X> Categorize<X> for UtcDateTimewhere
X: CustomValueKind,
fn value_kind() -> ValueKind<X>
source§impl Clone for UtcDateTime
impl Clone for UtcDateTime
source§fn clone(&self) -> UtcDateTime
fn clone(&self) -> UtcDateTime
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for UtcDateTime
impl Debug for UtcDateTime
source§impl<D, X> Decode<X, D> for UtcDateTimewhere
D: Decoder<X>,
X: CustomValueKind,
impl<D, X> Decode<X, D> for UtcDateTimewhere
D: Decoder<X>,
X: CustomValueKind,
source§fn decode_body_with_value_kind(
decoder: &mut D,
value_kind: ValueKind<X>
) -> Result<UtcDateTime, DecodeError>
fn decode_body_with_value_kind( decoder: &mut D, value_kind: ValueKind<X> ) -> Result<UtcDateTime, DecodeError>
source§impl Describe<NoCustomTypeKind> for UtcDateTime
impl Describe<NoCustomTypeKind> for UtcDateTime
source§const TYPE_ID: RustTypeId = _
const TYPE_ID: RustTypeId = _
TYPE_ID
should give a unique identifier for its SBOR schema type.
An SBOR schema type capture details about the SBOR payload, how it should be interpreted, validated and displayed. Read moresource§fn type_data() -> TypeData<NoCustomTypeKind, RustTypeId>
fn type_data() -> TypeData<NoCustomTypeKind, RustTypeId>
source§fn add_all_dependencies(aggregator: &mut TypeAggregator<NoCustomTypeKind>)
fn add_all_dependencies(aggregator: &mut TypeAggregator<NoCustomTypeKind>)
get_local_type_data
, we need to ensure that the type and all of its own references
get added to the aggregator. Read moresource§impl Describe<ScryptoCustomTypeKind> for UtcDateTime
impl Describe<ScryptoCustomTypeKind> for UtcDateTime
source§const TYPE_ID: RustTypeId = _
const TYPE_ID: RustTypeId = _
TYPE_ID
should give a unique identifier for its SBOR schema type.
An SBOR schema type capture details about the SBOR payload, how it should be interpreted, validated and displayed. Read moresource§fn type_data() -> TypeData<ScryptoCustomTypeKind, RustTypeId>
fn type_data() -> TypeData<ScryptoCustomTypeKind, RustTypeId>
source§fn add_all_dependencies(aggregator: &mut TypeAggregator<C>)
fn add_all_dependencies(aggregator: &mut TypeAggregator<C>)
get_local_type_data
, we need to ensure that the type and all of its own references
get added to the aggregator. Read moresource§impl Display for UtcDateTime
impl Display for UtcDateTime
source§impl<E, X> Encode<X, E> for UtcDateTimewhere
E: Encoder<X>,
X: CustomValueKind,
impl<E, X> Encode<X, E> for UtcDateTimewhere
E: Encoder<X>,
X: CustomValueKind,
source§fn encode_value_kind(&self, encoder: &mut E) -> Result<(), EncodeError>
fn encode_value_kind(&self, encoder: &mut E) -> Result<(), EncodeError>
source§fn encode_body(&self, encoder: &mut E) -> Result<(), EncodeError>
fn encode_body(&self, encoder: &mut E) -> Result<(), EncodeError>
source§impl From<UtcDateTime> for Instant
impl From<UtcDateTime> for Instant
source§fn from(dt: UtcDateTime) -> Instant
fn from(dt: UtcDateTime) -> Instant
source§impl FromStr for UtcDateTime
impl FromStr for UtcDateTime
§type Err = ParseUtcDateTimeError
type Err = ParseUtcDateTimeError
source§fn from_str(s: &str) -> Result<UtcDateTime, <UtcDateTime as FromStr>::Err>
fn from_str(s: &str) -> Result<UtcDateTime, <UtcDateTime as FromStr>::Err>
s
to return a value of this type. Read moresource§impl PartialEq for UtcDateTime
impl PartialEq for UtcDateTime
source§fn eq(&self, other: &UtcDateTime) -> bool
fn eq(&self, other: &UtcDateTime) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<X> SborTuple<X> for UtcDateTimewhere
X: CustomValueKind,
impl<X> SborTuple<X> for UtcDateTimewhere
X: CustomValueKind,
fn get_length(&self) -> usize
source§impl TryFrom<Instant> for UtcDateTime
impl TryFrom<Instant> for UtcDateTime
§type Error = DateTimeError
type Error = DateTimeError
source§fn try_from(
instant: Instant
) -> Result<UtcDateTime, <UtcDateTime as TryFrom<Instant>>::Error>
fn try_from( instant: Instant ) -> Result<UtcDateTime, <UtcDateTime as TryFrom<Instant>>::Error>
impl Copy for UtcDateTime
impl Eq for UtcDateTime
impl StructuralPartialEq for UtcDateTime
Auto Trait Implementations§
impl RefUnwindSafe for UtcDateTime
impl Send for UtcDateTime
impl Sync for UtcDateTime
impl Unpin for UtcDateTime
impl UnwindSafe for UtcDateTime
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moresource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.