feat: Add fmt::Display
for DateTime
This commit is contained in:
parent
00be854b11
commit
e3b12e313e
1 changed files with 33 additions and 0 deletions
33
src/types.rs
33
src/types.rs
|
@ -1,5 +1,6 @@
|
|||
//! Types that specify what is contained in a ZIP.
|
||||
use path::{Component, Path, PathBuf};
|
||||
use std::fmt;
|
||||
use std::path;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
|
@ -135,6 +136,17 @@ impl Default for DateTime {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DateTime {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
|
||||
self.year, self.month, self.day, self.hour, self.minute, self.second
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl DateTime {
|
||||
/// Converts an msdos (u16, u16) pair to a DateTime object
|
||||
pub const fn from_msdos(datepart: u16, timepart: u16) -> DateTime {
|
||||
|
@ -649,6 +661,27 @@ mod test {
|
|||
assert!(dt > DateTime::from_date_and_time(2018, 11, 17, 10, 38, 29).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn datetime_display() {
|
||||
use super::DateTime;
|
||||
|
||||
assert_eq!(format!("{}", DateTime::default()), "1980-01-01 00:00:00");
|
||||
assert_eq!(
|
||||
format!(
|
||||
"{}",
|
||||
DateTime::from_date_and_time(2018, 11, 17, 10, 38, 30).unwrap()
|
||||
),
|
||||
"2018-11-17 10:38:30"
|
||||
);
|
||||
assert_eq!(
|
||||
format!(
|
||||
"{}",
|
||||
DateTime::from_date_and_time(2107, 12, 31, 23, 59, 59).unwrap()
|
||||
),
|
||||
"2107-12-31 23:59:59"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn datetime_bounds() {
|
||||
use super::DateTime;
|
||||
|
|
Loading…
Add table
Reference in a new issue