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 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, ()>
pub fn from_date_and_time( year: u16, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<DateTime, ()>
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 from_time(dt: OffsetDateTime) -> Result<DateTime, ()>
👎Deprecated: use DateTime::try_from()
pub fn from_time(dt: OffsetDateTime) -> Result<DateTime, ()>
DateTime::try_from()Converts a OffsetDateTime object to a DateTime
Returns Err when this object is out of bounds
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) -> Result<OffsetDateTime, ComponentRange>
pub fn to_time(&self) -> Result<OffsetDateTime, ComponentRange>
Converts the DateTime to a OffsetDateTime structure
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
impl TryFrom<OffsetDateTime> for DateTime
Source§type Error = DateTimeRangeError
type Error = DateTimeRangeError
Source§fn try_from(
dt: OffsetDateTime,
) -> Result<DateTime, <DateTime as TryFrom<OffsetDateTime>>::Error>
fn try_from( dt: OffsetDateTime, ) -> Result<DateTime, <DateTime as TryFrom<OffsetDateTime>>::Error>
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