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() -> Self

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

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.

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, 60] (rounded down to even and to [0, 58] due to ZIP format limitation)
fn is_valid(&self) -> bool

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

const fn timepart(&self) -> u16

Gets the time portion of this datetime in the msdos representation

const fn datepart(&self) -> u16

Gets the date portion of this datetime in the msdos representation

const fn year(&self) -> u16

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

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

const fn day(&self) -> u8

Get the day

Warning

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

const fn hour(&self) -> u8

Get the hour

Warning

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

const fn minute(&self) -> u8

Get the minute

Warning

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

const fn second(&self) -> u8

Get 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) -> DateTime

impl Copy for DateTime

impl Debug for DateTime

fn fmt(&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, 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: &DateTime) -> Ordering

impl PartialEq for DateTime

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

impl PartialOrd for DateTime

fn partial_cmp(&self, other: &DateTime) -> 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>

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

impl<Q, K> Comparable<K> for DateTime where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

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

impl<Q, K> Equivalent<K> for DateTime where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

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

impl<Q, K> Equivalent<K> for DateTime where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

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

impl<T> Any for DateTime where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for DateTime where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for DateTime where T: ?Sized,

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

impl<T> CloneToUninit for DateTime where T: Clone,

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

impl<T> From<T> for DateTime

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Same for DateTime

type Output = T;

impl<T> ToOwned for DateTime where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for DateTime where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T, U> Into<U> for DateTime where U: From<T>,

fn into(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<U> for DateTime where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for DateTime where U: TryFrom<T>,

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