Skip to content

Commit 5220a4a

Browse files
committed
Improve printing the time part of interval
1 parent ace3958 commit 5220a4a

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<img alt="GitHub release" src="https://img.shields.io/github/v/release/amrdeveloper/gql">
1313
<img alt="GitHub issues" src="https://img.shields.io/github/issues/amrdeveloper/gql">
1414
<img alt="GitHub" src="https://img.shields.io/github/license/amrdeveloper/gql">
15+
<img all="Crates.io" src="https://img.shields.io/crates/d/gitql?label=Crates.io%20Downloads">
1516
<img alt="GitHub all releases" src="https://img.shields.io/github/downloads/amrdeveloper/gql/total">
1617
</p>
1718

@@ -57,7 +58,7 @@ SELECT * FROM commits
5758
SELECT author_name, author_email FROM commits
5859
SELECT author_name, author_email FROM commits ORDER BY author_name DESC, author_email ASC
5960
SELECT author_name, author_email FROM commits WHERE author_email LIKE "%gmail%" ORDER BY author_name
60-
SELECT * FROM commits WHERE LOWER(author_name) = "amrdeveloper"
61+
SELECT * FROM commits WHERE LOWER(author_name) = "AmrDeveloper"
6162
SELECT author_name FROM commits GROUP By author_name
6263
SELECT author_name FROM commits GROUP By author_name HAVING author_name = "AmrDeveloper"
6364

crates/gitql-ast/src/interval.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,16 @@ impl Display for Interval {
109109
));
110110
}
111111

112-
let mut time_parts = Vec::new();
113-
if self.hours != 0 {
114-
time_parts.push(format!("{}", self.hours));
115-
}
116-
if self.minutes != 0 {
117-
time_parts.push(format!("{}", self.minutes));
118-
}
119-
if self.seconds != 0.0 {
120-
time_parts.push(format!("{}", self.seconds));
121-
}
122-
123-
if !time_parts.is_empty() {
124-
parts.push(time_parts.join(":"));
112+
let (hours, minutes, seconds) = (self.hours, self.minutes, self.seconds);
113+
if hours != 0 || minutes != 0 || seconds != 0f64 {
114+
parts.push(format!("{:02}:{:02}:{:02}", hours, minutes, seconds));
125115
}
126116

127117
if parts.is_empty() {
128118
write!(f, "0 seconds")?;
129119
} else {
130120
write!(f, "{}", parts.join(" "))?;
131121
}
132-
133122
Ok(())
134123
}
135124
}

0 commit comments

Comments
 (0)