Skip to content

Commit

Permalink
Improve printing the time part of interval
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Jan 19, 2025
1 parent ace3958 commit 5220a4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<img alt="GitHub release" src="https://img.shields.io/github/v/release/amrdeveloper/gql">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/amrdeveloper/gql">
<img alt="GitHub" src="https://img.shields.io/github/license/amrdeveloper/gql">
<img all="Crates.io" src="https://img.shields.io/crates/d/gitql?label=Crates.io%20Downloads">
<img alt="GitHub all releases" src="https://img.shields.io/github/downloads/amrdeveloper/gql/total">
</p>

Expand Down Expand Up @@ -57,7 +58,7 @@ SELECT * FROM commits
SELECT author_name, author_email FROM commits
SELECT author_name, author_email FROM commits ORDER BY author_name DESC, author_email ASC
SELECT author_name, author_email FROM commits WHERE author_email LIKE "%gmail%" ORDER BY author_name
SELECT * FROM commits WHERE LOWER(author_name) = "amrdeveloper"
SELECT * FROM commits WHERE LOWER(author_name) = "AmrDeveloper"
SELECT author_name FROM commits GROUP By author_name
SELECT author_name FROM commits GROUP By author_name HAVING author_name = "AmrDeveloper"

Expand Down
17 changes: 3 additions & 14 deletions crates/gitql-ast/src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,16 @@ impl Display for Interval {
));
}

let mut time_parts = Vec::new();
if self.hours != 0 {
time_parts.push(format!("{}", self.hours));
}
if self.minutes != 0 {
time_parts.push(format!("{}", self.minutes));
}
if self.seconds != 0.0 {
time_parts.push(format!("{}", self.seconds));
}

if !time_parts.is_empty() {
parts.push(time_parts.join(":"));
let (hours, minutes, seconds) = (self.hours, self.minutes, self.seconds);
if hours != 0 || minutes != 0 || seconds != 0f64 {
parts.push(format!("{:02}:{:02}:{:02}", hours, minutes, seconds));
}

if parts.is_empty() {
write!(f, "0 seconds")?;
} else {
write!(f, "{}", parts.join(" "))?;
}

Ok(())
}
}
Expand Down

0 comments on commit 5220a4a

Please sign in to comment.