diff options
| author | Botahamec <botahamec@outlook.com> | 2022-01-31 10:03:59 -0500 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2022-01-31 10:03:59 -0500 |
| commit | 81f29c5fd9e9ca7b59fe26c0d647890922c4bde2 (patch) | |
| tree | 53e7c45380b1134eeccb92a08ef61598f9add43a /src/date.rs | |
| parent | 2a057c1197d70d1d9b31a090c28dd7b929fdb6ae (diff) | |
Implemented default formatting
Diffstat (limited to 'src/date.rs')
| -rw-r--r-- | src/date.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/date.rs b/src/date.rs index ff1805b..49a7642 100644 --- a/src/date.rs +++ b/src/date.rs @@ -1,6 +1,7 @@ use crate::{Month, Year}; use core::cmp::Ordering; +use core::fmt::Display; #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct Date { @@ -91,3 +92,16 @@ impl Ord for Date { } // TODO addition + +impl Display for Date { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!( + f, + "{:0width$}-{:02}-{:02}", + self.year, + self.month as u8, + self.day, + width = 4 + (self.year() < 0.into()) as usize + ) + } +} |
