Struct DateTime

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

Representation of a moment in time.

Zip files use an old format from DOS to store timestamps, with its own set of peculiarities. For example, it has a resolution of 2 seconds!

A DateTime can be stored directly in a zipfile with FileOptions::last_modified_time, or read from one with ZipFile::last_modified

§Warning

Because there is no timezone associated with the DateTime, they should ideally only be used for user-facing descriptions. This also means DateTime::to_time returns an OffsetDateTime (which is the equivalent of chrono’s NaiveDateTime).

Modern zip files store more precise timestamps, which are ignored by crate::read::ZipArchive, so keep in mind that these timestamps are unreliable. We’re working on this.

Implementations§

Source§

impl DateTime

Source

pub const YEAR_RANGE: RangeInclusive<u16>

The allowed range for years in a zip file’s timestamp.

Source

pub const MONTH_RANGE: RangeInclusive<u8>

The allowed range for months in a zip file’s timestamp.

Source

pub const DAY_RANGE: RangeInclusive<u8>

The allowed range for days in a zip file’s timestamp.

Source

pub const HOUR_RANGE: Range<u8>

The allowed range for hours in a zip file’s timestamp.

Source

pub const MINUTE_RANGE: Range<u8>

The allowed range for minutes in a zip file’s timestamp.

Source

pub const SECOND_RANGE: RangeInclusive<u8>

The allowed range for seconds in a zip file’s timestamp.

Source

pub const fn zero() -> Self

Constructs a ‘default’ datetime of 1980-01-01 00:00:00

Source

pub fn from_msdos(datepart: u16, timepart: u16) -> DateTime

Converts an msdos (u16, u16) pair to a DateTime object

Source

pub fn from_date_and_time( year: u16, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime, DateTimeRangeError>

Constructs a DateTime from a specific date and time

The bounds are:

  • year: [1980, 2107]
  • month: [1, 12]
  • day: [1, 31]
  • hour: [0, 23]
  • minute: [0, 59]
  • second: [0, 60]
Source

pub fn timepart(&self) -> u16

Gets the time portion of this datetime in the msdos representation

Source

pub fn datepart(&self) -> u16

Gets the date portion of this datetime in the msdos representation

Source

pub fn to_time( &self, offset: UtcOffset, ) -> Result<OffsetDateTime, ComponentRange>

Available on crate feature time only.

Converts the DateTime to a OffsetDateTime structure, given a UTC offset.

Source

pub fn year(&self) -> u16

Get the year. There is no epoch, i.e. 2018 will be returned as 2018.

Source

pub fn month(&self) -> u8

Get the month, where 1 = january and 12 = december

§Warning

When read from a zip file, this may not be a reasonable value

Source

pub fn day(&self) -> u8

Get the day

§Warning

When read from a zip file, this may not be a reasonable value

Source

pub fn hour(&self) -> u8

Get the hour

§Warning

When read from a zip file, this may not be a reasonable value

Source

pub fn minute(&self) -> u8

Get the minute

§Warning

When read from a zip file, this may not be a reasonable value

Source

pub fn second(&self) -> u8

Get the second

§Warning

When read from a zip file, this may not be a reasonable value

Trait Implementations§

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

Source§

fn default() -> DateTime

Returns the “default value” for a type. Read more
Source§

impl TryFrom<OffsetDateTime> for DateTime

Available on crate feature time only.
Source§

type Error = DateTimeRangeError

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

fn try_from(dt: OffsetDateTime) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = 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.