1
0
mirror of https://github.com/bspeice/dtparse synced 2024-12-22 12:28:08 -05:00

Use Datetime<FixedOffset>

This commit is contained in:
Bradlee Speice 2018-05-24 22:28:06 -04:00
parent 205f75995e
commit ec41f11d98

View File

@ -1,7 +1,10 @@
#![allow(dead_code)]
extern crate chrono; extern crate chrono;
use chrono::DateTime; use chrono::DateTime;
use chrono::Datelike; use chrono::Datelike;
use chrono::FixedOffset;
use chrono::Local; use chrono::Local;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use chrono::NaiveTime; use chrono::NaiveTime;
@ -674,7 +677,7 @@ impl Parser {
default: Option<NaiveDateTime>, default: Option<NaiveDateTime>,
ignoretz: bool, ignoretz: bool,
tzinfos: Vec<String>, tzinfos: Vec<String>,
) -> Result<DateTime<Utc>, ParseError> { ) -> Result<DateTime<FixedOffset>, ParseError> {
let now = Local::now().naive_local(); let now = Local::now().naive_local();
let default_date = default.unwrap_or(now).date(); let default_date = default.unwrap_or(now).date();
@ -708,16 +711,17 @@ impl Parser {
dt: NaiveDateTime, dt: NaiveDateTime,
res: &ParsingResult, res: &ParsingResult,
default: NaiveDateTime, default: NaiveDateTime,
) -> DateTime<Utc> { ) -> DateTime<FixedOffset> {
Utc::now()
Local::now().with_timezone(&FixedOffset::east(0))
} }
} }
fn parse_with_info(timestr: String, info: ParserInfo) -> Result<DateTime<Utc>, ParseError> { fn parse_with_info(timestr: String, info: ParserInfo) -> Result<DateTime<FixedOffset>, ParseError> {
let parser = Parser::new(info); let parser = Parser::new(info);
parser.parse(timestr, None, false, vec![]) parser.parse(timestr, None, false, vec![])
} }
fn parse(timestr: String) -> Result<DateTime<Utc>, ParseError> { fn parse(timestr: String) -> Result<DateTime<FixedOffset>, ParseError> {
parse_with_info(timestr, ParserInfo::default()) parse_with_info(timestr, ParserInfo::default())
} }