pub struct Date(/* private fields */);Expand description
Date is a type that represents the MS-DOS date.
This is a packed 16-bit unsigned integer value that specify the date an MS-DOS file was last written to, and is used as timestamps such as FAT or ZIP file format.
See the format specification for Kaitai Struct for more details on the structure of the MS-DOS date.
Implementations§
Source§impl Date
impl Date
Source§impl Date
impl Date
Sourcepub fn new(date: u16) -> Option<Self>
pub fn new(date: u16) -> Option<Self>
Creates a new Date with the given MS-DOS date.
Returns None if the given MS-DOS date is not a valid MS-DOS date.
§Examples
assert_eq!(Date::new(0b0000_0000_0010_0001), Some(Date::MIN));
assert_eq!(Date::new(0b1111_1111_1001_1111), Some(Date::MAX));
// The Day field is 0.
assert_eq!(Date::new(0b0000_0000_0010_0000), None);Sourcepub const unsafe fn new_unchecked(date: u16) -> Self
pub const unsafe fn new_unchecked(date: u16) -> Self
Sourcepub fn from_date(date: Date) -> Result<Self, DateRangeError>
pub fn from_date(date: Date) -> Result<Self, DateRangeError>
Creates a new Date with the given time::Date.
§Errors
Returns Err if date is an invalid as the MS-DOS date.
§Examples
assert_eq!(Date::from_date(date!(1980-01-01)), Ok(Date::MIN));
assert_eq!(Date::from_date(date!(2107-12-31)), Ok(Date::MAX));
// Before `1980-01-01`.
assert!(Date::from_date(date!(1979-12-31)).is_err());
// After `2107-12-31`.
assert!(Date::from_date(date!(2108-01-01)).is_err());Sourcepub const fn year(self) -> u16
pub const fn year(self) -> u16
Gets the year of this Date.
§Examples
assert_eq!(Date::MIN.year(), 1980);
assert_eq!(Date::MAX.year(), 2107);Trait Implementations§
Source§impl Ord for Date
impl Ord for Date
Source§impl PartialOrd for Date
impl PartialOrd for Date
Source§impl TryFrom<Date> for Date
impl TryFrom<Date> for Date
Source§fn try_from(date: Date) -> Result<Self, Self::Error>
fn try_from(date: Date) -> Result<Self, Self::Error>
Converts a time::Date to a Date.
§Errors
Returns Err if date is out of range for the MS-DOS date.
§Examples
assert_eq!(Date::try_from(date!(1980-01-01)), Ok(Date::MIN));
assert_eq!(Date::try_from(date!(2107-12-31)), Ok(Date::MAX));
// Before `1980-01-01`.
assert!(Date::try_from(date!(1979-12-31)).is_err());
// After `2107-12-31`.
assert!(Date::try_from(date!(2108-01-01)).is_err());Source§type Error = DateRangeError
type Error = DateRangeError
Source§impl TryFrom<Date> for Date
Available on crate feature jiff only.
impl TryFrom<Date> for Date
jiff only.Source§fn try_from(date: Date) -> Result<Self, Self::Error>
fn try_from(date: Date) -> Result<Self, Self::Error>
Converts a civil::Date to a Date.
§Errors
Returns Err if date is out of range for the MS-DOS date.
§Examples
assert_eq!(Date::try_from(civil::date(1980, 1, 1)), Ok(Date::MIN));
assert_eq!(Date::try_from(civil::date(2107, 12, 31)), Ok(Date::MAX));
// Before `1980-01-01`.
assert!(Date::try_from(civil::date(1979, 12, 31)).is_err());
// After `2107-12-31`.
assert!(Date::try_from(civil::date(2108, 1, 1)).is_err());Source§type Error = DateRangeError
type Error = DateRangeError
Source§impl TryFrom<NaiveDate> for Date
Available on crate feature chrono only.
impl TryFrom<NaiveDate> for Date
chrono only.Source§fn try_from(date: NaiveDate) -> Result<Self, Self::Error>
fn try_from(date: NaiveDate) -> Result<Self, Self::Error>
Converts a NaiveDate to a Date.
§Errors
Returns Err if date is out of range for the MS-DOS date.
§Examples
assert_eq!(
Date::try_from("1980-01-01".parse::<NaiveDate>().unwrap()),
Ok(Date::MIN)
);
assert_eq!(
Date::try_from("2107-12-31".parse::<NaiveDate>().unwrap()),
Ok(Date::MAX)
);
// Before `1980-01-01`.
assert!(Date::try_from("1979-12-31".parse::<NaiveDate>().unwrap()).is_err());
// After `2107-12-31`.
assert!(Date::try_from("2108-01-01".parse::<NaiveDate>().unwrap()).is_err());Source§type Error = DateRangeError
type Error = DateRangeError
impl Copy for Date
impl Eq for Date
impl StructuralPartialEq for Date
Auto Trait Implementations§
impl Freeze for Date
impl RefUnwindSafe for Date
impl Send for Date
impl Sync for Date
impl Unpin for Date
impl UnwindSafe for Date
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)