Struct PrimitiveDateTime
struct PrimitiveDateTime { ... }
Combined date and time.
Implementations
impl PrimitiveDateTime
const fn replace_time(self: Self, time: Time) -> SelfReplace the time, preserving the date.
# use ; assert_eq!;const fn replace_date(self: Self, date: Date) -> SelfReplace the date, preserving the time.
# use ; assert_eq!;const fn replace_year(self: Self, year: i32) -> Result<Self, ComponentRange>Replace the year. The month and day will be unchanged.
# use datetime; assert_eq!; assert!; // -1_000_000_000 isn't a valid year assert!; // 1_000_000_000 isn't a valid yearconst fn replace_month(self: Self, month: Month) -> Result<Self, ComponentRange>Replace the month of the year.
# use datetime; # use Month; assert_eq!; assert!; // 30 isn't a valid day in Februaryconst fn replace_day(self: Self, day: u8) -> Result<Self, ComponentRange>Replace the day of the month.
# use datetime; assert_eq!; assert!; // 00 isn't a valid day assert!; // 30 isn't a valid day in Februaryconst fn replace_ordinal(self: Self, ordinal: u16) -> Result<Self, ComponentRange>Replace the day of the year.
# use datetime; assert_eq!; assert!; // 0 isn't a valid ordinal assert!; // 2022 isn't a leap yearconst fn truncate_to_day(self: Self) -> SelfTruncate to the start of the day, setting the time to midnight.
# use datetime; assert_eq!;const fn replace_hour(self: Self, hour: u8) -> Result<Self, ComponentRange>Replace the clock hour.
# use datetime; assert_eq!; assert!; // 24 isn't a valid hourconst fn truncate_to_hour(self: Self) -> SelfTruncate to the hour, setting the minute, second, and subsecond components to zero.
# use datetime; assert_eq!;const fn replace_minute(self: Self, minute: u8) -> Result<Self, ComponentRange>Replace the minutes within the hour.
# use datetime; assert_eq!; assert!; // 60 isn't a valid minuteconst fn truncate_to_minute(self: Self) -> SelfTruncate to the minute, setting the second and subsecond components to zero.
# use datetime; assert_eq!;const fn replace_second(self: Self, second: u8) -> Result<Self, ComponentRange>Replace the seconds within the minute.
# use datetime; assert_eq!; assert!; // 60 isn't a valid secondconst fn truncate_to_second(self: Self) -> SelfTruncate to the second, setting the subsecond components to zero.
# use datetime; assert_eq!;const fn replace_millisecond(self: Self, millisecond: u16) -> Result<Self, ComponentRange>Replace the milliseconds within the second.
# use datetime; assert_eq!; assert!; // 1_000 isn't a valid millisecondconst fn truncate_to_millisecond(self: Self) -> SelfTruncate to the millisecond, setting the microsecond and nanosecond components to zero.
# use datetime; assert_eq!;const fn replace_microsecond(self: Self, microsecond: u32) -> Result<Self, ComponentRange>Replace the microseconds within the second.
# use datetime; assert_eq!; assert!; // 1_000_000 isn't a valid microsecondconst fn truncate_to_microsecond(self: Self) -> SelfTruncate to the microsecond, setting the nanosecond component to zero.
# use datetime; assert_eq!;const fn replace_nanosecond(self: Self, nanosecond: u32) -> Result<Self, ComponentRange>Replace the nanoseconds within the second.
# use datetime; assert_eq!; assert!; // 1_000_000_000 isn't a valid nanosecond
impl PrimitiveDateTime
const fn new(date: Date, time: Time) -> SelfCreate a new
PrimitiveDateTimefrom the providedDateandTime.# use PrimitiveDateTime; # use ; assert_eq!;const fn date(self: Self) -> DateGet the
Datecomponent of thePrimitiveDateTime.# use ; assert_eq!;const fn time(self: Self) -> TimeGet the
Timecomponent of thePrimitiveDateTime.# use ; assert_eq!;const fn year(self: Self) -> i32Get the year of the date.
# use datetime; assert_eq!; assert_eq!; assert_eq!;const fn month(self: Self) -> MonthGet the month of the date.
# use Month; # use datetime; assert_eq!; assert_eq!;const fn day(self: Self) -> u8Get the day of the date.
The returned value will always be in the range
1..=31.# use datetime; assert_eq!; assert_eq!;const fn ordinal(self: Self) -> u16Get the day of the year.
The returned value will always be in the range
1..=366(1..=365for common years).# use datetime; assert_eq!; assert_eq!;const fn iso_week(self: Self) -> u8Get the ISO week number.
The returned value will always be in the range
1..=53.# use datetime; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn sunday_based_week(self: Self) -> u8Get the week number where week 1 begins on the first Sunday.
The returned value will always be in the range
0..=53.# use datetime; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn monday_based_week(self: Self) -> u8Get the week number where week 1 begins on the first Monday.
The returned value will always be in the range
0..=53.# use datetime; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn to_calendar_date(self: Self) -> (i32, Month, u8)Get the year, month, and day.
# use Month; # use datetime; assert_eq!;const fn to_ordinal_date(self: Self) -> (i32, u16)Get the year and ordinal day number.
# use datetime; assert_eq!;const fn to_iso_week_date(self: Self) -> (i32, u8, Weekday)Get the ISO 8601 year, week number, and weekday.
# use *; # use datetime; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn weekday(self: Self) -> WeekdayGet the weekday.
# use *; # use datetime; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn to_julian_day(self: Self) -> i32Get the Julian day for the date. The time is not taken into account for this calculation.
# use datetime; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn as_hms(self: Self) -> (u8, u8, u8)Get the clock hour, minute, and second.
# use datetime; assert_eq!; assert_eq!;const fn as_hms_milli(self: Self) -> (u8, u8, u8, u16)Get the clock hour, minute, second, and millisecond.
# use datetime; assert_eq!; assert_eq!;const fn as_hms_micro(self: Self) -> (u8, u8, u8, u32)Get the clock hour, minute, second, and microsecond.
# use datetime; assert_eq!; assert_eq!;const fn as_hms_nano(self: Self) -> (u8, u8, u8, u32)Get the clock hour, minute, second, and nanosecond.
# use datetime; assert_eq!; assert_eq!;const fn hour(self: Self) -> u8Get the clock hour.
The returned value will always be in the range
0..24.# use datetime; assert_eq!; assert_eq!;const fn minute(self: Self) -> u8Get the minute within the hour.
The returned value will always be in the range
0..60.# use datetime; assert_eq!; assert_eq!;const fn second(self: Self) -> u8Get the second within the minute.
The returned value will always be in the range
0..60.# use datetime; assert_eq!; assert_eq!;const fn millisecond(self: Self) -> u16Get the milliseconds within the second.
The returned value will always be in the range
0..1_000.# use datetime; assert_eq!; assert_eq!;const fn microsecond(self: Self) -> u32Get the microseconds within the second.
The returned value will always be in the range
0..1_000_000.# use datetime; assert_eq!; assert_eq!;const fn nanosecond(self: Self) -> u32Get the nanoseconds within the second.
The returned value will always be in the range
0..1_000_000_000.# use datetime; assert_eq!; assert_eq!;const fn assume_offset(self: Self, offset: UtcOffset) -> OffsetDateTimeAssuming that the existing
PrimitiveDateTimerepresents a moment in the providedUtcOffset, return anOffsetDateTime.# use ; assert_eq!; assert_eq!;const fn assume_utc(self: Self) -> OffsetDateTimeAssuming that the existing
PrimitiveDateTimerepresents a moment in UTC, return anOffsetDateTime.# use datetime; assert_eq!;Note: You may want a
UtcDateTimeinstead, which can be obtained with thePrimitiveDateTime::as_utcmethod.const fn as_utc(self: Self) -> UtcDateTimeAssuming that the existing
PrimitiveDateTimerepresents a moment in UTC, return aUtcDateTime.# use datetime; assert_eq!;const fn checked_add(self: Self, duration: Duration) -> Option<Self>Computes
self + duration, returningNoneif an overflow occurred.# use ; # use datetime; let datetime = MIN.midnight; assert_eq!; let datetime = MAX.midnight; assert_eq!; assert_eq!;const fn checked_sub(self: Self, duration: Duration) -> Option<Self>Computes
self - duration, returningNoneif an overflow occurred.# use ; # use datetime; let datetime = MIN.midnight; assert_eq!; let datetime = MAX.midnight; assert_eq!; assert_eq!;const fn saturating_add(self: Self, duration: Duration) -> SelfComputes
self + duration, saturating value on overflow.# use ; # use datetime; assert_eq!; assert_eq!; assert_eq!;const fn saturating_sub(self: Self, duration: Duration) -> SelfComputes
self - duration, saturating value on overflow.# use ; # use datetime; assert_eq!; assert_eq!; assert_eq!;
impl Add for PrimitiveDateTime
fn add(self: Self, duration: Duration) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Add for PrimitiveDateTime
fn add(self: Self, duration: StdDuration) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl AddAssign for PrimitiveDateTime
fn add_assign(self: &mut Self, duration: Duration)Panics
This may panic if an overflow occurs.
impl AddAssign for PrimitiveDateTime
fn add_assign(self: &mut Self, duration: StdDuration)Panics
This may panic if an overflow occurs.
impl Clone for PrimitiveDateTime
fn clone(self: &Self) -> PrimitiveDateTime
impl Copy for PrimitiveDateTime
impl Debug for PrimitiveDateTime
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Display for PrimitiveDateTime
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Eq for PrimitiveDateTime
impl Freeze for PrimitiveDateTime
impl Hash for PrimitiveDateTime
fn hash<H>(self: &Self, state: &mut H) where H: Hasher
impl Ord for PrimitiveDateTime
fn cmp(self: &Self, other: &Self) -> Ordering
impl PartialEq for PrimitiveDateTime
fn eq(self: &Self, other: &Self) -> bool
impl PartialOrd for PrimitiveDateTime
fn partial_cmp(self: &Self, other: &Self) -> Option<Ordering>
impl RefUnwindSafe for PrimitiveDateTime
impl Send for PrimitiveDateTime
impl SmartDisplay for PrimitiveDateTime
fn metadata(self: &Self, _: FormatterOptions) -> Metadata<'_, Self>fn fmt_with_metadata(self: &Self, f: &mut Formatter<'_>, metadata: Metadata<'_, Self>) -> Result
impl Sub for PrimitiveDateTime
fn sub(self: Self, duration: StdDuration) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Sub for PrimitiveDateTime
fn sub(self: Self, rhs: Self) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl Sub for PrimitiveDateTime
fn sub(self: Self, duration: Duration) -> <Self as >::OutputPanics
This may panic if an overflow occurs.
impl SubAssign for PrimitiveDateTime
fn sub_assign(self: &mut Self, duration: Duration)Panics
This may panic if an overflow occurs.
impl SubAssign for PrimitiveDateTime
fn sub_assign(self: &mut Self, duration: StdDuration)Panics
This may panic if an overflow occurs.
impl Sync for PrimitiveDateTime
impl Unpin for PrimitiveDateTime
impl UnsafeUnpin for PrimitiveDateTime
impl UnwindSafe for PrimitiveDateTime
impl<T> Any for PrimitiveDateTime
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for PrimitiveDateTime
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for PrimitiveDateTime
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for PrimitiveDateTime
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for PrimitiveDateTime
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for PrimitiveDateTime
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for PrimitiveDateTime
fn to_string(self: &Self) -> String
impl<T, U> Into for PrimitiveDateTime
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for PrimitiveDateTime
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for PrimitiveDateTime
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>