Struct DateTime

struct DateTime { ... }

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

unsafe const 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.

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.

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]
fn is_valid(self: &Self) -> bool

Indicates whether this date and time can be written to a zip archive.

fn from_time(dt: OffsetDateTime) -> Result<DateTime, DateTimeRangeError>

Converts a OffsetDateTime object to a DateTime

Returns Err when this object is out of bounds

const fn timepart(self: &Self) -> u16

Gets the time portion of this datetime in the msdos representation

const fn datepart(self: &Self) -> u16

Gets the date portion of this datetime in the msdos representation

fn to_time(self: &Self) -> Result<OffsetDateTime, ComponentRange>

Converts the DateTime to a OffsetDateTime structure

const fn year(self: &Self) -> u16

Get the year. There is no epoch, i.e. 2018 will be returned as 2018.

const fn month(self: &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

const fn day(self: &Self) -> u8

Get the day

Warning

When read from a zip file, this may not be a reasonable value

const fn hour(self: &Self) -> u8

Get the hour

Warning

When read from a zip file, this may not be a reasonable value

const fn minute(self: &Self) -> u8

Get the minute

Warning

When read from a zip file, this may not be a reasonable value

const fn second(self: &Self) -> u8

Get the second

Warning

When read from a zip file, this may not be a reasonable value

impl DateTime

fn default_for_write() -> Self

Returns the current time if possible, otherwise the default of 1980-01-01.

impl Clone for DateTime

fn clone(self: &Self) -> DateTime

impl Copy for DateTime

impl Debug for DateTime

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Default for DateTime

fn default() -> DateTime

Constructs an 'default' datetime of 1980-01-01 00:00:00

impl Display for DateTime

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Eq for DateTime

impl Freeze for DateTime

impl Hash for DateTime

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl Ord for DateTime

fn cmp(self: &Self, other: &Self) -> Ordering

impl PartialEq for DateTime

fn eq(self: &Self, other: &DateTime) -> bool

impl PartialOrd for DateTime

fn partial_cmp(self: &Self, other: &Self) -> Option<Ordering>

impl RefUnwindSafe for DateTime

impl Send for DateTime

impl StructuralPartialEq for DateTime

impl Sync for DateTime

impl TryFrom for DateTime

fn try_from(dt: OffsetDateTime) -> Result<Self, <Self as >::Error>

impl TryFrom for DateTime

fn try_from(values: (u16, u16)) -> Result<Self, <Self as >::Error>

impl TryFrom for DateTime

fn try_from(dt: PrimitiveDateTime) -> Result<Self, <Self as >::Error>

impl Unpin for DateTime

impl UnsafeUnpin for DateTime

impl UnwindSafe for DateTime

impl<Q, K> Comparable for DateTime

fn compare(self: &Self, key: &K) -> Ordering

impl<Q, K> Equivalent for DateTime

fn equivalent(self: &Self, key: &K) -> bool

impl<Q, K> Equivalent for DateTime

fn equivalent(self: &Self, key: &K) -> bool

impl<T> Any for DateTime

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for DateTime

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for DateTime

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for DateTime

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for DateTime

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Same for DateTime

impl<T> ToOwned for DateTime

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for DateTime

fn to_string(self: &Self) -> String

impl<T, U> Into for DateTime

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for DateTime

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for DateTime

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>