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
Available on crate feature time only.
pub fn default_for_write() -> Self
time only.Returns the current time if possible, otherwise the default of 1980-01-01.
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, 60] (rounded down to even and to [0, 58] due to ZIP format limitation)
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 Arbitrary<'_> for DateTime
Available on crate feature _arbitrary only.
impl Arbitrary<'_> for DateTime
_arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Ord for DateTime
impl Ord for DateTime
Source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
Source§impl TryFrom<DateTime> for NaiveDateTime
Available on crate feature chrono only.
impl TryFrom<DateTime> for NaiveDateTime
chrono only.Source§impl TryFrom<DateTime> for OffsetDateTime
Available on crate features time and deprecated-time only.
impl TryFrom<DateTime> for OffsetDateTime
time and deprecated-time only.Source§impl TryFrom<DateTime> for PrimitiveDateTime
Available on crate feature time only.
impl TryFrom<DateTime> for PrimitiveDateTime
time only.Source§impl TryFrom<NaiveDateTime> for DateTime
Available on crate feature chrono only.
impl TryFrom<NaiveDateTime> for DateTime
chrono only.Source§type Error = DateTimeRangeError
type Error = DateTimeRangeError
Source§impl TryFrom<OffsetDateTime> for DateTime
Available on crate features time and deprecated-time only.
impl TryFrom<OffsetDateTime> for DateTime
time and deprecated-time only.Source§type Error = DateTimeRangeError
type Error = DateTimeRangeError
Source§impl TryFrom<PrimitiveDateTime> for DateTime
Available on crate feature time only.
impl TryFrom<PrimitiveDateTime> for DateTime
time only.Source§type Error = DateTimeRangeError
type Error = DateTimeRangeError
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 UnsafeUnpin 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.