Truncate fractional seconds to picoseconds
Close https://github.com/alexcrichton/toml-rs/issues/186
This commit is contained in:
parent
10d15333b4
commit
4e246b2142
|
@ -218,7 +218,10 @@ impl FromStr for Datetime {
|
||||||
return Err(DatetimeParseError { _private: () })
|
return Err(DatetimeParseError { _private: () })
|
||||||
}
|
}
|
||||||
chars = whole[end..].chars();
|
chars = whole[end..].chars();
|
||||||
match format!("0.{}", &whole[..end]).parse() {
|
|
||||||
|
// truncate to picoseconds precision
|
||||||
|
let last = if end > 12 { 12 } else { end };
|
||||||
|
match format!("0.{}", &whole[..last]).parse() {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(_) => return Err(DatetimeParseError { _private: () }),
|
Err(_) => return Err(DatetimeParseError { _private: () }),
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,9 @@ test!(example_bom,
|
||||||
include_str!("valid/example-bom.toml"),
|
include_str!("valid/example-bom.toml"),
|
||||||
include_str!("valid/example.json"));
|
include_str!("valid/example.json"));
|
||||||
|
|
||||||
|
test!(datetime_truncate,
|
||||||
|
include_str!("valid/datetime-truncate.toml"),
|
||||||
|
include_str!("valid/datetime-truncate.json"));
|
||||||
test!(table_array_nest_no_keys,
|
test!(table_array_nest_no_keys,
|
||||||
include_str!("valid/table-array-nest-no-keys.toml"),
|
include_str!("valid/table-array-nest-no-keys.toml"),
|
||||||
include_str!("valid/table-array-nest-no-keys.json"));
|
include_str!("valid/table-array-nest-no-keys.json"));
|
||||||
|
|
6
tests/valid/datetime-truncate.json
Normal file
6
tests/valid/datetime-truncate.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"bestdayever": {
|
||||||
|
"type": "datetime",
|
||||||
|
"value": "1987-07-05T17:45:00.123456789012Z"
|
||||||
|
}
|
||||||
|
}
|
1
tests/valid/datetime-truncate.toml
Normal file
1
tests/valid/datetime-truncate.toml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bestdayever = 1987-07-05T17:45:00.123456789012345Z
|
Loading…
Reference in a new issue