KeyGenerationTime: remove formatted(); add to_datetime(); implement Display.

This commit is contained in:
Heiko Schaefer 2022-05-01 17:42:34 +02:00
parent 02b42081b9
commit b668aebaba
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D
2 changed files with 10 additions and 6 deletions

View file

@ -252,11 +252,15 @@ impl KeyGenerationTime {
self.0 self.0
} }
pub fn formatted(&self) -> String { pub fn to_datetime(&self) -> DateTime<Utc> {
let d = UNIX_EPOCH + Duration::from_secs(self.get() as u64); let d = UNIX_EPOCH + Duration::from_secs(self.get() as u64);
let datetime = DateTime::<Utc>::from(d); DateTime::<Utc>::from(d)
}
}
datetime.format("%Y-%m-%d %H:%M:%S").to_string() impl Display for KeyGenerationTime {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_datetime())
} }
} }

View file

@ -465,7 +465,7 @@ fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
println!(" fingerprint: {}", fp.to_spaced_hex()); println!(" fingerprint: {}", fp.to_spaced_hex());
} }
if let Some(kgt) = kgt.signature() { if let Some(kgt) = kgt.signature() {
println! {" created: {}", kgt.formatted()}; println! {" created: {}", kgt.to_datetime()};
} }
println! {" algorithm: {}", open.algorithm_attributes(KeyType::Signing)?}; println! {" algorithm: {}", open.algorithm_attributes(KeyType::Signing)?};
if verbose { if verbose {
@ -480,7 +480,7 @@ fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
println!(" fingerprint: {}", fp.to_spaced_hex()); println!(" fingerprint: {}", fp.to_spaced_hex());
} }
if let Some(kgt) = kgt.decryption() { if let Some(kgt) = kgt.decryption() {
println! {" created: {}", kgt.formatted()}; println! {" created: {}", kgt.to_datetime()};
} }
println! {" algorithm: {}", open.algorithm_attributes(KeyType::Decryption)?}; println! {" algorithm: {}", open.algorithm_attributes(KeyType::Decryption)?};
if verbose { if verbose {
@ -495,7 +495,7 @@ fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
println!(" fingerprint: {}", fp.to_spaced_hex()); println!(" fingerprint: {}", fp.to_spaced_hex());
} }
if let Some(kgt) = kgt.authentication() { if let Some(kgt) = kgt.authentication() {
println! {" created: {}", kgt.formatted()}; println! {" created: {}", kgt.to_datetime()};
} }
println! {" algorithm: {}", open.algorithm_attributes(KeyType::Authentication)?}; println! {" algorithm: {}", open.algorithm_attributes(KeyType::Authentication)?};
if verbose { if verbose {