Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}),
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/query/engine/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/repository/revision/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 5 additions & 4 deletions gix-date/src/time/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Format>) -> 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<Format>) -> String {
self.format_inner(format.into())
.unwrap_or_else(|_| self.seconds.to_string())
}

fn format_inner(&self, format: Format) -> Result<String, jiff::Error> {
Expand Down
20 changes: 13 additions & 7 deletions gix-date/tests/time/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion gix/src/repository/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion gix/src/revision/spec/parse/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}
Expand Down
Loading