fix: decode postgres time without subsecond (#2784)

* fix: decode postgres time without subsecond

* update: decode postgres time without subsecond by making subsecond optional
This commit is contained in:
Yudai Fukushima 2023-10-05 08:56:14 +09:00 committed by GitHub
parent 4bac21da37
commit 846dcfe52a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -42,7 +42,8 @@ impl<'r> Decode<'r, Postgres> for Time {
PgValueFormat::Text => Time::parse(
value.as_str()?,
&format_description!("[hour]:[minute]:[second].[subsecond]"),
// Postgres will not include the subsecond part if it's zero.
&format_description!("[hour]:[minute]:[second][optional [.[subsecond]]]"),
)?,
})
}

View file

@ -321,7 +321,8 @@ mod time_tests {
test_type!(time_time<Time>(
Postgres,
"TIME '05:10:20.115100'" == time!(5:10:20.115100)
"TIME '05:10:20.115100'" == time!(5:10:20.115100),
"TIME '05:10:20'" == time!(5:10:20)
));
test_type!(time_date_time<PrimitiveDateTime>(