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.
Modern zip files store more precise timestamps; see crate::extra_fields::ExtendedTimestamp
for details.
Implementations§
Source§impl DateTime
impl DateTime
Sourcepub fn default_for_write() -> Self
pub fn default_for_write() -> Self
Returns the current time if possible, otherwise the default of 1980-01-01.
Source§impl DateTime
impl DateTime
Sourcepub const unsafe fn from_msdos_unchecked(
datepart: u16,
timepart: u16,
) -> DateTime
pub const unsafe fn from_msdos_unchecked( datepart: u16, timepart: u16, ) -> DateTime
Converts an msdos (u16, u16) pair to a DateTime object
§Safety
The caller must ensure the date and time are valid.
Sourcepub fn try_from_msdos(
datepart: u16,
timepart: u16,
) -> Result<DateTime, DateTimeRangeError>
pub fn try_from_msdos( datepart: u16, timepart: u16, ) -> Result<DateTime, DateTimeRangeError>
Converts an msdos (u16, u16) pair to a DateTime object if it represents a valid date and time.
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, 28..=31]
- hour: [0, 23]
- minute: [0, 59]
- second: [0, 58]
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
Trait Implementations§
Source§impl Ord for DateTime
impl Ord for DateTime
Source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
impl Copy for DateTime
impl Eq for DateTime
impl StructuralPartialEq 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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.