]> git.proxmox.com Git - rustc.git/blobdiff - vendor/chrono/README.md
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / vendor / chrono / README.md
index 8a37c7b775e3b84d2f85ca178dcc635f6f3dba0a..128568d506d876c223bb6b7914dfec4234dbb03a 100644 (file)
@@ -1,16 +1,13 @@
 [Chrono][docsrs]: Date and Time for Rust
 ========================================
 
-[![Chrono on Travis CI][travis-image]][travis]
-[![Chrono on Appveyor][appveyor-image]][appveyor]
+[![Chrono GitHub Actions][gh-image]][gh-checks]
 [![Chrono on crates.io][cratesio-image]][cratesio]
 [![Chrono on docs.rs][docsrs-image]][docsrs]
 [![Join the chat at https://gitter.im/chrono-rs/chrono][gitter-image]][gitter]
 
-[travis-image]: https://travis-ci.org/chronotope/chrono.svg?branch=master
-[travis]: https://travis-ci.org/chronotope/chrono
-[appveyor-image]: https://ci.appveyor.com/api/projects/status/2ia91ofww4w31m2w/branch/master?svg=true
-[appveyor]: https://ci.appveyor.com/project/chronotope/chrono
+[gh-image]: https://github.com/chronotope/chrono/workflows/test/badge.svg
+[gh-checks]: https://github.com/chronotope/chrono/actions?query=workflow%3Atest
 [cratesio-image]: https://img.shields.io/crates/v/chrono.svg
 [cratesio]: https://crates.io/crates/chrono
 [docsrs-image]: https://docs.rs/chrono/badge.svg
@@ -75,14 +72,14 @@ use chrono::prelude::*;
 Chrono currently uses
 the [`time::Duration`](https://docs.rs/time/0.1.40/time/struct.Duration.html) type
 from the `time` crate to represent the magnitude of a time span.
-Since this has the same name to the newer, standard type for duration,
+Since this has the same name as the newer, standard type for duration,
 the reference will refer this type as `OldDuration`.
 Note that this is an "accurate" duration represented as seconds and
 nanoseconds and does not represent "nominal" components such as days or
 months.
 
 Chrono does not yet natively support
-the standard [`Duration`](https://docs.rs/time/0.1.40/time/struct.Duration.html) type,
+the standard [`Duration`](https://doc.rust-lang.org/std/time/struct.Duration.html) type,
 but it will be supported in the future.
 Meanwhile you can convert between two types with
 [`Duration::from_std`](https://docs.rs/time/0.1.40/time/struct.Duration.html#method.from_std)
@@ -93,7 +90,7 @@ methods.
 ### Date and Time
 
 Chrono provides a
-[**`DateTime`**](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html)
+[**`DateTime`**](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html)
 type to represent a date and a time in a timezone.
 
 For more abstract moment-in-time tracking such as internal timekeeping
@@ -104,15 +101,15 @@ which tracks your system clock, or
 is an opaque but monotonically-increasing representation of a moment in time.
 
 `DateTime` is timezone-aware and must be constructed from
-the [**`TimeZone`**](https://docs.rs/chrono/0.4.6/chrono/offset/trait.TimeZone.html) object,
+the [**`TimeZone`**](https://docs.rs/chrono/0.4/chrono/offset/trait.TimeZone.html) object,
 which defines how the local date is converted to and back from the UTC date.
 There are three well-known `TimeZone` implementations:
 
-* [**`Utc`**](https://docs.rs/chrono/0.4.6/chrono/offset/struct.Utc.html) specifies the UTC time zone. It is most efficient.
+* [**`Utc`**](https://docs.rs/chrono/0.4/chrono/offset/struct.Utc.html) specifies the UTC time zone. It is most efficient.
 
-* [**`Local`**](https://docs.rs/chrono/0.4.6/chrono/offset/struct.Local.html) specifies the system local time zone.
+* [**`Local`**](https://docs.rs/chrono/0.4/chrono/offset/struct.Local.html) specifies the system local time zone.
 
-* [**`FixedOffset`**](https://docs.rs/chrono/0.4.6/chrono/offset/struct.FixedOffset.html) specifies
+* [**`FixedOffset`**](https://docs.rs/chrono/0.4/chrono/offset/struct.FixedOffset.html) specifies
   an arbitrary, fixed time zone such as UTC+09:00 or UTC-10:30.
   This often results from the parsed textual date and time.
   Since it stores the most information and does not depend on the system environment,
@@ -120,12 +117,12 @@ There are three well-known `TimeZone` implementations:
 
 `DateTime`s with different `TimeZone` types are distinct and do not mix,
 but can be converted to each other using
-the [`DateTime::with_timezone`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.with_timezone) method.
+the [`DateTime::with_timezone`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.with_timezone) method.
 
 You can get the current date and time in the UTC time zone
-([`Utc::now()`](https://docs.rs/chrono/0.4.6/chrono/offset/struct.Utc.html#method.now))
+([`Utc::now()`](https://docs.rs/chrono/0.4/chrono/offset/struct.Utc.html#method.now))
 or in the local time zone
-([`Local::now()`](https://docs.rs/chrono/0.4.6/chrono/offset/struct.Local.html#method.now)).
+([`Local::now()`](https://docs.rs/chrono/0.4/chrono/offset/struct.Local.html#method.now)).
 
 ```rust
 use chrono::prelude::*;
@@ -166,24 +163,26 @@ assert_eq!(dt, fixed_dt);
 ```
 
 Various properties are available to the date and time, and can be altered individually.
-Most of them are defined in the traits [`Datelike`](https://docs.rs/chrono/0.4.6/chrono/trait.Datelike.html) and
-[`Timelike`](https://docs.rs/chrono/0.4.6/chrono/trait.Timelike.html) which you should `use` before.
+Most of them are defined in the traits [`Datelike`](https://docs.rs/chrono/0.4/chrono/trait.Datelike.html) and
+[`Timelike`](https://docs.rs/chrono/0.4/chrono/trait.Timelike.html) which you should `use` before.
 Addition and subtraction is also supported.
 The following illustrates most supported operations to the date and time:
 
 ```rust
+extern crate time;
+
 use chrono::prelude::*;
 use time::Duration;
 
 // assume this returned `2014-11-28T21:45:59.324310806+09:00`:
-let dt = Local::now();
+let dt = FixedOffset::east(9*3600).ymd(2014, 11, 28).and_hms_nano(21, 45, 59, 324310806);
 
 // property accessors
 assert_eq!((dt.year(), dt.month(), dt.day()), (2014, 11, 28));
 assert_eq!((dt.month0(), dt.day0()), (10, 27)); // for unfortunate souls
 assert_eq!((dt.hour(), dt.minute(), dt.second()), (21, 45, 59));
 assert_eq!(dt.weekday(), Weekday::Fri);
-assert_eq!(dt.weekday().number_from_monday(), 5); // Mon=1, ..., Sat=7
+assert_eq!(dt.weekday().number_from_monday(), 5); // Mon=1, ..., Sun=7
 assert_eq!(dt.ordinal(), 332); // the day of year
 assert_eq!(dt.num_days_from_ce(), 735565); // the number of days from and including Jan 1, 1
 
@@ -210,15 +209,15 @@ assert_eq!(Utc.ymd(1970, 1, 1).and_hms(0, 0, 0) - Duration::seconds(1_000_000_00
 
 ### Formatting and Parsing
 
-Formatting is done via the [`format`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.format) method,
+Formatting is done via the [`format`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.format) method,
 which format is equivalent to the familiar `strftime` format.
 
-See [`format::strftime`](https://docs.rs/chrono/0.4.6/chrono/format/strftime/index.html#specifiers)
+See [`format::strftime`](https://docs.rs/chrono/0.4/chrono/format/strftime/index.html#specifiers)
 documentation for full syntax and list of specifiers.
 
 The default `to_string` method and `{:?}` specifier also give a reasonable representation.
-Chrono also provides [`to_rfc2822`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.to_rfc2822) and
-[`to_rfc3339`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.to_rfc3339) methods
+Chrono also provides [`to_rfc2822`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.to_rfc2822) and
+[`to_rfc3339`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.to_rfc3339) methods
 for well-known formats.
 
 ```rust
@@ -248,23 +247,23 @@ Parsing can be done with three methods:
    ([`std::fmt::Debug`](https://doc.rust-lang.org/std/fmt/trait.Debug.html))
    format specifier prints, and requires the offset to be present.
 
-2. [`DateTime::parse_from_str`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.parse_from_str) parses
+2. [`DateTime::parse_from_str`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.parse_from_str) parses
    a date and time with offsets and returns `DateTime<FixedOffset>`.
    This should be used when the offset is a part of input and the caller cannot guess that.
    It *cannot* be used when the offset can be missing.
-   [`DateTime::parse_from_rfc2822`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.parse_from_rfc2822)
+   [`DateTime::parse_from_rfc2822`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.parse_from_rfc2822)
    and
-   [`DateTime::parse_from_rfc3339`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.parse_from_rfc3339)
+   [`DateTime::parse_from_rfc3339`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.parse_from_rfc3339)
    are similar but for well-known formats.
 
-3. [`Offset::datetime_from_str`](https://docs.rs/chrono/0.4.6/chrono/offset/trait.TimeZone.html#method.datetime_from_str) is
+3. [`Offset::datetime_from_str`](https://docs.rs/chrono/0.4/chrono/offset/trait.TimeZone.html#method.datetime_from_str) is
    similar but returns `DateTime` of given offset.
    When the explicit offset is missing from the input, it simply uses given offset.
    It issues an error when the input contains an explicit offset different
    from the current offset.
 
 More detailed control over the parsing process is available via
-[`format`](https://docs.rs/chrono/0.4.6/chrono/format/index.html) module.
+[`format`](https://docs.rs/chrono/0.4/chrono/format/index.html) module.
 
 ```rust
 use chrono::prelude::*;
@@ -296,23 +295,23 @@ assert!(Utc.datetime_from_str("Fri Nov 28 12:00:09", "%a %b %e %T").is_err());
 assert!(Utc.datetime_from_str("Sat Nov 28 12:00:09 2014", "%a %b %e %T %Y").is_err());
 ```
 
-Again : See [`format::strftime`](https://docs.rs/chrono/0.4.6/chrono/format/strftime/index.html#specifiers)
+Again : See [`format::strftime`](https://docs.rs/chrono/0.4/chrono/format/strftime/index.html#specifiers)
 documentation for full syntax and list of specifiers.
 
 ### Conversion from and to EPOCH timestamps
 
-Use [`Utc.timestamp(seconds, nanoseconds)`](https://docs.rs/chrono/0.4.6/chrono/offset/trait.TimeZone.html#method.timestamp)
-to construct a [`DateTime<Utc>`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html) from a UNIX timestamp
+Use [`Utc.timestamp(seconds, nanoseconds)`](https://docs.rs/chrono/0.4/chrono/offset/trait.TimeZone.html#method.timestamp)
+to construct a [`DateTime<Utc>`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html) from a UNIX timestamp
 (seconds, nanoseconds that passed since January 1st 1970).
 
-Use [`DateTime.timestamp`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.timestamp) to get the timestamp (in seconds)
-from a [`DateTime`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html). Additionally, you can use
-[`DateTime.timestamp_subsec_nanos`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.timestamp_subsec_nanos)
+Use [`DateTime.timestamp`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.timestamp) to get the timestamp (in seconds)
+from a [`DateTime`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html). Additionally, you can use
+[`DateTime.timestamp_subsec_nanos`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.timestamp_subsec_nanos)
 to get the number of additional number of nanoseconds.
 
 ```rust
 // We need the trait in scope to use Utc::timestamp().
-use chrono::TimeZone;
+use chrono::{DateTime, TimeZone, Utc};
 
 // Construct a datetime from epoch:
 let dt = Utc.timestamp(1_500_000_000, 0);
@@ -325,7 +324,7 @@ assert_eq!(dt.timestamp(), 1_500_000_000);
 
 ### Individual date
 
-Chrono also provides an individual date type ([**`Date`**](https://docs.rs/chrono/0.4.6/chrono/struct.Date.html)).
+Chrono also provides an individual date type ([**`Date`**](https://docs.rs/chrono/0.4/chrono/struct.Date.html)).
 It also has time zones attached, and have to be constructed via time zones.
 Most operations available to `DateTime` are also available to `Date` whenever appropriate.
 
@@ -344,26 +343,26 @@ assert_eq!(Utc.ymd(2014, 11, 28).and_hms_milli(7, 8, 9, 10).format("%H%M%S").to_
 
 There is no timezone-aware `Time` due to the lack of usefulness and also the complexity.
 
-`DateTime` has [`date`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.date) method
+`DateTime` has [`date`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.date) method
 which returns a `Date` which represents its date component.
-There is also a [`time`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.time) method,
+There is also a [`time`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.time) method,
 which simply returns a naive local time described below.
 
 ### Naive date and time
 
 Chrono provides naive counterparts to `Date`, (non-existent) `Time` and `DateTime`
-as [**`NaiveDate`**](https://docs.rs/chrono/0.4.6/chrono/naive/struct.NaiveDate.html),
-[**`NaiveTime`**](https://docs.rs/chrono/0.4.6/chrono/naive/struct.NaiveTime.html) and
-[**`NaiveDateTime`**](https://docs.rs/chrono/0.4.6/chrono/naive/struct.NaiveDateTime.html) respectively.
+as [**`NaiveDate`**](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveDate.html),
+[**`NaiveTime`**](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveTime.html) and
+[**`NaiveDateTime`**](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveDateTime.html) respectively.
 
 They have almost equivalent interfaces as their timezone-aware twins,
 but are not associated to time zones obviously and can be quite low-level.
 They are mostly useful for building blocks for higher-level types.
 
 Timezone-aware `DateTime` and `Date` types have two methods returning naive versions:
-[`naive_local`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.naive_local) returns
+[`naive_local`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.naive_local) returns
 a view to the naive local time,
-and [`naive_utc`](https://docs.rs/chrono/0.4.6/chrono/struct.DateTime.html#method.naive_utc) returns
+and [`naive_utc`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html#method.naive_utc) returns
 a view to the naive UTC time.
 
 ## Limitations
@@ -375,7 +374,7 @@ Date types are limited in about +/- 262,000 years from the common epoch.
 Time types are limited in the nanosecond accuracy.
 
 [Leap seconds are supported in the representation but
-Chrono doesn't try to make use of them](https://docs.rs/chrono/0.4.6/chrono/naive/struct.NaiveTime.html#leap-second-handling).
+Chrono doesn't try to make use of them](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveTime.html#leap-second-handling).
 (The main reason is that leap seconds are not really predictable.)
 Almost *every* operation over the possible leap seconds will ignore them.
 Consider using `NaiveDateTime` with the implicit TAI (International Atomic Time) scale
@@ -386,6 +385,10 @@ Any operation that can be ambiguous will return `None` in such cases.
 For example, "a month later" of 2014-01-30 is not well-defined
 and consequently `Utc.ymd(2014, 1, 30).with_month(2)` returns `None`.
 
+Non ISO week handling is not yet supported.
+For now you can use the [chrono_ext](https://crates.io/crates/chrono_ext)
+crate ([sources](https://github.com/bcourtine/chrono-ext/)).
+
 Advanced time zone handling is not yet supported.
 For now you can try the [Chrono-tz](https://github.com/chronotope/chrono-tz/) crate instead.