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 fn from_msdos(datepart: u16, timepart: u16) -> DateTime
pub const 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 is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Indicates whether this date and time can be written to a zip archive.
sourcepub const fn timepart(&self) -> u16
pub const fn timepart(&self) -> u16
Gets the time portion of this datetime in the msdos representation
sourcepub const fn datepart(&self) -> u16
pub const fn datepart(&self) -> u16
Gets the date portion of this datetime in the msdos representation
sourcepub const fn year(&self) -> u16
pub const fn year(&self) -> u16
Get the year. There is no epoch, i.e. 2018 will be returned as 2018.
sourcepub const fn month(&self) -> u8
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