Store fraction of seconds in times unconditionally
This way, times without fractional seconds will be compare equal to times with 0 fractional seconds if all else is equal. For example, 06:00:00 == 06:00:00.0 Closes https://github.com/alexcrichton/toml-rs/issues/179
This commit is contained in:
parent
5170d66d51
commit
d375f4d63a
|
@ -55,7 +55,7 @@ struct Time {
|
||||||
hour: u8,
|
hour: u8,
|
||||||
minute: u8,
|
minute: u8,
|
||||||
second: u8,
|
second: u8,
|
||||||
secfract: Option<f64>,
|
secfract: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Clone)]
|
#[derive(PartialEq, Clone)]
|
||||||
|
@ -97,8 +97,8 @@ impl fmt::Display for Date {
|
||||||
impl fmt::Display for Time {
|
impl fmt::Display for Time {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{:02}:{:02}:{:02}", self.hour, self.minute, self.second)?;
|
write!(f, "{:02}:{:02}:{:02}", self.hour, self.minute, self.second)?;
|
||||||
if let Some(i) = self.secfract {
|
if self.secfract != 0.0 {
|
||||||
let s = format!("{}", i);
|
let s = format!("{}", self.secfract);
|
||||||
write!(f, "{}", s.trim_left_matches("0"))?;
|
write!(f, "{}", s.trim_left_matches("0"))?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -219,11 +219,11 @@ impl FromStr for Datetime {
|
||||||
}
|
}
|
||||||
chars = whole[end..].chars();
|
chars = whole[end..].chars();
|
||||||
match format!("0.{}", &whole[..end]).parse() {
|
match format!("0.{}", &whole[..end]).parse() {
|
||||||
Ok(f) => Some(f),
|
Ok(f) => f,
|
||||||
Err(_) => return Err(DatetimeParseError { _private: () }),
|
Err(_) => return Err(DatetimeParseError { _private: () }),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
0.0
|
||||||
};
|
};
|
||||||
|
|
||||||
let time = Time {
|
let time = Time {
|
||||||
|
|
Loading…
Reference in a new issue