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
sourceimpl 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, ()>
pub fn from_time(dt: OffsetDateTime) -> Result<DateTime, ()>
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
impl Copy for DateTime
Auto Trait Implementations
impl RefUnwindSafe for DateTime
impl Send for DateTime
impl Sync for DateTime
impl Unpin for DateTime
impl UnwindSafe for DateTime
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more