mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39: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 s = value.as_str()?;
|
||||||
|
|
||||||
let fmt = if s.len() >= 11 && s.as_bytes()[10] == b'T' {
|
let fmt = if s.len() >= 11 && s.as_bytes()[10] == b'T' {
|
||||||
"%FT%T%.f%:z"
|
"%FT%T%.f%#z"
|
||||||
} else {
|
} else {
|
||||||
"%F %T%.f%:z"
|
"%F %T%.f%#z"
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(dt) = DateTime::parse_from_str(s, fmt) {
|
if let Ok(dt) = DateTime::parse_from_str(s, fmt) {
|
||||||
@ -127,7 +127,10 @@ impl FromSql for DateTime<Local> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::{Connection, Result};
|
use crate::{
|
||||||
|
types::{FromSql, ValueRef},
|
||||||
|
Connection, Result,
|
||||||
|
};
|
||||||
use chrono::{DateTime, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
|
use chrono::{DateTime, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
|
||||||
|
|
||||||
fn checked_memory_handle() -> Result<Connection> {
|
fn checked_memory_handle() -> Result<Connection> {
|
||||||
@ -261,4 +264,10 @@ mod test {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
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