Struct zip::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 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 is_valid(&self) -> bool

Indicates whether this date and time can be written to a zip archive.

source

pub fn from_time(dt: OffsetDateTime) -> Result<DateTime, DateTimeRangeError>

👎Deprecated: use DateTime::try_from()

Converts a OffsetDateTime object to a DateTime

Returns Err when this object is out of bounds

source

pub const fn timepart(&self) -> u16

Gets the time portion of this datetime in the msdos representation

source

pub const fn datepart(&self) -> u16

Gets the date portion of this datetime in the msdos representation

source

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

Converts the DateTime to a OffsetDateTime structure

source

pub const fn year(&self) -> u16

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

source

pub const 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 const fn day(&self) -> u8

Get the day

§Warning

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

source

pub const fn hour(&self) -> u8

Get the hour

§Warning

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

source

pub const fn minute(&self) -> u8

Get the minute

§Warning

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

source

pub const 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

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

source§

impl TryFrom<OffsetDateTime> for DateTime

§

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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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.