mirror of
https://github.com/chronotope/chrono.git
synced 2025-10-01 06:52:15 +00:00
Update to 2018 edition (and MSRV 1.32)
This commit is contained in:
parent
895906a810
commit
e4c8a529f5
7
.github/workflows/test-release.yml
vendored
7
.github/workflows/test-release.yml
vendored
@ -31,10 +31,11 @@ jobs:
|
|||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
rust_version: nightly
|
rust_version: nightly
|
||||||
- os: ubuntu-18.04
|
- os: ubuntu-18.04
|
||||||
rust_version: 1.13.0
|
rust_version: 1.32.0
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
rust_version: 1.13.0
|
rust_version: 1.32.0
|
||||||
# time doesn't work on windows with 1.13
|
- os: windows-latest
|
||||||
|
rust_version: 1.32.0
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
7
.github/workflows/test.yml
vendored
7
.github/workflows/test.yml
vendored
@ -39,10 +39,11 @@ jobs:
|
|||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
rust_version: nightly
|
rust_version: nightly
|
||||||
- os: ubuntu-18.04
|
- os: ubuntu-18.04
|
||||||
rust_version: 1.13.0
|
rust_version: 1.32.0
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
rust_version: 1.13.0
|
rust_version: 1.32.0
|
||||||
# time doesn't work on windows with 1.13
|
- os: windows-latest
|
||||||
|
rust_version: 1.32.0
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ categories = ["date-and-time"]
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
exclude = ["/ci/*", "/.travis.yml", "/appveyor.yml", "/Makefile"]
|
exclude = ["/ci/*", "/.travis.yml", "/appveyor.yml", "/Makefile"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "chronotope/chrono" }
|
travis-ci = { repository = "chronotope/chrono" }
|
||||||
|
12
ci/github.sh
12
ci/github.sh
@ -8,7 +8,7 @@ source "${BASH_SOURCE[0]%/*}/_shlib.sh"
|
|||||||
TEST_TZS=(ACST-9:30 EST4 UTC0 Asia/Katmandu)
|
TEST_TZS=(ACST-9:30 EST4 UTC0 Asia/Katmandu)
|
||||||
FEATURES=(std serde clock "alloc serde" unstable-locales)
|
FEATURES=(std serde clock "alloc serde" unstable-locales)
|
||||||
CHECK_FEATURES=(alloc "std unstable-locales" "serde clock" "clock unstable-locales")
|
CHECK_FEATURES=(alloc "std unstable-locales" "serde clock" "clock unstable-locales")
|
||||||
RUST_113_FEATURES=(rustc-serialize serde)
|
RUST_132_FEATURES=(rustc-serialize serde)
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
if [[ "$*" =~ "-h" ]]; then
|
if [[ "$*" =~ "-h" ]]; then
|
||||||
@ -29,7 +29,7 @@ meaningful in the github actions feature matrix UI.
|
|||||||
|
|
||||||
runv cargo --version
|
runv cargo --version
|
||||||
|
|
||||||
if [[ ${RUST_VERSION:-} != 1.13.0 ]]; then
|
if [[ ${RUST_VERSION:-} != 1.32.0 ]]; then
|
||||||
if [[ ${WASM:-} == yes_wasm ]]; then
|
if [[ ${WASM:-} == yes_wasm ]]; then
|
||||||
test_wasm
|
test_wasm
|
||||||
elif [[ ${WASM:-} == wasm_simple ]]; then
|
elif [[ ${WASM:-} == wasm_simple ]]; then
|
||||||
@ -43,8 +43,8 @@ meaningful in the github actions feature matrix UI.
|
|||||||
else
|
else
|
||||||
test_regular UTC0
|
test_regular UTC0
|
||||||
fi
|
fi
|
||||||
elif [[ ${RUST_VERSION:-} == 1.13.0 ]]; then
|
elif [[ ${RUST_VERSION:-} == 1.32.0 ]]; then
|
||||||
test_113
|
test_132
|
||||||
else
|
else
|
||||||
echo "ERROR: didn't run any tests"
|
echo "ERROR: didn't run any tests"
|
||||||
exit 1
|
exit 1
|
||||||
@ -74,9 +74,9 @@ check_combinatoric() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
test_113() {
|
test_132() {
|
||||||
runv cargo build --color=always
|
runv cargo build --color=always
|
||||||
for feature in "${RUST_113_FEATURES[@]}"; do
|
for feature in "${RUST_132_FEATURES[@]}"; do
|
||||||
runt cargo build --features "$feature" --color=always
|
runt cargo build --features "$feature" --color=always
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
18
src/date.rs
18
src/date.rs
@ -3,21 +3,21 @@
|
|||||||
|
|
||||||
//! ISO 8601 calendar date with time zone.
|
//! ISO 8601 calendar date with time zone.
|
||||||
|
|
||||||
|
use crate::oldtime::Duration as OldDuration;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use core::borrow::Borrow;
|
use core::borrow::Borrow;
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core::ops::{Add, Sub};
|
use core::ops::{Add, Sub};
|
||||||
use core::{fmt, hash};
|
use core::{fmt, hash};
|
||||||
use oldtime::Duration as OldDuration;
|
|
||||||
|
|
||||||
#[cfg(feature = "unstable-locales")]
|
#[cfg(feature = "unstable-locales")]
|
||||||
use format::Locale;
|
use crate::format::Locale;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use format::{DelayedFormat, Item, StrftimeItems};
|
use crate::format::{DelayedFormat, Item, StrftimeItems};
|
||||||
use naive::{self, IsoWeek, NaiveDate, NaiveTime};
|
use crate::naive::{self, IsoWeek, NaiveDate, NaiveTime};
|
||||||
use offset::{TimeZone, Utc};
|
use crate::offset::{TimeZone, Utc};
|
||||||
use DateTime;
|
use crate::DateTime;
|
||||||
use {Datelike, Weekday};
|
use crate::{Datelike, Weekday};
|
||||||
|
|
||||||
/// ISO 8601 calendar date with time zone.
|
/// ISO 8601 calendar date with time zone.
|
||||||
///
|
///
|
||||||
@ -36,7 +36,7 @@ use {Datelike, Weekday};
|
|||||||
/// the corresponding local date should exist for at least a moment.
|
/// the corresponding local date should exist for at least a moment.
|
||||||
/// (It may still have a gap from the offset changes.)
|
/// (It may still have a gap from the offset changes.)
|
||||||
///
|
///
|
||||||
/// - The `TimeZone` is free to assign *any* [`Offset`](::offset::Offset) to the
|
/// - The `TimeZone` is free to assign *any* [`Offset`](crate::offset::Offset) to the
|
||||||
/// local date, as long as that offset did occur in given day.
|
/// local date, as long as that offset did occur in given day.
|
||||||
///
|
///
|
||||||
/// For example, if `2015-03-08T01:59-08:00` is followed by `2015-03-08T03:00-07:00`,
|
/// For example, if `2015-03-08T01:59-08:00` is followed by `2015-03-08T03:00-07:00`,
|
||||||
@ -297,7 +297,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Formats the date with the specified format string.
|
/// Formats the date with the specified format string.
|
||||||
/// See the [`::format::strftime`] module
|
/// See the [`crate::format::strftime`] module
|
||||||
/// on the supported escape sequences.
|
/// on the supported escape sequences.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
//! ISO 8601 date and time with time zone.
|
//! ISO 8601 date and time with time zone.
|
||||||
|
|
||||||
|
use crate::oldtime::Duration as OldDuration;
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core::ops::{Add, Sub};
|
use core::ops::{Add, Sub};
|
||||||
use core::{fmt, hash, str};
|
use core::{fmt, hash, str};
|
||||||
use oldtime::Duration as OldDuration;
|
|
||||||
#[cfg(any(feature = "std", test))]
|
#[cfg(any(feature = "std", test))]
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
@ -16,19 +16,19 @@ use alloc::string::{String, ToString};
|
|||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
|
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use core::borrow::Borrow;
|
use crate::format::DelayedFormat;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
|
||||||
use format::DelayedFormat;
|
|
||||||
#[cfg(feature = "unstable-locales")]
|
#[cfg(feature = "unstable-locales")]
|
||||||
use format::Locale;
|
use crate::format::Locale;
|
||||||
use format::{parse, ParseError, ParseResult, Parsed, StrftimeItems};
|
use crate::format::{parse, ParseError, ParseResult, Parsed, StrftimeItems};
|
||||||
use format::{Fixed, Item};
|
use crate::format::{Fixed, Item};
|
||||||
use naive::{self, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime};
|
use crate::naive::{self, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime};
|
||||||
#[cfg(feature = "clock")]
|
#[cfg(feature = "clock")]
|
||||||
use offset::Local;
|
use crate::offset::Local;
|
||||||
use offset::{FixedOffset, Offset, TimeZone, Utc};
|
use crate::offset::{FixedOffset, Offset, TimeZone, Utc};
|
||||||
use Date;
|
use crate::Date;
|
||||||
use {Datelike, Timelike, Weekday};
|
use crate::{Datelike, Timelike, Weekday};
|
||||||
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
|
use core::borrow::Borrow;
|
||||||
|
|
||||||
/// Specific formatting options for seconds. This may be extended in the
|
/// Specific formatting options for seconds. This may be extended in the
|
||||||
/// future, so exhaustive matching in external code is not recommended.
|
/// future, so exhaustive matching in external code is not recommended.
|
||||||
@ -473,7 +473,7 @@ impl DateTime<FixedOffset> {
|
|||||||
/// Parses a string with the specified format string and returns a new
|
/// Parses a string with the specified format string and returns a new
|
||||||
/// [`DateTime`] with a parsed [`FixedOffset`].
|
/// [`DateTime`] with a parsed [`FixedOffset`].
|
||||||
///
|
///
|
||||||
/// See the [`::format::strftime`] module on the supported escape
|
/// See the [`crate::format::strftime`] module on the supported escape
|
||||||
/// sequences.
|
/// sequences.
|
||||||
///
|
///
|
||||||
/// See also [`TimeZone::datetime_from_str`] which gives a local
|
/// See also [`TimeZone::datetime_from_str`] which gives a local
|
||||||
@ -543,9 +543,9 @@ where
|
|||||||
/// ```
|
/// ```
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
pub fn to_rfc3339_opts(&self, secform: SecondsFormat, use_z: bool) -> String {
|
pub fn to_rfc3339_opts(&self, secform: SecondsFormat, use_z: bool) -> String {
|
||||||
use format::Numeric::*;
|
use crate::format::Numeric::*;
|
||||||
use format::Pad::Zero;
|
use crate::format::Pad::Zero;
|
||||||
use SecondsFormat::*;
|
use crate::SecondsFormat::*;
|
||||||
|
|
||||||
debug_assert!(secform != __NonExhaustive, "Do not use __NonExhaustive!");
|
debug_assert!(secform != __NonExhaustive, "Do not use __NonExhaustive!");
|
||||||
|
|
||||||
@ -597,7 +597,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Formats the combined date and time with the specified format string.
|
/// Formats the combined date and time with the specified format string.
|
||||||
/// See the [`::format::strftime`] module
|
/// See the [`crate::format::strftime`] module
|
||||||
/// on the supported escape sequences.
|
/// on the supported escape sequences.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@ -1084,11 +1084,11 @@ fn test_decodable_json_timestamps<FUtc, FFixed, FLocal, E>(
|
|||||||
#[cfg(feature = "rustc-serialize")]
|
#[cfg(feature = "rustc-serialize")]
|
||||||
pub mod rustc_serialize {
|
pub mod rustc_serialize {
|
||||||
use super::DateTime;
|
use super::DateTime;
|
||||||
|
#[cfg(feature = "clock")]
|
||||||
|
use crate::offset::Local;
|
||||||
|
use crate::offset::{FixedOffset, LocalResult, TimeZone, Utc};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
#[cfg(feature = "clock")]
|
|
||||||
use offset::Local;
|
|
||||||
use offset::{FixedOffset, LocalResult, TimeZone, Utc};
|
|
||||||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||||
|
|
||||||
impl<Tz: TimeZone> Encodable for DateTime<Tz> {
|
impl<Tz: TimeZone> Encodable for DateTime<Tz> {
|
||||||
@ -1211,12 +1211,12 @@ pub mod rustc_serialize {
|
|||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
pub mod serde {
|
pub mod serde {
|
||||||
use super::DateTime;
|
use super::DateTime;
|
||||||
use core::fmt;
|
|
||||||
#[cfg(feature = "clock")]
|
#[cfg(feature = "clock")]
|
||||||
use offset::Local;
|
use crate::offset::Local;
|
||||||
use offset::{FixedOffset, LocalResult, TimeZone, Utc};
|
use crate::offset::{FixedOffset, LocalResult, TimeZone, Utc};
|
||||||
use serdelib::{de, ser};
|
use crate::serdelib::{de, ser};
|
||||||
use {ne_timestamp, SerdeError};
|
use crate::{ne_timestamp, SerdeError};
|
||||||
|
use core::fmt;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -1379,8 +1379,8 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use offset::TimeZone;
|
use crate::offset::TimeZone;
|
||||||
use {DateTime, Utc};
|
use crate::{DateTime, Utc};
|
||||||
|
|
||||||
use super::{serde_from, NanoSecondsTimestampVisitor};
|
use super::{serde_from, NanoSecondsTimestampVisitor};
|
||||||
|
|
||||||
@ -1532,7 +1532,7 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use {DateTime, Utc};
|
use crate::{DateTime, Utc};
|
||||||
|
|
||||||
use super::NanoSecondsTimestampVisitor;
|
use super::NanoSecondsTimestampVisitor;
|
||||||
|
|
||||||
@ -1689,8 +1689,8 @@ pub mod serde {
|
|||||||
|
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use offset::TimeZone;
|
use crate::offset::TimeZone;
|
||||||
use {DateTime, Utc};
|
use crate::{DateTime, Utc};
|
||||||
|
|
||||||
use super::{serde_from, MicroSecondsTimestampVisitor};
|
use super::{serde_from, MicroSecondsTimestampVisitor};
|
||||||
|
|
||||||
@ -1842,7 +1842,7 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use {DateTime, Utc};
|
use crate::{DateTime, Utc};
|
||||||
|
|
||||||
use super::MicroSecondsTimestampVisitor;
|
use super::MicroSecondsTimestampVisitor;
|
||||||
|
|
||||||
@ -1998,8 +1998,8 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use offset::TimeZone;
|
use crate::offset::TimeZone;
|
||||||
use {DateTime, Utc};
|
use crate::{DateTime, Utc};
|
||||||
|
|
||||||
use super::{serde_from, MilliSecondsTimestampVisitor};
|
use super::{serde_from, MilliSecondsTimestampVisitor};
|
||||||
|
|
||||||
@ -2148,7 +2148,7 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use {DateTime, Utc};
|
use crate::{DateTime, Utc};
|
||||||
|
|
||||||
use super::MilliSecondsTimestampVisitor;
|
use super::MilliSecondsTimestampVisitor;
|
||||||
|
|
||||||
@ -2317,8 +2317,8 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use offset::TimeZone;
|
use crate::offset::TimeZone;
|
||||||
use {DateTime, Utc};
|
use crate::{DateTime, Utc};
|
||||||
|
|
||||||
use super::{serde_from, SecondsTimestampVisitor};
|
use super::{serde_from, SecondsTimestampVisitor};
|
||||||
|
|
||||||
@ -2461,7 +2461,7 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use {DateTime, Utc};
|
use crate::{DateTime, Utc};
|
||||||
|
|
||||||
use super::SecondsTimestampVisitor;
|
use super::SecondsTimestampVisitor;
|
||||||
|
|
||||||
@ -2614,14 +2614,14 @@ pub mod serde {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::DateTime;
|
use super::DateTime;
|
||||||
use naive::{NaiveDate, NaiveTime};
|
use crate::naive::{NaiveDate, NaiveTime};
|
||||||
#[cfg(feature = "clock")]
|
#[cfg(feature = "clock")]
|
||||||
use offset::Local;
|
use crate::offset::Local;
|
||||||
use offset::{FixedOffset, TimeZone, Utc};
|
use crate::offset::{FixedOffset, TimeZone, Utc};
|
||||||
use oldtime::Duration;
|
use crate::oldtime::Duration;
|
||||||
|
#[cfg(feature = "clock")]
|
||||||
|
use crate::Datelike;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
#[cfg(feature = "clock")]
|
|
||||||
use Datelike;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
@ -2774,7 +2774,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rfc3339_opts() {
|
fn test_rfc3339_opts() {
|
||||||
use SecondsFormat::*;
|
use crate::SecondsFormat::*;
|
||||||
let pst = FixedOffset::east(8 * 60 * 60);
|
let pst = FixedOffset::east(8 * 60 * 60);
|
||||||
let dt = pst.ymd(2018, 1, 11).and_hms_nano(10, 5, 13, 84_660_000);
|
let dt = pst.ymd(2018, 1, 11).and_hms_nano(10, 5, 13, 84_660_000);
|
||||||
assert_eq!(dt.to_rfc3339_opts(Secs, false), "2018-01-11T10:05:13+08:00");
|
assert_eq!(dt.to_rfc3339_opts(Secs, false), "2018-01-11T10:05:13+08:00");
|
||||||
@ -2797,7 +2797,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_rfc3339_opts_nonexhaustive() {
|
fn test_rfc3339_opts_nonexhaustive() {
|
||||||
use SecondsFormat;
|
use crate::SecondsFormat;
|
||||||
let dt = Utc.ymd(1999, 10, 9).and_hms(1, 2, 3);
|
let dt = Utc.ymd(1999, 10, 9).and_hms(1, 2, 3);
|
||||||
dt.to_rfc3339_opts(SecondsFormat::__NonExhaustive, true);
|
dt.to_rfc3339_opts(SecondsFormat::__NonExhaustive, true);
|
||||||
}
|
}
|
||||||
|
@ -47,22 +47,22 @@ use core::str::FromStr;
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use naive::{NaiveDate, NaiveTime};
|
use crate::naive::{NaiveDate, NaiveTime};
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use offset::{FixedOffset, Offset};
|
use crate::offset::{FixedOffset, Offset};
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use {Datelike, Timelike};
|
use crate::{Datelike, Timelike};
|
||||||
use {Month, ParseMonthError, ParseWeekdayError, Weekday};
|
use crate::{Month, ParseMonthError, ParseWeekdayError, Weekday};
|
||||||
|
|
||||||
#[cfg(feature = "unstable-locales")]
|
#[cfg(feature = "unstable-locales")]
|
||||||
pub(crate) mod locales;
|
pub(crate) mod locales;
|
||||||
|
|
||||||
pub use self::parse::parse;
|
pub use parse::parse;
|
||||||
pub use self::parsed::Parsed;
|
pub use parsed::Parsed;
|
||||||
pub use self::strftime::StrftimeItems;
|
|
||||||
/// L10n locales.
|
/// L10n locales.
|
||||||
#[cfg(feature = "unstable-locales")]
|
#[cfg(feature = "unstable-locales")]
|
||||||
pub use pure_rust_locales::Locale;
|
pub use pure_rust_locales::Locale;
|
||||||
|
pub use strftime::StrftimeItems;
|
||||||
|
|
||||||
#[cfg(not(feature = "unstable-locales"))]
|
#[cfg(not(feature = "unstable-locales"))]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -465,8 +465,8 @@ fn format_inner<'a>(
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::div::{div_floor, mod_floor};
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use div::{div_floor, mod_floor};
|
|
||||||
|
|
||||||
match *item {
|
match *item {
|
||||||
Item::Literal(s) | Item::Space(s) => result.push_str(s),
|
Item::Literal(s) | Item::Space(s) => result.push_str(s),
|
||||||
|
@ -14,7 +14,7 @@ use super::scan;
|
|||||||
use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric, Pad, Parsed};
|
use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric, Pad, Parsed};
|
||||||
use super::{ParseError, ParseErrorKind, ParseResult};
|
use super::{ParseError, ParseErrorKind, ParseResult};
|
||||||
use super::{BAD_FORMAT, INVALID, NOT_ENOUGH, OUT_OF_RANGE, TOO_LONG, TOO_SHORT};
|
use super::{BAD_FORMAT, INVALID, NOT_ENOUGH, OUT_OF_RANGE, TOO_LONG, TOO_SHORT};
|
||||||
use {DateTime, FixedOffset, Weekday};
|
use crate::{DateTime, FixedOffset, Weekday};
|
||||||
|
|
||||||
fn set_weekday_with_num_days_from_sunday(p: &mut Parsed, v: i64) -> ParseResult<()> {
|
fn set_weekday_with_num_days_from_sunday(p: &mut Parsed, v: i64) -> ParseResult<()> {
|
||||||
p.set_weekday(match v {
|
p.set_weekday(match v {
|
||||||
@ -809,8 +809,8 @@ fn test_parse() {
|
|||||||
fn test_rfc2822() {
|
fn test_rfc2822() {
|
||||||
use super::NOT_ENOUGH;
|
use super::NOT_ENOUGH;
|
||||||
use super::*;
|
use super::*;
|
||||||
use offset::FixedOffset;
|
use crate::offset::FixedOffset;
|
||||||
use DateTime;
|
use crate::DateTime;
|
||||||
|
|
||||||
// Test data - (input, Ok(expected result after parse and format) or Err(error code))
|
// Test data - (input, Ok(expected result after parse and format) or Err(error code))
|
||||||
let testdates = [
|
let testdates = [
|
||||||
@ -864,7 +864,7 @@ fn test_rfc2822() {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_rfc850() {
|
fn parse_rfc850() {
|
||||||
use {TimeZone, Utc};
|
use crate::{TimeZone, Utc};
|
||||||
|
|
||||||
static RFC850_FMT: &'static str = "%A, %d-%b-%y %T GMT";
|
static RFC850_FMT: &'static str = "%A, %d-%b-%y %T GMT";
|
||||||
|
|
||||||
@ -897,8 +897,8 @@ fn parse_rfc850() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_rfc3339() {
|
fn test_rfc3339() {
|
||||||
use super::*;
|
use super::*;
|
||||||
use offset::FixedOffset;
|
use crate::offset::FixedOffset;
|
||||||
use DateTime;
|
use crate::DateTime;
|
||||||
|
|
||||||
// Test data - (input, Ok(expected result after parse and format) or Err(error code))
|
// Test data - (input, Ok(expected result after parse and format) or Err(error code))
|
||||||
let testdates = [
|
let testdates = [
|
||||||
|
@ -4,16 +4,16 @@
|
|||||||
//! A collection of parsed date and time items.
|
//! A collection of parsed date and time items.
|
||||||
//! They can be constructed incrementally while being checked for consistency.
|
//! They can be constructed incrementally while being checked for consistency.
|
||||||
|
|
||||||
|
use crate::oldtime::Duration as OldDuration;
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use oldtime::Duration as OldDuration;
|
|
||||||
|
|
||||||
use super::{ParseResult, IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
|
use super::{ParseResult, IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
|
||||||
use div::div_rem;
|
use crate::div::div_rem;
|
||||||
use naive::{NaiveDate, NaiveDateTime, NaiveTime};
|
use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||||
use offset::{FixedOffset, LocalResult, Offset, TimeZone};
|
use crate::offset::{FixedOffset, LocalResult, Offset, TimeZone};
|
||||||
use DateTime;
|
use crate::DateTime;
|
||||||
use Weekday;
|
use crate::Weekday;
|
||||||
use {Datelike, Timelike};
|
use crate::{Datelike, Timelike};
|
||||||
|
|
||||||
/// Parsed parts of date and time. There are two classes of methods:
|
/// Parsed parts of date and time. There are two classes of methods:
|
||||||
///
|
///
|
||||||
@ -693,10 +693,10 @@ impl Parsed {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::super::{IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
|
use super::super::{IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
|
||||||
use super::Parsed;
|
use super::Parsed;
|
||||||
use naive::{NaiveDate, NaiveTime, MAX_DATE, MIN_DATE};
|
use crate::naive::{NaiveDate, NaiveTime, MAX_DATE, MIN_DATE};
|
||||||
use offset::{FixedOffset, TimeZone, Utc};
|
use crate::offset::{FixedOffset, TimeZone, Utc};
|
||||||
use Datelike;
|
use crate::Datelike;
|
||||||
use Weekday::*;
|
use crate::Weekday::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parsed_set_fields() {
|
fn test_parsed_set_fields() {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#![allow(deprecated)]
|
#![allow(deprecated)]
|
||||||
|
|
||||||
use super::{ParseResult, INVALID, OUT_OF_RANGE, TOO_SHORT};
|
use super::{ParseResult, INVALID, OUT_OF_RANGE, TOO_SHORT};
|
||||||
use Weekday;
|
use crate::Weekday;
|
||||||
|
|
||||||
/// Returns true when two slices are equal case-insensitively (in ASCII).
|
/// Returns true when two slices are equal case-insensitively (in ASCII).
|
||||||
/// Assumes that the `pattern` is already converted to lower case.
|
/// Assumes that the `pattern` is already converted to lower case.
|
||||||
@ -62,7 +62,7 @@ pub fn number(s: &str, min: usize, max: usize) -> ParseResult<(&str, i64)> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((&s[::core::cmp::min(max, bytes.len())..], n))
|
Ok((&s[core::cmp::min(max, bytes.len())..], n))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to consume at least one digits as a fractional second.
|
/// Tries to consume at least one digits as a fractional second.
|
||||||
|
@ -540,7 +540,7 @@ fn test_strftime_items() {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_strftime_docs() {
|
fn test_strftime_docs() {
|
||||||
use {FixedOffset, TimeZone, Timelike};
|
use crate::{FixedOffset, TimeZone, Timelike};
|
||||||
|
|
||||||
let dt = FixedOffset::east(34200).ymd(2001, 7, 8).and_hms_nano(0, 34, 59, 1_026_490_708);
|
let dt = FixedOffset::east(34200).ymd(2001, 7, 8).and_hms_nano(0, 34, 59, 1_026_490_708);
|
||||||
|
|
||||||
@ -618,7 +618,7 @@ fn test_strftime_docs() {
|
|||||||
#[cfg(feature = "unstable-locales")]
|
#[cfg(feature = "unstable-locales")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_strftime_docs_localized() {
|
fn test_strftime_docs_localized() {
|
||||||
use {FixedOffset, TimeZone};
|
use crate::{FixedOffset, TimeZone};
|
||||||
|
|
||||||
let dt = FixedOffset::east(34200).ymd(2001, 7, 8).and_hms_nano(0, 34, 59, 1_026_490_708);
|
let dt = FixedOffset::east(34200).ymd(2001, 7, 8).and_hms_nano(0, 34, 59, 1_026_490_708);
|
||||||
|
|
||||||
|
18
src/lib.rs
18
src/lib.rs
@ -518,25 +518,25 @@ pub use round::{DurationRound, RoundingError, SubsecRound};
|
|||||||
/// A convenience module appropriate for glob imports (`use chrono::prelude::*;`).
|
/// A convenience module appropriate for glob imports (`use chrono::prelude::*;`).
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use Date;
|
pub use crate::Date;
|
||||||
#[cfg(feature = "clock")]
|
#[cfg(feature = "clock")]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use Local;
|
pub use crate::Local;
|
||||||
#[cfg(feature = "unstable-locales")]
|
#[cfg(feature = "unstable-locales")]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use Locale;
|
pub use crate::Locale;
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use SubsecRound;
|
pub use crate::SubsecRound;
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use {DateTime, SecondsFormat};
|
pub use crate::{DateTime, SecondsFormat};
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use {Datelike, Month, Timelike, Weekday};
|
pub use crate::{Datelike, Month, Timelike, Weekday};
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use {FixedOffset, Utc};
|
pub use crate::{FixedOffset, Utc};
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use {NaiveDate, NaiveDateTime, NaiveTime};
|
pub use crate::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use {Offset, TimeZone};
|
pub use crate::{Offset, TimeZone};
|
||||||
}
|
}
|
||||||
|
|
||||||
// useful throughout the codebase
|
// useful throughout the codebase
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
|
|
||||||
//! ISO 8601 calendar date without timezone.
|
//! ISO 8601 calendar date without timezone.
|
||||||
|
|
||||||
|
use crate::oldtime::Duration as OldDuration;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use core::borrow::Borrow;
|
use core::borrow::Borrow;
|
||||||
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
||||||
use core::{fmt, str};
|
use core::{fmt, str};
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use oldtime::Duration as OldDuration;
|
|
||||||
|
|
||||||
use div::div_mod_floor;
|
use crate::div::div_mod_floor;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use format::DelayedFormat;
|
use crate::format::DelayedFormat;
|
||||||
use format::{parse, ParseError, ParseResult, Parsed, StrftimeItems};
|
use crate::format::{parse, ParseError, ParseResult, Parsed, StrftimeItems};
|
||||||
use format::{Item, Numeric, Pad};
|
use crate::format::{Item, Numeric, Pad};
|
||||||
use naive::{IsoWeek, NaiveDateTime, NaiveTime};
|
use crate::naive::{IsoWeek, NaiveDateTime, NaiveTime};
|
||||||
use {Datelike, Weekday};
|
use crate::{Datelike, Weekday};
|
||||||
|
|
||||||
use super::internals::{self, DateImpl, Mdf, Of, YearFlags};
|
use super::internals::{self, DateImpl, Mdf, Of, YearFlags};
|
||||||
use super::isoweek;
|
use super::isoweek;
|
||||||
@ -1906,9 +1906,9 @@ mod tests {
|
|||||||
use super::NaiveDate;
|
use super::NaiveDate;
|
||||||
use super::{MAX_DATE, MAX_DAYS_FROM_YEAR_0, MAX_YEAR};
|
use super::{MAX_DATE, MAX_DAYS_FROM_YEAR_0, MAX_YEAR};
|
||||||
use super::{MIN_DATE, MIN_DAYS_FROM_YEAR_0, MIN_YEAR};
|
use super::{MIN_DATE, MIN_DAYS_FROM_YEAR_0, MIN_YEAR};
|
||||||
use oldtime::Duration;
|
use crate::oldtime::Duration;
|
||||||
|
use crate::{Datelike, Weekday};
|
||||||
use std::{i32, u32};
|
use std::{i32, u32};
|
||||||
use {Datelike, Weekday};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_date_from_ymd() {
|
fn test_date_from_ymd() {
|
||||||
|
@ -3,22 +3,22 @@
|
|||||||
|
|
||||||
//! ISO 8601 date and time without timezone.
|
//! ISO 8601 date and time without timezone.
|
||||||
|
|
||||||
|
use crate::oldtime::Duration as OldDuration;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use core::borrow::Borrow;
|
use core::borrow::Borrow;
|
||||||
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
||||||
use core::{fmt, hash, str};
|
use core::{fmt, hash, str};
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use oldtime::Duration as OldDuration;
|
|
||||||
|
|
||||||
use div::div_mod_floor;
|
use crate::div::div_mod_floor;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use format::DelayedFormat;
|
use crate::format::DelayedFormat;
|
||||||
use format::{parse, ParseError, ParseResult, Parsed, StrftimeItems};
|
use crate::format::{parse, ParseError, ParseResult, Parsed, StrftimeItems};
|
||||||
use format::{Fixed, Item, Numeric, Pad};
|
use crate::format::{Fixed, Item, Numeric, Pad};
|
||||||
use naive::date::{MAX_DATE, MIN_DATE};
|
use crate::naive::date::{MAX_DATE, MIN_DATE};
|
||||||
use naive::time::{MAX_TIME, MIN_TIME};
|
use crate::naive::time::{MAX_TIME, MIN_TIME};
|
||||||
use naive::{IsoWeek, NaiveDate, NaiveTime};
|
use crate::naive::{IsoWeek, NaiveDate, NaiveTime};
|
||||||
use {Datelike, Timelike, Weekday};
|
use crate::{Datelike, Timelike, Weekday};
|
||||||
|
|
||||||
/// The tight upper bound guarantees that a duration with `|Duration| >= 2^MAX_SECS_BITS`
|
/// The tight upper bound guarantees that a duration with `|Duration| >= 2^MAX_SECS_BITS`
|
||||||
/// will always overflow the addition with any date and time type.
|
/// will always overflow the addition with any date and time type.
|
||||||
@ -1401,7 +1401,7 @@ impl Sub<NaiveDateTime> for NaiveDateTime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The `Debug` output of the naive date and time `dt` is the same as
|
/// The `Debug` output of the naive date and time `dt` is the same as
|
||||||
/// [`dt.format("%Y-%m-%dT%H:%M:%S%.f")`](::format::strftime).
|
/// [`dt.format("%Y-%m-%dT%H:%M:%S%.f")`](crate::format::strftime).
|
||||||
///
|
///
|
||||||
/// The string printed can be readily parsed via the `parse` method on `str`.
|
/// The string printed can be readily parsed via the `parse` method on `str`.
|
||||||
///
|
///
|
||||||
@ -1434,7 +1434,7 @@ impl fmt::Debug for NaiveDateTime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The `Display` output of the naive date and time `dt` is the same as
|
/// The `Display` output of the naive date and time `dt` is the same as
|
||||||
/// [`dt.format("%Y-%m-%d %H:%M:%S%.f")`](::format::strftime).
|
/// [`dt.format("%Y-%m-%d %H:%M:%S%.f")`](crate::format::strftime).
|
||||||
///
|
///
|
||||||
/// It should be noted that, for leap seconds not on the minute boundary,
|
/// It should be noted that, for leap seconds not on the minute boundary,
|
||||||
/// it may print a representation not distinguishable from non-leap seconds.
|
/// it may print a representation not distinguishable from non-leap seconds.
|
||||||
@ -1465,7 +1465,7 @@ impl fmt::Display for NaiveDateTime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parsing a `str` into a `NaiveDateTime` uses the same format,
|
/// Parsing a `str` into a `NaiveDateTime` uses the same format,
|
||||||
/// [`%Y-%m-%dT%H:%M:%S%.f`](::format::strftime), as in `Debug`.
|
/// [`%Y-%m-%dT%H:%M:%S%.f`](crate::format::strftime), as in `Debug`.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
@ -1810,7 +1810,7 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use {ne_timestamp, NaiveDateTime};
|
use crate::{ne_timestamp, NaiveDateTime};
|
||||||
|
|
||||||
/// Serialize a UTC datetime into an integer number of nanoseconds since the epoch
|
/// Serialize a UTC datetime into an integer number of nanoseconds since the epoch
|
||||||
///
|
///
|
||||||
@ -1962,7 +1962,7 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use {ne_timestamp, NaiveDateTime};
|
use crate::{ne_timestamp, NaiveDateTime};
|
||||||
|
|
||||||
/// Serialize a UTC datetime into an integer number of milliseconds since the epoch
|
/// Serialize a UTC datetime into an integer number of milliseconds since the epoch
|
||||||
///
|
///
|
||||||
@ -2111,7 +2111,7 @@ pub mod serde {
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serdelib::{de, ser};
|
use serdelib::{de, ser};
|
||||||
|
|
||||||
use {ne_timestamp, NaiveDateTime};
|
use crate::{ne_timestamp, NaiveDateTime};
|
||||||
|
|
||||||
/// Serialize a UTC datetime into an integer number of seconds since the epoch
|
/// Serialize a UTC datetime into an integer number of seconds since the epoch
|
||||||
///
|
///
|
||||||
@ -2240,7 +2240,7 @@ pub mod serde {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_serde_bincode() {
|
fn test_serde_bincode() {
|
||||||
use self::bincode::{deserialize, serialize, Infinite};
|
use self::bincode::{deserialize, serialize, Infinite};
|
||||||
use naive::NaiveDate;
|
use crate::naive::NaiveDate;
|
||||||
|
|
||||||
let dt = NaiveDate::from_ymd(2016, 7, 8).and_hms_milli(9, 10, 48, 90);
|
let dt = NaiveDate::from_ymd(2016, 7, 8).and_hms_milli(9, 10, 48, 90);
|
||||||
let encoded = serialize(&dt, Infinite).unwrap();
|
let encoded = serialize(&dt, Infinite).unwrap();
|
||||||
@ -2252,8 +2252,8 @@ pub mod serde {
|
|||||||
fn test_serde_bincode_optional() {
|
fn test_serde_bincode_optional() {
|
||||||
use self::bincode::{deserialize, serialize, Infinite};
|
use self::bincode::{deserialize, serialize, Infinite};
|
||||||
use self::serde_derive::{Deserialize, Serialize};
|
use self::serde_derive::{Deserialize, Serialize};
|
||||||
use prelude::*;
|
use crate::prelude::*;
|
||||||
use serde::ts_nanoseconds_option;
|
use crate::serde::ts_nanoseconds_option;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
struct Test {
|
struct Test {
|
||||||
@ -2273,10 +2273,10 @@ pub mod serde {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::NaiveDateTime;
|
use super::NaiveDateTime;
|
||||||
use naive::{NaiveDate, MAX_DATE, MIN_DATE};
|
use crate::naive::{NaiveDate, MAX_DATE, MIN_DATE};
|
||||||
use oldtime::Duration;
|
use crate::oldtime::Duration;
|
||||||
|
use crate::Datelike;
|
||||||
use std::i64;
|
use std::i64;
|
||||||
use Datelike;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_datetime_from_timestamp() {
|
fn test_datetime_from_timestamp() {
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
#![allow(dead_code)] // some internal methods have been left for consistency
|
#![allow(dead_code)] // some internal methods have been left for consistency
|
||||||
#![cfg_attr(feature = "__internal_bench", allow(missing_docs))]
|
#![cfg_attr(feature = "__internal_bench", allow(missing_docs))]
|
||||||
|
|
||||||
|
use crate::div::{div_rem, mod_floor};
|
||||||
|
use crate::Weekday;
|
||||||
use core::{fmt, i32};
|
use core::{fmt, i32};
|
||||||
use div::{div_rem, mod_floor};
|
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use Weekday;
|
|
||||||
|
|
||||||
/// The internal date representation. This also includes the packed `Mdf` value.
|
/// The internal date representation. This also includes the packed `Mdf` value.
|
||||||
pub type DateImpl = i32;
|
pub type DateImpl = i32;
|
||||||
@ -490,8 +490,8 @@ mod tests {
|
|||||||
use self::num_iter::range_inclusive;
|
use self::num_iter::range_inclusive;
|
||||||
use super::{Mdf, Of};
|
use super::{Mdf, Of};
|
||||||
use super::{YearFlags, A, AG, B, BA, C, CB, D, DC, E, ED, F, FE, G, GF};
|
use super::{YearFlags, A, AG, B, BA, C, CB, D, DC, E, ED, F, FE, G, GF};
|
||||||
|
use crate::Weekday;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
use Weekday;
|
|
||||||
|
|
||||||
const NONLEAP_FLAGS: [YearFlags; 7] = [A, B, C, D, E, F, G];
|
const NONLEAP_FLAGS: [YearFlags; 7] = [A, B, C, D, E, F, G];
|
||||||
const LEAP_FLAGS: [YearFlags; 7] = [AG, BA, CB, DC, ED, FE, GF];
|
const LEAP_FLAGS: [YearFlags; 7] = [AG, BA, CB, DC, ED, FE, GF];
|
||||||
|
@ -142,8 +142,8 @@ impl fmt::Debug for IsoWeek {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use naive::{internals, MAX_DATE, MIN_DATE};
|
use crate::naive::{internals, MAX_DATE, MIN_DATE};
|
||||||
use Datelike;
|
use crate::Datelike;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_iso_week_extremes() {
|
fn test_iso_week_extremes() {
|
||||||
|
@ -3,18 +3,18 @@
|
|||||||
|
|
||||||
//! ISO 8601 time without timezone.
|
//! ISO 8601 time without timezone.
|
||||||
|
|
||||||
|
use crate::oldtime::Duration as OldDuration;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use core::borrow::Borrow;
|
use core::borrow::Borrow;
|
||||||
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
||||||
use core::{fmt, hash, str};
|
use core::{fmt, hash, str};
|
||||||
use oldtime::Duration as OldDuration;
|
|
||||||
|
|
||||||
use div::div_mod_floor;
|
use crate::div::div_mod_floor;
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
use format::DelayedFormat;
|
use crate::format::DelayedFormat;
|
||||||
use format::{parse, ParseError, ParseResult, Parsed, StrftimeItems};
|
use crate::format::{parse, ParseError, ParseResult, Parsed, StrftimeItems};
|
||||||
use format::{Fixed, Item, Numeric, Pad};
|
use crate::format::{Fixed, Item, Numeric, Pad};
|
||||||
use Timelike;
|
use crate::Timelike;
|
||||||
|
|
||||||
pub const MIN_TIME: NaiveTime = NaiveTime { secs: 0, frac: 0 };
|
pub const MIN_TIME: NaiveTime = NaiveTime { secs: 0, frac: 0 };
|
||||||
pub const MAX_TIME: NaiveTime = NaiveTime { secs: 23 * 3600 + 59 * 60 + 59, frac: 999_999_999 };
|
pub const MAX_TIME: NaiveTime = NaiveTime { secs: 23 * 3600 + 59 * 60 + 59, frac: 999_999_999 };
|
||||||
@ -1541,9 +1541,9 @@ mod serde {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::NaiveTime;
|
use super::NaiveTime;
|
||||||
use oldtime::Duration;
|
use crate::oldtime::Duration;
|
||||||
|
use crate::Timelike;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
use Timelike;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_time_from_hms_milli() {
|
fn test_time_from_hms_milli() {
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
|
|
||||||
//! The time zone which has a fixed offset from UTC.
|
//! The time zone which has a fixed offset from UTC.
|
||||||
|
|
||||||
|
use crate::oldtime::Duration as OldDuration;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::ops::{Add, Sub};
|
use core::ops::{Add, Sub};
|
||||||
use oldtime::Duration as OldDuration;
|
|
||||||
|
|
||||||
use super::{LocalResult, Offset, TimeZone};
|
use super::{LocalResult, Offset, TimeZone};
|
||||||
use div::div_mod_floor;
|
use crate::div::div_mod_floor;
|
||||||
use naive::{NaiveDate, NaiveDateTime, NaiveTime};
|
use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||||
use DateTime;
|
use crate::DateTime;
|
||||||
use Timelike;
|
use crate::Timelike;
|
||||||
|
|
||||||
/// The time zone with fixed offset, from UTC-23:59:59 to UTC+23:59:59.
|
/// The time zone with fixed offset, from UTC-23:59:59 to UTC+23:59:59.
|
||||||
///
|
///
|
||||||
@ -218,7 +218,7 @@ impl<Tz: TimeZone> Sub<FixedOffset> for DateTime<Tz> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FixedOffset;
|
use super::FixedOffset;
|
||||||
use offset::TimeZone;
|
use crate::offset::TimeZone;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_date_extreme_offset() {
|
fn test_date_extreme_offset() {
|
||||||
|
@ -4,16 +4,16 @@
|
|||||||
//! The local (system) time zone.
|
//! The local (system) time zone.
|
||||||
|
|
||||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
||||||
use sys::{self, Timespec};
|
use crate::sys::{self, Timespec};
|
||||||
|
|
||||||
use super::fixed::FixedOffset;
|
use super::fixed::FixedOffset;
|
||||||
use super::{LocalResult, TimeZone};
|
use super::{LocalResult, TimeZone};
|
||||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
||||||
use naive::NaiveTime;
|
use crate::naive::NaiveTime;
|
||||||
use naive::{NaiveDate, NaiveDateTime};
|
use crate::naive::{NaiveDate, NaiveDateTime};
|
||||||
use {Date, DateTime};
|
use crate::{Date, DateTime};
|
||||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
||||||
use {Datelike, Timelike};
|
use crate::{Datelike, Timelike};
|
||||||
|
|
||||||
/// Converts a `time::Tm` struct into the timezone-aware `DateTime`.
|
/// Converts a `time::Tm` struct into the timezone-aware `DateTime`.
|
||||||
/// This assumes that `time` is working correctly, i.e. any error is fatal.
|
/// This assumes that `time` is working correctly, i.e. any error is fatal.
|
||||||
@ -196,8 +196,8 @@ impl TimeZone for Local {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Local;
|
use super::Local;
|
||||||
use offset::TimeZone;
|
use crate::offset::TimeZone;
|
||||||
use Datelike;
|
use crate::Datelike;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_local_date_sanity_check() {
|
fn test_local_date_sanity_check() {
|
||||||
|
@ -20,10 +20,10 @@
|
|||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use format::{parse, ParseResult, Parsed, StrftimeItems};
|
use crate::format::{parse, ParseResult, Parsed, StrftimeItems};
|
||||||
use naive::{NaiveDate, NaiveDateTime, NaiveTime};
|
use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||||
use Weekday;
|
use crate::Weekday;
|
||||||
use {Date, DateTime};
|
use crate::{Date, DateTime};
|
||||||
|
|
||||||
/// The conversion result from the local time to the timezone-aware datetime types.
|
/// The conversion result from the local time to the timezone-aware datetime types.
|
||||||
#[derive(Clone, PartialEq, Debug, Copy, Eq, Hash)]
|
#[derive(Clone, PartialEq, Debug, Copy, Eq, Hash)]
|
||||||
@ -406,7 +406,7 @@ pub trait TimeZone: Sized + Clone {
|
|||||||
/// Parses a string with the specified format string and returns a
|
/// Parses a string with the specified format string and returns a
|
||||||
/// `DateTime` with the current offset.
|
/// `DateTime` with the current offset.
|
||||||
///
|
///
|
||||||
/// See the [`::format::strftime`] module on the
|
/// See the [`crate::format::strftime`] module on the
|
||||||
/// supported escape sequences.
|
/// supported escape sequences.
|
||||||
///
|
///
|
||||||
/// If the to-be-parsed string includes an offset, it *must* match the
|
/// If the to-be-parsed string includes an offset, it *must* match the
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use super::{FixedOffset, LocalResult, Offset, TimeZone};
|
use super::{FixedOffset, LocalResult, Offset, TimeZone};
|
||||||
use naive::{NaiveDate, NaiveDateTime};
|
use crate::naive::{NaiveDate, NaiveDateTime};
|
||||||
|
#[cfg(feature = "clock")]
|
||||||
|
use crate::{Date, DateTime};
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
feature = "clock",
|
feature = "clock",
|
||||||
not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))
|
not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))
|
||||||
))]
|
))]
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
#[cfg(feature = "clock")]
|
|
||||||
use {Date, DateTime};
|
|
||||||
|
|
||||||
/// The UTC time zone. This is the most efficient time zone when you don't need the local time.
|
/// The UTC time zone. This is the most efficient time zone when you don't need the local time.
|
||||||
/// It is also used as an offset (which is also a dummy type).
|
/// It is also used as an offset (which is also a dummy type).
|
||||||
|
16
src/round.rs
16
src/round.rs
@ -1,17 +1,15 @@
|
|||||||
// This is a part of Chrono.
|
// This is a part of Chrono.
|
||||||
// See README.md and LICENSE.txt for details.
|
// See README.md and LICENSE.txt for details.
|
||||||
|
|
||||||
|
use crate::datetime::DateTime;
|
||||||
|
use crate::naive::NaiveDateTime;
|
||||||
|
use crate::oldtime::Duration;
|
||||||
|
use crate::TimeZone;
|
||||||
|
use crate::Timelike;
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::marker::Sized;
|
use core::marker::Sized;
|
||||||
use core::ops::{Add, Sub};
|
use core::ops::{Add, Sub};
|
||||||
use datetime::DateTime;
|
|
||||||
use naive::NaiveDateTime;
|
|
||||||
use oldtime::Duration;
|
|
||||||
#[cfg(any(feature = "std", test))]
|
|
||||||
use std;
|
|
||||||
use TimeZone;
|
|
||||||
use Timelike;
|
|
||||||
|
|
||||||
/// Extension trait for subsecond rounding or truncation to a maximum number
|
/// Extension trait for subsecond rounding or truncation to a maximum number
|
||||||
/// of digits. Rounding can be used to decrease the error variance when
|
/// of digits. Rounding can be used to decrease the error variance when
|
||||||
@ -303,8 +301,8 @@ impl std::error::Error for RoundingError {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Duration, DurationRound, SubsecRound};
|
use super::{Duration, DurationRound, SubsecRound};
|
||||||
use offset::{FixedOffset, TimeZone, Utc};
|
use crate::offset::{FixedOffset, TimeZone, Utc};
|
||||||
use Timelike;
|
use crate::Timelike;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_round_subsecs() {
|
fn test_round_subsecs() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user