Commit Graph

136 Commits

Author SHA1 Message Date
vallentin 89da02ebd5 Fixed typos 2020-02-11 21:08:21 +01:00
Waldir Pimenta 176dfeff87 Reword 'same to' --> 'same as' 2019-12-29 22:27:59 +00: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 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 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
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 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
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 a09f9ba2a8 Test against serde with no features in both std and no-std 2019-09-20 10:50:28 -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 33800c876b Add docs around panic behavior around timestamp_nanos
Document panic behavior that should have been documented better.

Resolves #310
2019-03-31 19:03:18 -04:00
Alex Sayers 892bbf3f3a Add NaiveDate::from_ymwd_opt, implement from_ymwd in terms of it 2018-08-13 11:29:02 +09:00
Alex Sayers 4ffd411654 Add NaiveDate::from_ymwd
This contructor allows you to make a NaiveDate by specifying eg. "the
2nd Friday of March 2017".  It contains a couple of panics, but these
are consistent with the behaviour of the other NaiveDate constructors.
2018-08-13 11:29:02 +09:00
Brandon W Maister 369ce72987
Merge pull request #252 from quodlibetor/negative-timestamps
Add doctests around negative timestamps
2018-07-28 17:07:04 -04:00
Brandon W Maister a58a833324 Add doctests for negative timestamps 2018-07-28 16:40:26 -04:00
novacrazy 4a66b17bd0 Add docs/tests and fix math 2018-07-04 14:12:36 -05:00
novacrazy 5df91c3985 Add WIP millisecond serde implementation 2018-07-04 10:38:39 -05:00
Thomas Bytheway cc613976a4 Add functions to present DateTime in nanoseconds since epoch 2018-05-18 11:04:39 +01:00
Brandon W Maister ebd16f49d2
Merge pull request #237 from tobz1000/datetime-diff-sub
impl Sub<T> for T for Date/Time types
2018-04-03 19:30:15 -07:00
Toby Dimmick 19466e6ff4 Move `SubAssign<OldDuration> next to `Sub<OldDuration` 2018-04-03 14:16:37 +01:00
Toby Dimmick d9a50cb767 Documentation 2018-04-03 14:14:52 +01:00
Toby Dimmick d5d5fd92b7 impl Sub<T> for <T> for Date/Time types 2018-04-03 13:42:03 +01:00
Brandon W Maister 39ca2e622c Deprecated warnings in cargo output for rustc-serialize feature
Unfortunately due to rust-lang/rust#39935 placing the annotation on the `impl`s
of `Encodable`/`Decodable` for the various items have no effect whatsoever, so
we need to place it on some type that chrono actually uses internally. The only
*type* that I can find that only exists for rustc-serialize only is the
 `TsSeconds` struct.

So, marking TsSeconds deprecated causes Chrono's internal uses of `TsSeconds`
to emit deprecation warnings, both in our builds and for packages that specify
Chrono as a dependency with the `rustc-serialize` feature active. This means
that the current commit will cause a `warning: use of deprecated item:
RustcSerialize will be removed before chrono 1.0, use Serde instead` to appear
in `cargo build` output.

Unfortunately I don't think that it's possible for downstream crates to disable
the warning the warning in any way other than actually switching to Serde or
using an older chrono. That's the reason for all the `#[allow(deprecated)]`
through the code, it means that the warning appears almost exactly once,
instead of dozens of times.
2018-03-29 14:32:39 -04:00
Josh Stone 8f90f405d5 Use no_std-compatible num dependencies
Rather than the `num` meta-crate, use `num-integer` and `num-traits`
without default features to make them `#[no_std]`.  `num-iter` is
just a dev-dependency now for a few test cases.

The only public change is the `impl FromPrimitive for Weekday`, but this
is still the same exact trait that `num` re-exports, so this is not a
breaking change.
2018-02-23 00:07:16 -08:00
Brandon W Maister c3fa1b5f17 Fix Clippy lints: cast_lossless
Now (assuming clippy is right) all (~100) uses of ` as ` in the code are
actually doing casts that could potentially silently lose data. Woooo?

At least this means that new `as`s can be extra-scrutinized, and we should
probably be adding debug_assert!s for the casts in real code.
2017-10-08 18:12:20 -04:00
Brandon W Maister 268be10d79 Fix Clippy lints: unreadable_literal and inconsistent_digit_grouping
Use `_` consistently in long numeric literals.
2017-10-08 17:38:41 -04:00
Jonas Bushart 4eacc1416e Additional tests which test parsing of %s in combination with %f/%.3f/... 2017-07-15 16:27:56 +02:00
Brandon W Maister d99304145b Add `timestamp_millis` method to DateTime and NaiveDateTime
Fixes #151
2017-07-09 16:31:06 -05:00
Brandon W Maister ce6ea4d8d1 deny(missing_debug_implementations) 2017-07-09 15:23:07 -05:00
Brandon W Maister 5643b845a5 Allow Clippy lint: derive_hash_xor_eq
The implementation is identical to how #[derive] would do it, and we use the
implementation to add some documentation warning people not to use items with
nanosecond-level precision in hash maps unless they're sure that's what they
want.
2017-07-09 15:23:06 -05:00
Brandon W Maister 4c18d701ca Allow Clippy lint: cyclomatic complexity
Honestly this function is pretty clear, breaking it up makes it seem worse.
2017-07-09 15:10:26 -05:00
Brandon W Maister 3e6e0e51c6 Fix Clippy lints: doc_markdown 2017-07-09 15:10:26 -05:00
Brandon W Maister ed8f406a61 Fix Clippy lints: redundant_closure 2017-07-09 15:10:26 -05:00
Brandon W Maister 4ca861c905 Fix Clippy lints: should_assert_eq 2017-07-09 15:10:26 -05:00
Brandon W Maister 853154b239 Only create naive TsSeconds if rustc-serialize is enabled 2017-06-24 13:12:33 -05:00
Brandon W Maister 3c058086e2 Update serde docs 2017-06-21 13:24:30 -05:00
Kang Seonghoon fe529c8016
0.4.0: Mass renaming, `IsoWeek`, `SystemTime` supports, serde utils.
Starting from this version the `CHANGELOG.md` file is the canonical
source for the list of significant changes. See the file for details.

Fixes #146.
Fixes #159.
2017-06-22 02:59:46 +09:00
Kang Seonghoon 8ea2d3f236
Merge branch 'master' into naive_assign 2017-06-22 01:12:18 +09:00
Kang Seonghoon c3c34da141
Clarified that time arithmetic notations are for explanation only.
Also fixes yet another remaining broken anchor links.

Fixes #136.
2017-06-22 00:40:48 +09:00
Kang Seonghoon 7b9b0c4437
Renamed `chrono::UTC` to `chrono::Utc`.
Fixes #148.
2017-06-22 00:33:17 +09:00
Kang Seonghoon 9768b289f0
New type: `chrono::naive::IsoWeek`.
This removes `Datelike::isoweekdate` in favor of `Datelike::iso_week`.
The original `isoweekdate` was not named in accordance with the style
guide and also used to return the day of the week which is already
provided by `Datelike::weekday`. The new design should be more
reasonable.

Note that we initially do not implement any public constructor for
`IsoWeek`. That is, the only legitimate way to get a new `IsoWeek` is
from `Datelike::iso_week`. This sidesteps the issue of boundary values
(for example the year number in the maximal date will overflow in
the week date) while giving the same power as the original API.

Partially accounts for #139. We may add additional week types
as necessary---this is the beginning.
2017-06-22 00:21:24 +09:00
Kang Seonghoon 42a7c8e589
Fixed more documentation links.
Linkchecker recognizes the distinction between internal and external
links (which are not checked by default), and considers URLs which
does not have the starting URL base as a prefix internal...

This commit has been verified against a proper set of options to
Linkchecker, but there are several false positives (for our purposes)
which would make the automated checking not as effective. </rant>
2017-06-21 21:58:42 +09:00
Kang Seonghoon 4f51ab0281
Moved `chrono::naive:📅:internals` into its own file. 2017-06-21 21:20:35 +09:00