mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 16:29:20 +08:00
Leniently parse rfc3339 timezones (#928)
This commit is contained in:
parent
ed3bfbdf9d
commit
ecbc0aa767
@ -101,9 +101,9 @@ impl FromSql for DateTime<Utc> {
|
||||
let s = value.as_str()?;
|
||||
|
||||
let fmt = if s.len() >= 11 && s.as_bytes()[10] == b'T' {
|
||||
"%FT%T%.f%:z"
|
||||
"%FT%T%.f%#z"
|
||||
} else {
|
||||
"%F %T%.f%:z"
|
||||
"%F %T%.f%#z"
|
||||
};
|
||||
|
||||
if let Ok(dt) = DateTime::parse_from_str(s, fmt) {
|
||||
@ -127,7 +127,10 @@ impl FromSql for DateTime<Local> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{Connection, Result};
|
||||
use crate::{
|
||||
types::{FromSql, ValueRef},
|
||||
Connection, Result,
|
||||
};
|
||||
use chrono::{DateTime, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
|
||||
|
||||
fn checked_memory_handle() -> Result<Connection> {
|
||||
@ -261,4 +264,10 @@ mod test {
|
||||
assert!(result.is_ok());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lenient_parse_timezone() {
|
||||
assert!(DateTime::<Utc>::column_result(ValueRef::Text(b"1970-01-01T00:00:00Z")).is_ok());
|
||||
assert!(DateTime::<Utc>::column_result(ValueRef::Text(b"1970-01-01T00:00:00+00")).is_ok());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user