Commit Graph

418 Commits

Author SHA1 Message Date
vallentin 89da02ebd5 Fixed typos 2020-02-11 21:08:21 +01:00
Brandon W Maister 4837b568c2
Merge pull request #381 from waldyrious/same-to_same-as
Reword 'same to' → 'same as'
2019-12-30 17:17:46 -05:00
Brandon W Maister 9397ab2b47
Merge pull request #375 from dlalic/354
Support comparison between dts with different timezones. Fixes #354
2019-12-30 17:16:06 -05:00
Waldir Pimenta 176dfeff87 Reword 'same to' --> 'same as' 2019-12-29 22:27:59 +00:00
Brandon W Maister b9c967b2ac support round tripping display <-> datetime
This extends `FromStr` to allow either a `T` or a ` ` (space) as the delimiter
between the date and the time, and, because of the fact that the `Z`
parser-specifier is shared with the Fixed notation, extends the fixed notation
to support `UTC` in addition to `Z` as the zero-offset.

IMO this Fixes #147
2019-12-27 13:57:02 -05:00
Brandon W Maister 3b295ccb8f Add doctest for comparison between timestamps with different time_zones 2019-12-27 13:49:53 -05:00
Dunja Lalic ad8644ea57 Fixes #354 2019-12-26 20:32:45 -05:00
Brandon W Maister b9cd0ce803
Merge pull request #270 from asayers/from_ymwd
Construct a NaiveDate by specifying eg. "the 2nd Friday of March 2017"
2019-12-26 20:17:17 -05:00
Brandon W Maister 5d16648df4 rename from_ymwd -> from_weekday_of_month 2019-12-23 17:33:44 -05:00
Brandon W Maister b5015c634b
Merge pull request #348 from gThorondorsen/test-num_days_from_ce
Test `Datelike::num_days_from_ce` against an alternative implementation
2019-12-23 17:19:43 -05:00
Brandon W Maister d9d0728f51
Merge pull request #374 from quodlibetor/fix-playground-and-docs
Change docs and playground features so that it compiles
2019-12-23 14:16:02 -05:00
Gwaihir Thorondorsen 3e592d4565 Test `Datelike::num_days_from_ce` against an alternative implementation 2019-12-23 13:28:46 -05:00
Brandon W Maister 5ca6ff5afc Make it harder to accidentally use private features
In particular if built with `--all-features` or `features = "all"` we don't
want to accidentally make it look like `YearFlags` are something that people
should use. So: hide it from docs and put it behind a dunder.
2019-12-23 13:26:05 -05:00
Brandon W Maister 977ad60391 allow_deprecated on stub Error::description for rust 1.13 2019-12-23 12:38:25 -05:00
Andrii Radyk a42c5b22cd remove deprecated Error::description 2019-12-17 09:42:32 +01:00
Brandon W Maister df0e6ae8f6
Merge pull request #370 from quodlibetor/rfc2822-is-http-and-email
Document that rfc2822 is what is used for http and email headers
2019-11-30 19:46:05 -05:00
Brandon W Maister 495243ae3c
Merge pull request #369 from quodlibetor/finish-criterion
Finish moving all benchmarks to criterion
2019-11-30 19:45:37 -05:00
Brandon W Maister 7a1cd09b86 Document that rfc2822 is what is used for http and email headers
Closes #328
2019-11-30 18:25:36 -05:00
Brandon W Maister 4f1c35827f Finish moving all benchmarks to criterion
I didn't delete some, apparently, and an internal struct had to be made public
to get its benchmark to work.
2019-11-30 18:11:03 -05:00
Brandon W Maister b10e430b1f
Merge pull request #368 from quodlibetor/support-negative-utc-in-rfc2822
Support -0000 as a valid UTC tz in rfc2822
2019-11-30 17:59:22 -05:00
Brandon W Maister b553798f86 Support -0000 as a valid UTC tz in rfc2822
This is a time that is commonly set in some environments, and RFC 5322
explicitly clarifies that we should treat -0000 as UTC[1][2] when interpretting
rfc2822.

Fixes #102

[1]: https://github.com/chronotope/chrono/issues/102#issuecomment-557846931
[2]: https://tools.ietf.org/html/rfc5322#section-3.3
2019-11-30 16:48:35 -05:00
coolreader18 c5973277e7
Don't do wasmbind on wasi 2019-11-26 23:57:51 -06:00
Brandon W Maister 41700d101e Remove unused constant, deny(dead_code) 2019-11-23 19:58:20 -05:00
Brandon W Maister 5b4fc23bcb
Merge pull request #360 from quodlibetor/chrono-0_4_10
Prepare for and Bump Chrono version to 0.4.10
2019-11-23 19:53:58 -05:00
Brandon W Maister 288f1dd76f
Merge pull request #356 from quodlibetor/num_days_from_epoch-docs
Remove num_days_from_epoch
2019-11-23 19:29:23 -05:00
Brandon W Maister 6622bdcae7 Replace all uses of `try!` with question mark
The `?` operator was stabilized in 1.13, this gets rid of a few hundred
deprecation warnings.

Fixes #357
2019-11-23 19:18:08 -05:00
Brandon W Maister b717e0442c Handle some semantic merge conflicts
Something that wasn't part of this PR: the work to support nested
`Option<[ChronoType]>` was merged without being adjusted for the no-std
support

And now there are some unused import warnings because they need to get
configged out.
2019-11-23 18:38:38 -05:00
Brandon W Maister 27f5e5e9b3 Temporarily globally allow deprecated
The question mark will be fixed in a pending commit
2019-11-23 18:22:40 -05:00
Michal Srb 0b8c248791 Fix build with rust 1.13.0 2019-11-23 23:34:59 +01:00
Michal Srb a716b48e9d Inline some parse related functions
Speedups:
 datetime::tests::bench_datetime_from_str             365                         337                       -28   -7.67%   x 1.08
 datetime::tests::bench_datetime_parse_from_rfc2822   195                         181                       -14   -7.18%   x 1.08
 datetime::tests::bench_datetime_parse_from_rfc3339   166                         142                       -24  -14.46%   x 1.17
2019-11-23 23:34:59 +01:00
Michal Srb 6da5359d39 Reimplement scan::number
The original would first check that there is right amount of numeric
characters and then parsed them using the std::str::parse, which
internally checks the characters again and also checks for -/+ prefix,
which is not necessary in this case.

Since we are already going over the characters, we may as well do the
parsing ourselves. The length of the function is roughly the same and
it is faster:

 name                                                 simplify-from-str ns/iter  reimplement-number ns/iter  diff ns/iter   diff %  speedup
 datetime::tests::bench_datetime_from_str             448                        365                                  -83  -18.53%   x 1.23
 datetime::tests::bench_datetime_parse_from_rfc2822   242                        195                                  -47  -19.42%   x 1.24
 datetime::tests::bench_datetime_parse_from_rfc3339   234                        166                                  -68  -29.06%   x 1.41
2019-11-23 23:34:59 +01:00
Michal Srb f7318277e2 Simplify ITEMS in FromStr implementations
The Item::Space calls str::trim_left and Item::Numeric also calls
str::trim_left before doing anything else, so there is no need to
have Item::Space before Item::Numeric.

Speeds up parsing:
 name                                                 remove-cloned ns/iter  simplify-from-str ns/iter  diff ns/iter   diff %  speedup
 datetime::tests::bench_datetime_from_str             582                    448                                -134  -23.02%   x 1.30
 datetime::tests::bench_datetime_parse_from_rfc2822   244                    242                                  -2   -0.82%   x 1.01
 datetime::tests::bench_datetime_parse_from_rfc3339   239                    234                                  -5   -2.09%   x 1.02
2019-11-23 23:34:59 +01:00
Michal Srb 05acc869b9 Accept Borrow<Item> as items
The parse::parse and format::format functions accepted Iterator of owned
Items. While it is sometimes convenient to pass in the owned values,
neither of the functions really need to own them, so references would
be enough. The Borrow trait allows us to pass in Iterator over values,
references, boxes, etc.

According to RFC 1105 this is a minor change, because it shouldn't break
any existing code. And chrono is in pre-1.0 version anyway.

This allows us to remove multiple cloned() calls which speeds up parsing
and formating:

 name                                                 control ns/iter  remove-cloned ns/iter  diff ns/iter   diff %  speedup
 datetime::tests::bench_datetime_from_str             712              582                            -130  -18.26%   x 1.22
 datetime::tests::bench_datetime_parse_from_rfc2822   252              244                              -8   -3.17%   x 1.03
 datetime::tests::bench_datetime_parse_from_rfc3339   242              239                              -3   -1.24%   x 1.01
2019-11-23 23:34:59 +01:00
Michal Srb 53ef941c3a Add benchmarks for DateTime parsing and formatting 2019-11-23 23:34:59 +01:00
Michal Srb db8784f97c Fix existing benchmarks
The #[cfg(bench)] attribute does not exist and is always false. Lets
define a feature "bench" which can be used to enable benchmarks when
building with nightly.
2019-11-23 23:34:59 +01:00
Brandon W Maister d9929a60b4
Merge pull request #341 from CryZe/no-std
Implement Support for no_std
2019-11-22 16:53:09 -05:00
Brandon W Maister 3d385fe2ce
Merge pull request #302 from manifest/feature/option
Add Serialize/Deserialize for Option<DateTime>
2019-11-22 16:07:09 -05:00
Brandon W Maister 64a28d6812 Remove core_only, cfg-out the `format::Item::Owned*` variants
This means that a few more features of formatting items don't compile in
non-alloc environments, but they wouldn't have worked correctly anyway.
2019-11-22 15:27:10 -05:00
Brandon W Maister 6a2adc45b7 Use markdown footnotes in strftime docs 2019-11-22 11:30:10 -05:00
Brandon W Maister a74a9744f1 Remove num_days_from_epoch
Deciding between zero-indexed (slightly more reasonable, more compatible with
the outside world) and one-indexed (same indexing as `num_days_from_ce`) seems
not worth it. It's trivial to build `num_days_from_epoch` based on the docs in
`num_days_from_ce`, which punts on the decision and is therefor probably the
right decision.
2019-11-16 16:48:47 -05:00
Gwaihir Thorondorsen bfdef11d0b Clarify documentation of `num_days_from_ce` methods
The new wording tries to make clearer that those methods use a 1-based
numbering scheme.

This commit also includes a couple of drive-by cosmetic changes.
2019-10-08 19:04:43 +02:00
Brandon W Maister 911dc57402 support rust v1.13.0 struct initialization syntax 2019-09-20 11:41:23 -04:00
Brandon W Maister a09f9ba2a8 Test against serde with no features in both std and no-std 2019-09-20 10:50:28 -04:00
Brandon W Maister 505db4504d Add Datelike::num_days_from_epoch 2019-09-18 17:48:39 -04:00
Brandon W Maister e5bbc94c3b First pass at making "alloc" its own feature
Part of this means that we don't actually need to allocate to write to Serde
any more, which is a win in its own right.
2019-09-15 20:45:49 -04:00
Brandon W Maister 4027bbb66d Rename serde-1 back to serde 2019-09-13 14:49:41 -04:00
Christopher Serr e62a054cd9 Introduce an `alloc` feature 2019-09-09 13:51:10 +02:00
Christopher Serr 9dc91f78ed Implement Support for no_std
This adds a new `std` feature to chrono that is enabled by default. By
deactivating this feature via `default-features = false` you can now use
chrono in applications that don't use the standard library. The `serde`
feature is supported as well.

Resolves #336
2019-09-07 12:12:49 +02:00
Brandon W Maister c045750e06
Merge pull request #335 from chronotope/fix-wasm
Put wasm-bindgen and js-sys behind a wasm-bindgen feature gate
2019-09-03 22:12:39 -04:00
Brandon W Maister 2839d8d7db Put wasm-bindgen and js-sys behind a wasm-bindgen feature gate
Fixes #334
2019-09-03 09:05:15 -04:00