Struct DateTime
pub struct DateTime { /* private fields */ }
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.
Modern zip files store more precise timestamps; see crate::extra_fields::ExtendedTimestamp
for details.
Implementations
impl DateTime
const DEFAULT: Self = _;Constructs a default datetime of 1980-01-01 00:00:00.
fn default_for_write() -> SelfReturns the current time if possible, otherwise the default of 1980-01-01.
const unsafe fn from_msdos_unchecked(datepart: u16, timepart: u16) -> DateTimeConverts an msdos (u16, u16) pair to a
DateTimeobjectSafety
The caller must ensure the date and time are valid.
fn try_from_msdos(datepart: u16, timepart: u16) -> Result<DateTime, DateTimeRangeError>Converts an msdos (u16, u16) pair to a
DateTimeobject if it represents a valid date and time.fn from_date_and_time(year: u16, month: u8, day: u8, hour: u8, minute: u8, second: u8) -> Result<DateTime, DateTimeRangeError>Constructs a
DateTimefrom a specific date and timeThe bounds are:
- year: [1980, 2107]
- month: [1, 12]
- day: [1, 28..=31]
- hour: [0, 23]
- minute: [0, 59]
- second: [0, 60] (rounded down to even and to [0, 58] due to ZIP format limitation)
fn is_valid(&self) -> boolIndicates whether this date and time can be written to a zip archive.
const fn timepart(&self) -> u16Gets the time portion of this datetime in the msdos representation
const fn datepart(&self) -> u16Gets the date portion of this datetime in the msdos representation
const fn year(&self) -> u16Get the year. There is no epoch, i.e. 2018 will be returned as 2018.
const fn month(&self) -> u8Get the month, where 1 = january and 12 = december
Warning
When read from a zip file, this may not be a reasonable value
const fn day(&self) -> u8Get the day
Warning
When read from a zip file, this may not be a reasonable value
const fn hour(&self) -> u8Get the hour
Warning
When read from a zip file, this may not be a reasonable value
const fn minute(&self) -> u8Get the minute
Warning
When read from a zip file, this may not be a reasonable value
const fn second(&self) -> u8Get the second
Warning
When read from a zip file, this may not be a reasonable value
Trait Implementations
impl Clone for DateTime
fn clone(&self) -> Self
impl Copy for DateTime
impl Debug for DateTime
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for DateTime
fn default() -> DateTimeConstructs an 'default' datetime of 1980-01-01 00:00:00
impl Display for DateTime
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for DateTime
impl Hash for DateTime
fn hash<__H: Hasher>(&self, state: &mut __H)
impl Ord for DateTime
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for DateTime
fn eq(&self, other: &Self) -> bool
impl PartialOrd for DateTime
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl StructuralPartialEq for DateTime
impl TryFrom<(u16, u16)> for DateTime
type Error = DateTimeRangeError;fn try_from(values: (u16, u16)) -> Result<Self, Self::Error>
impl TryFrom<PlainDateTime> for DateTime
type Error = DateTimeRangeError;fn try_from(dt: PrimitiveDateTime) -> Result<Self, Self::Error>