MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / fmt

Method fmt

crates/gitql-ast/src/interval.rs:87–132  ·  view source on GitHub ↗
(&self, f: &mut Formatter<'_>)

Source from the content-addressed store, hash-verified

85
86impl Display for Interval {
87 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
88 let mut parts = Vec::new();
89
90 if self.years != 0 {
91 parts.push(format!(
92 "{} year{}",
93 self.years,
94 if self.years > 1 { "s" } else { "" }
95 ));
96 }
97 if self.months != 0 {
98 parts.push(format!(
99 "{} month{}",
100 self.months,
101 if self.months > 1 { "s" } else { "" }
102 ));
103 }
104 if self.days != 0 {
105 parts.push(format!(
106 "{} day{}",
107 self.days,
108 if self.days > 1 { "s" } else { "" }
109 ));
110 }
111
112 let (mut hours, mut minutes, mut seconds) = (self.hours, self.minutes, self.seconds);
113 if hours != 0 || minutes != 0 || seconds != 0f64 {
114 let has_minus_sign =
115 hours.is_negative() || minutes.is_negative() || seconds.is_sign_negative();
116 if has_minus_sign {
117 hours = hours.abs();
118 minutes = minutes.abs();
119 seconds = seconds.abs();
120 parts.push(format!("-{hours:02}:{minutes:02}:{seconds:02}"));
121 } else {
122 parts.push(format!("{hours:02}:{minutes:02}:{seconds:02}"));
123 }
124 }
125
126 if parts.is_empty() {
127 write!(f, "0 seconds")?;
128 } else {
129 write!(f, "{}", parts.join(" "))?;
130 }
131 Ok(())
132 }
133}
134
135fn interval_value_or_error_i64(value: i64) -> Result<i64, String> {

Callers

nothing calls this directly

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected