diff --git a/examples/log.rs b/examples/log.rs index 76a651e3171..293d358529e 100644 --- a/examples/log.rs +++ b/examples/log.rs @@ -150,7 +150,7 @@ fn run(args: Args) -> anyhow::Result<()> { commit_ref.author.actor().write_to(&mut buf)?; buf.into() }, - time: commit_ref.author.time()?.format_or_raw(format::DEFAULT), + time: commit_ref.author.time()?.format_or_unix(format::DEFAULT), message: commit_ref.message.to_owned(), }) }), diff --git a/gitoxide-core/src/query/engine/command.rs b/gitoxide-core/src/query/engine/command.rs index ef3e6f85414..05bdc48a024 100644 --- a/gitoxide-core/src/query/engine/command.rs +++ b/gitoxide-core/src/query/engine/command.rs @@ -180,7 +180,7 @@ mod trace_path { out, "{}| {} | {} {} {} ➡ {}", self.diff.unwrap_or_default().format(max_diff_lines), - self.commit_time.format_or_raw(gix::date::time::format::SHORT), + self.commit_time.format_or_unix(gix::date::time::format::SHORT), id.shorten_or_id(), self.mode.as_str(), path_by_id[&source_id], @@ -192,7 +192,7 @@ mod trace_path { out, "{}| {} | {} {} {}", self.diff.unwrap_or_default().format(max_diff_lines), - self.commit_time.format_or_raw(gix::date::time::format::SHORT), + self.commit_time.format_or_unix(gix::date::time::format::SHORT), id.shorten_or_id(), self.mode.as_str(), path_by_id[&self.file_id] diff --git a/gitoxide-core/src/repository/revision/explain.rs b/gitoxide-core/src/repository/revision/explain.rs index ecc75c47d3f..45e67427b48 100644 --- a/gitoxide-core/src/repository/revision/explain.rs +++ b/gitoxide-core/src/repository/revision/explain.rs @@ -88,7 +88,7 @@ impl delegate::Revision for Explain<'_> { ReflogLookup::Date(time) => writeln!( self.out, "Find entry closest to time {} in reflog of '{}' reference", - time.format_or_raw(gix::date::time::format::ISO8601), + time.format_or_unix(gix::date::time::format::ISO8601), ref_name ) .ok(), diff --git a/gix-date/src/time/format.rs b/gix-date/src/time/format.rs index 552c143018f..b318f129366 100644 --- a/gix-date/src/time/format.rs +++ b/gix-date/src/time/format.rs @@ -42,10 +42,11 @@ impl Time { self.format_inner(format.into()) } - /// Like [`Self::format()`], but on time conversion error, produce the [RAW] format instead to make it - /// infallible. - pub fn format_or_raw(&self, format: impl Into) -> String { - self.format_inner(format.into()).unwrap_or_else(|_| self.to_string()) + /// Like [`Self::format()`], but on time conversion error, produce the [UNIX] format instead + /// to make it infallible. + pub fn format_or_unix(&self, format: impl Into) -> String { + self.format_inner(format.into()) + .unwrap_or_else(|_| self.seconds.to_string()) } fn format_inner(&self, format: Format) -> Result { diff --git a/gix-date/tests/time/format.rs b/gix-date/tests/time/format.rs index d5376aa19ec..2713eb78757 100644 --- a/gix-date/tests/time/format.rs +++ b/gix-date/tests/time/format.rs @@ -66,15 +66,21 @@ fn git_rfc2822() -> gix_testtools::Result { #[test] fn default() -> gix_testtools::Result { + assert_eq!(time().format(format::GITOXIDE)?, "Fri Nov 30 1973 00:03:09 +0230"); + assert_eq!(time_dec1().format(format::GITOXIDE)?, "Sat Dec 01 1973 00:03:09 +0230"); + Ok(()) +} + +#[test] +fn format_or_unix() { assert_eq!( - time().format(gix_date::time::format::GITOXIDE)?, - "Fri Nov 30 1973 00:03:09 +0230" - ); - assert_eq!( - time_dec1().format(gix_date::time::format::GITOXIDE)?, - "Sat Dec 01 1973 00:03:09 +0230" + Time { + seconds: 42, + offset: 7200 * 60 + } + .format_or_unix(format::GITOXIDE), + "42" ); - Ok(()) } #[test] diff --git a/gix/src/repository/identity.rs b/gix/src/repository/identity.rs index 212fe78b4b3..ea9f3a506c4 100644 --- a/gix/src/repository/identity.rs +++ b/gix/src/repository/identity.rs @@ -140,7 +140,7 @@ impl Personas { .and_then(|date| gix_date::parse(date, Some(SystemTime::now())).ok()) }) .or_else(|| Some(gix_date::Time::now_local_or_utc())) - .map(|time| time.format_or_raw(gix_date::time::Format::Raw)) + .map(|time| time.format_or_unix(gix_date::time::Format::Raw)) }; let fallback = ( diff --git a/gix/src/revision/spec/parse/error.rs b/gix/src/revision/spec/parse/error.rs index 513b3e886e2..7e043386110 100644 --- a/gix/src/revision/spec/parse/error.rs +++ b/gix/src/revision/spec/parse/error.rs @@ -44,7 +44,7 @@ impl std::fmt::Display for CandidateInfo { "commit {} {title:?}", gix_date::parse_header(date) .unwrap_or_default() - .format_or_raw(gix_date::time::format::SHORT) + .format_or_unix(gix_date::time::format::SHORT) ) } }