commit
e308e8e929
|
@ -86,7 +86,7 @@ fn parse_rfc2822<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult<(&'a st
|
||||||
s = s.trim_left();
|
s = s.trim_left();
|
||||||
|
|
||||||
if let Ok((s_, weekday)) = scan::short_weekday(s) {
|
if let Ok((s_, weekday)) = scan::short_weekday(s) {
|
||||||
if !s_.starts_with(",") { return Err(INVALID); }
|
if !s_.starts_with(',') { return Err(INVALID); }
|
||||||
s = &s_[1..];
|
s = &s_[1..];
|
||||||
try!(parsed.set_weekday(weekday));
|
try!(parsed.set_weekday(weekday));
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ fn parse_rfc3339<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult<(&'a st
|
||||||
try!(parsed.set_minute(try_consume!(scan::number(s, 2, 2))));
|
try!(parsed.set_minute(try_consume!(scan::number(s, 2, 2))));
|
||||||
s = try!(scan::char(s, b':'));
|
s = try!(scan::char(s, b':'));
|
||||||
try!(parsed.set_second(try_consume!(scan::number(s, 2, 2))));
|
try!(parsed.set_second(try_consume!(scan::number(s, 2, 2))));
|
||||||
if s.starts_with(".") {
|
if s.starts_with('.') {
|
||||||
let nanosecond = try_consume!(scan::nanosecond(&s[1..]));
|
let nanosecond = try_consume!(scan::nanosecond(&s[1..]));
|
||||||
try!(parsed.set_nanosecond(nanosecond));
|
try!(parsed.set_nanosecond(nanosecond));
|
||||||
}
|
}
|
||||||
|
@ -252,10 +252,10 @@ pub fn parse<'a, I>(parsed: &mut Parsed, mut s: &str, items: I) -> ParseResult<(
|
||||||
|
|
||||||
s = s.trim_left();
|
s = s.trim_left();
|
||||||
let v = if signed {
|
let v = if signed {
|
||||||
if s.starts_with("-") {
|
if s.starts_with('-') {
|
||||||
let v = try_consume!(scan::number(&s[1..], 1, usize::MAX));
|
let v = try_consume!(scan::number(&s[1..], 1, usize::MAX));
|
||||||
try!(0i64.checked_sub(v).ok_or(OUT_OF_RANGE))
|
try!(0i64.checked_sub(v).ok_or(OUT_OF_RANGE))
|
||||||
} else if s.starts_with("+") {
|
} else if s.starts_with('+') {
|
||||||
try_consume!(scan::number(&s[1..], 1, usize::MAX))
|
try_consume!(scan::number(&s[1..], 1, usize::MAX))
|
||||||
} else {
|
} else {
|
||||||
// if there is no explicit sign, we respect the original `width`
|
// if there is no explicit sign, we respect the original `width`
|
||||||
|
@ -303,7 +303,7 @@ pub fn parse<'a, I>(parsed: &mut Parsed, mut s: &str, items: I) -> ParseResult<(
|
||||||
}
|
}
|
||||||
|
|
||||||
Nanosecond | Nanosecond3 | Nanosecond6 | Nanosecond9=> {
|
Nanosecond | Nanosecond3 | Nanosecond6 | Nanosecond9=> {
|
||||||
if s.starts_with(".") {
|
if s.starts_with('.') {
|
||||||
let nano = try_consume!(scan::nanosecond(&s[1..]));
|
let nano = try_consume!(scan::nanosecond(&s[1..]));
|
||||||
try!(parsed.set_nanosecond(nano));
|
try!(parsed.set_nanosecond(nano));
|
||||||
}
|
}
|
||||||
|
|
|
@ -555,7 +555,7 @@ impl Parsed {
|
||||||
|
|
||||||
/// Returns a parsed fixed time zone offset out of given fields.
|
/// Returns a parsed fixed time zone offset out of given fields.
|
||||||
pub fn to_fixed_offset(&self) -> ParseResult<FixedOffset> {
|
pub fn to_fixed_offset(&self) -> ParseResult<FixedOffset> {
|
||||||
self.offset.and_then(|offset| FixedOffset::east_opt(offset)).ok_or(OUT_OF_RANGE)
|
self.offset.and_then(FixedOffset::east_opt).ok_or(OUT_OF_RANGE)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a parsed timezone-aware date and time out of given fields.
|
/// Returns a parsed timezone-aware date and time out of given fields.
|
||||||
|
|
|
@ -252,7 +252,7 @@ pub fn timezone_offset_2822(s: &str) -> ParseResult<(&str, Option<i32>)> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let (s_, offset) = try!(timezone_offset(s, |s| Ok(s)));
|
let (s_, offset) = try!(timezone_offset(s, |s| Ok(s)));
|
||||||
if offset == 0 && s.starts_with("-") { // -0000 is not same to +0000
|
if offset == 0 && s.starts_with('-') { // -0000 is not same to +0000
|
||||||
Ok((s_, None))
|
Ok((s_, None))
|
||||||
} else {
|
} else {
|
||||||
Ok((s_, Some(offset)))
|
Ok((s_, Some(offset)))
|
||||||
|
|
|
@ -482,7 +482,7 @@ impl NaiveDate {
|
||||||
/// ~~~~
|
/// ~~~~
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn and_time(&self, time: NaiveTime) -> NaiveDateTime {
|
pub fn and_time(&self, time: NaiveTime) -> NaiveDateTime {
|
||||||
NaiveDateTime::new(self.clone(), time)
|
NaiveDateTime::new(*self, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Makes a new `NaiveDateTime` from the current date, hour, minute and second.
|
/// Makes a new `NaiveDateTime` from the current date, hour, minute and second.
|
||||||
|
@ -884,7 +884,7 @@ impl NaiveDate {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I>
|
pub fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I>
|
||||||
where I: Iterator<Item=Item<'a>> + Clone {
|
where I: Iterator<Item=Item<'a>> + Clone {
|
||||||
DelayedFormat::new(Some(self.clone()), None, items)
|
DelayedFormat::new(Some(*self), None, items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formats the date with the specified format string.
|
/// Formats the date with the specified format string.
|
||||||
|
|
|
@ -505,7 +505,7 @@ impl NaiveDateTime {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I>
|
pub fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I>
|
||||||
where I: Iterator<Item=Item<'a>> + Clone {
|
where I: Iterator<Item=Item<'a>> + Clone {
|
||||||
DelayedFormat::new(Some(self.date.clone()), Some(self.time.clone()), items)
|
DelayedFormat::new(Some(self.date), Some(self.time), items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formats the combined date and time with the specified format string.
|
/// Formats the combined date and time with the specified format string.
|
||||||
|
|
|
@ -652,7 +652,7 @@ impl NaiveTime {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I>
|
pub fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I>
|
||||||
where I: Iterator<Item=Item<'a>> + Clone {
|
where I: Iterator<Item=Item<'a>> + Clone {
|
||||||
DelayedFormat::new(None, Some(self.clone()), items)
|
DelayedFormat::new(None, Some(*self), items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formats the time with the specified format string.
|
/// Formats the time with the specified format string.
|
||||||
|
|
|
@ -82,17 +82,17 @@ impl FixedOffset {
|
||||||
impl TimeZone for FixedOffset {
|
impl TimeZone for FixedOffset {
|
||||||
type Offset = FixedOffset;
|
type Offset = FixedOffset;
|
||||||
|
|
||||||
fn from_offset(offset: &FixedOffset) -> FixedOffset { offset.clone() }
|
fn from_offset(offset: &FixedOffset) -> FixedOffset { *offset }
|
||||||
|
|
||||||
fn offset_from_local_date(&self, _local: &NaiveDate) -> LocalResult<FixedOffset> {
|
fn offset_from_local_date(&self, _local: &NaiveDate) -> LocalResult<FixedOffset> {
|
||||||
LocalResult::Single(self.clone())
|
LocalResult::Single(*self)
|
||||||
}
|
}
|
||||||
fn offset_from_local_datetime(&self, _local: &NaiveDateTime) -> LocalResult<FixedOffset> {
|
fn offset_from_local_datetime(&self, _local: &NaiveDateTime) -> LocalResult<FixedOffset> {
|
||||||
LocalResult::Single(self.clone())
|
LocalResult::Single(*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn offset_from_utc_date(&self, _utc: &NaiveDate) -> FixedOffset { self.clone() }
|
fn offset_from_utc_date(&self, _utc: &NaiveDate) -> FixedOffset { *self }
|
||||||
fn offset_from_utc_datetime(&self, _utc: &NaiveDateTime) -> FixedOffset { self.clone() }
|
fn offset_from_utc_datetime(&self, _utc: &NaiveDateTime) -> FixedOffset { *self }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Offset for FixedOffset {
|
impl Offset for FixedOffset {
|
||||||
|
|
|
@ -111,7 +111,7 @@ impl TimeZone for Local {
|
||||||
// in the other words, we use the offset at the local midnight
|
// in the other words, we use the offset at the local midnight
|
||||||
// but keep the actual date unaltered (much like `FixedOffset`).
|
// but keep the actual date unaltered (much like `FixedOffset`).
|
||||||
let midnight = self.from_local_datetime(&local.and_hms(0, 0, 0));
|
let midnight = self.from_local_datetime(&local.and_hms(0, 0, 0));
|
||||||
midnight.map(|datetime| Date::from_utc(*local, datetime.offset().clone()))
|
midnight.map(|datetime| Date::from_utc(*local, *datetime.offset()))
|
||||||
}
|
}
|
||||||
fn from_local_datetime(&self, local: &NaiveDateTime) -> LocalResult<DateTime<Local>> {
|
fn from_local_datetime(&self, local: &NaiveDateTime) -> LocalResult<DateTime<Local>> {
|
||||||
let timespec = datetime_to_timespec(local, true);
|
let timespec = datetime_to_timespec(local, true);
|
||||||
|
@ -120,7 +120,7 @@ impl TimeZone for Local {
|
||||||
|
|
||||||
fn from_utc_date(&self, utc: &NaiveDate) -> Date<Local> {
|
fn from_utc_date(&self, utc: &NaiveDate) -> Date<Local> {
|
||||||
let midnight = self.from_utc_datetime(&utc.and_hms(0, 0, 0));
|
let midnight = self.from_utc_datetime(&utc.and_hms(0, 0, 0));
|
||||||
Date::from_utc(*utc, midnight.offset().clone())
|
Date::from_utc(*utc, *midnight.offset())
|
||||||
}
|
}
|
||||||
fn from_utc_datetime(&self, utc: &NaiveDateTime) -> DateTime<Local> {
|
fn from_utc_datetime(&self, utc: &NaiveDateTime) -> DateTime<Local> {
|
||||||
let timespec = datetime_to_timespec(utc, false);
|
let timespec = datetime_to_timespec(utc, false);
|
||||||
|
|
|
@ -333,13 +333,13 @@ pub trait TimeZone: Sized + Clone {
|
||||||
/// Converts the UTC `NaiveDate` to the local time.
|
/// Converts the UTC `NaiveDate` to the local time.
|
||||||
/// The UTC is continuous and thus this cannot fail (but can give the duplicate local time).
|
/// The UTC is continuous and thus this cannot fail (but can give the duplicate local time).
|
||||||
fn from_utc_date(&self, utc: &NaiveDate) -> Date<Self> {
|
fn from_utc_date(&self, utc: &NaiveDate) -> Date<Self> {
|
||||||
Date::from_utc(utc.clone(), self.offset_from_utc_date(utc))
|
Date::from_utc(*utc, self.offset_from_utc_date(utc))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the UTC `NaiveDateTime` to the local time.
|
/// Converts the UTC `NaiveDateTime` to the local time.
|
||||||
/// The UTC is continuous and thus this cannot fail (but can give the duplicate local time).
|
/// The UTC is continuous and thus this cannot fail (but can give the duplicate local time).
|
||||||
fn from_utc_datetime(&self, utc: &NaiveDateTime) -> DateTime<Self> {
|
fn from_utc_datetime(&self, utc: &NaiveDateTime) -> DateTime<Self> {
|
||||||
DateTime::from_utc(utc.clone(), self.offset_from_utc_datetime(utc))
|
DateTime::from_utc(*utc, self.offset_from_utc_datetime(utc))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue