aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Du <alanhdu@gmail.com>2017-05-30 23:31:32 +0100
committerAlan Du <alanhdu@gmail.com>2017-05-30 23:50:58 +0100
commita40a2cb389b97844e3ebd615f53273be0c004edd (patch)
tree15874362747d528faa14c1459a863383739a7095
parent7aa2594fb0ccd528087a492d1497f3af580bdb54 (diff)
downloadmilf-rs-a40a2cb389b97844e3ebd615f53273be0c004edd.tar.gz
milf-rs-a40a2cb389b97844e3ebd615f53273be0c004edd.zip
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
-rw-r--r--src/datetime.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/datetime.rs b/src/datetime.rs
index 7917cad..f39d9fa 100644
--- a/src/datetime.rs
+++ b/src/datetime.rs
@@ -55,7 +55,7 @@ struct Time {
hour: u8,
minute: u8,
second: u8,
- secfract: Option<f64>,
+ secfract: f64,
}
#[derive(PartialEq, Clone)]
@@ -97,8 +97,8 @@ impl fmt::Display for Date {
impl fmt::Display for Time {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:02}:{:02}:{:02}", self.hour, self.minute, self.second)?;
- if let Some(i) = self.secfract {
- let s = format!("{}", i);
+ if self.secfract != 0.0 {
+ let s = format!("{}", self.secfract);
write!(f, "{}", s.trim_left_matches("0"))?;
}
Ok(())
@@ -219,11 +219,11 @@ impl FromStr for Datetime {
}
chars = whole[end..].chars();
match format!("0.{}", &whole[..end]).parse() {
- Ok(f) => Some(f),
+ Ok(f) => f,
Err(_) => return Err(DatetimeParseError { _private: () }),
}
} else {
- None
+ 0.0
};
let time = Time {