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
impl DateTime
Sourcepub const YEAR_RANGE: RangeInclusive<u16>
pub const YEAR_RANGE: RangeInclusive<u16>
The allowed range for years in a zip file’s timestamp.
Sourcepub const MONTH_RANGE: RangeInclusive<u8>
pub const MONTH_RANGE: RangeInclusive<u8>
The allowed range for months in a zip file’s timestamp.
Sourcepub const DAY_RANGE: RangeInclusive<u8>
pub const DAY_RANGE: RangeInclusive<u8>
The allowed range for days in a zip file’s timestamp.
Sourcepub const HOUR_RANGE: Range<u8>
pub const HOUR_RANGE: Range<u8>
The allowed range for hours in a zip file’s timestamp.
Sourcepub const MINUTE_RANGE: Range<u8>
pub const MINUTE_RANGE: Range<u8>
The allowed range for minutes in a zip file’s timestamp.
Sourcepub const SECOND_RANGE: RangeInclusive<u8>
pub const SECOND_RANGE: RangeInclusive<u8>
The allowed range for seconds in a zip file’s timestamp.
Sourcepub fn from_msdos(datepart: u16, timepart: u16) -> DateTime
pub fn from_msdos(datepart: u16, timepart: u16) -> DateTime
Converts an msdos (u16, u16) pair to a DateTime object
Sourcepub fn from_date_and_time(
year: u16,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime, DateTimeRangeError>
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]
Sourcepub fn timepart(&self) -> u16
pub fn timepart(&self) -> u16
Gets the time portion of this datetime in the msdos representation
Sourcepub fn datepart(&self) -> u16
pub fn datepart(&self) -> u16
Gets the date portion of this datetime in the msdos representation
Sourcepub fn to_time(
&self,
offset: UtcOffset,
) -> Result<OffsetDateTime, ComponentRange>
Available on crate feature time
only.
pub fn to_time( &self, offset: UtcOffset, ) -> Result<OffsetDateTime, ComponentRange>
time
only.Converts the DateTime to a OffsetDateTime structure, given a UTC offset.
Sourcepub fn month(&self) -> u8
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
Trait Implementations§
Source§impl TryFrom<OffsetDateTime> for DateTime
Available on crate feature time
only.
impl TryFrom<OffsetDateTime> for DateTime
time
only.Source§type Error = DateTimeRangeError
type Error = DateTimeRangeError
impl Copy for DateTime
Auto Trait Implementations§
impl Freeze for DateTime
impl RefUnwindSafe for DateTime
impl Send for DateTime
impl Sync for DateTime
impl Unpin for DateTime
impl UnwindSafe for DateTime
Blanket Implementations§
Source§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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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