Commit Graph

100 Commits

Author SHA1 Message Date
Waldir Pimenta 176dfeff87 Reword 'same to' --> 'same as' 2019-12-29 22:27:59 +00: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
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
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 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 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 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 c06bc01f0b
Flattened intermediate implementation modules.
There used to be multiple modules like `chrono::datetime` which only
provide a single type `DateTime`. In retrospect, this module structure
never reflected how people use those types; with the release of 0.3.0
`chrono::prelude` is a preferred way to glob-import types, and due to
reexports `chrono::DateTime` and likes are also common enough.

Therefore this commit removes those implementation modules and
flattens the module structure. Specifically:

    Before                              After
    ----------------------------------  ----------------------------
    chrono:📅:Date                  chrono::Date
    chrono:📅:MIN                   chrono::MIN_DATE
    chrono:📅:MAX                   chrono::MAX_DATE
    chrono::datetime::DateTime          chrono::DateTime
    chrono::datetime::TsSeconds         chrono::TsSeconds
    chrono::datetime::serde::*          chrono::serde::*
    chrono::naive::time::NaiveTime      chrono::naive::NaiveTime
    chrono::naive:📅:NaiveDate      chrono::naive::NaiveDate
    chrono::naive:📅:MIN            chrono::naive::MIN_DATE
    chrono::naive:📅:MAX            chrono::naive::MAX_DATE
    chrono::naive::datetime::NaiveDateTime
                                        chrono::naive::NaiveDateTime
    chrono::naive::datetime::TsSeconds  chrono::naive::TsSeconds
    chrono::naive::datetime::serde::*   chrono::naive::serde::*
    chrono::offset::utc::UTC            chrono::offset::UTC
    chrono::offset::fixed::FixedOffset  chrono::offset::FixedOffset
    chrono::offset::local::Local        chrono::offset::Local
    chrono::format::parsed::Parsed      chrono::format::Parsed

All internal documentation links have been updated (phew!) and
verified with LinkChecker [1]. Probably we can automate this check
in the future.

[1] https://wummel.github.io/linkchecker/

Closes #161. Compared to the original proposal, `chrono::naive` is
retained as we had `TsSeconds` types duplicated for `NaiveDateTime`
and `DateTime` (legitimately).
2017-06-21 14:03:49 +09:00
Brandon W Maister 4e7b84064f re-add TsSeconds for RustcDecodable
I think it's a terrible API, but AFAIK rustc-serialize doesn't support anything
like serde's `with` attribute.

I think it would be better to just not include this API at all and require that
people who want to use this move to serde, which is the recommended rust
encoding/decoding library.
2017-06-21 03:39:39 +09:00
Brandon W Maister 44fc13d7df Use serde's serialize_with instead of a newtype
This is a significantly less horrible API than in the previous commit.
2017-06-21 03:39:39 +09:00
Brandon W Maister bc879d705e Deserialize both Serde and Serialize from timestamps
This introduces a newtype around DateTime and NaiveDateTime that deserlization
is implemented for.

There are two advantages to this over the previous implementation:

* It is expandable to other timestamp representations (e.g. millisecond and
  microsecond timestamps)
* It works with RustcSerialize::Decodable. AFAICT Decodable will error if you
  try to call more than one of the `read_*` functions in the same `decode`
  invocation. This is slightly annoying compared to serde which just calls the
  correct `visit_*` function for whatever type the deserializer encounters.

On the whole I think that I prefer this to the previous implementation of
deserializing timestamps (even though I don't care about RustcSerialize in the
post-1.15 world) because it is much more explicit.

On the other hand, this feels like it's introducing a lot of types, and
possibly making downstream crates introduce a variety of different structs for
ser/de and translating into different struct types.
2017-06-21 03:39:39 +09:00
Brandon W Maister c0c61b5bfa Add the ability for serde to deserialize timestamps
Timestamps are defined in terms of UTC, so what this does is, if we encounter
an integer instead of a str, create a FixedOffset timestamp with an offset of
zero and create the timestamp from that.
2017-06-21 03:39:39 +09:00
Ashley Mannix 1d1bfd93da remove unneeded hrtb 2017-04-24 07:17:37 +10:00
Ashley Mannix 5504f6c854 optimise serialize 2017-04-21 21:31:50 +10:00
Ashley Mannix 80c3582531 upgrade to serde 1.0 2017-04-21 21:12:26 +10:00
Kang Seonghoon 1583df95b5
Upgrade bincode dev-dependency to >=1.0.0-alpha6.
The test depends on the bincode API changed at that version.
2017-04-19 00:34:10 +09:00
Kang Seonghoon d036c07370
Bincode 1.0.0-alpha2 no longer has the `bincode::serde` module. 2017-02-14 03:28:14 +09:00
Kang Seonghoon e9e7bdd99c
Removed older aliases (previously marked as deprecated).
The intention was to add newer methods using `std::time::Duration`
to the older names, but it will break the API compatibility anyway.
Better to completely remove them right now.
2017-02-07 04:51:08 +09:00
Kang Seonghoon 36c45f2e02 Removed methods deprecated in 0.2. 2017-02-07 03:13:55 +09:00
Kang Seonghoon c118a3985f
Serialization cleanup for 0.3.
- Rustc-serialize now uses the same serialization format as Serde.
  This also means that the older format (naturally derived from
  the internals) is no longer supported.

- Serialization support only existed for rustc-serialize has been
  (temporarily) removed. This affects `Date<Tz>` and all individual
  time zone types. This does *not* affect `DateTime<Tz>` as it has
  individual support per `Tz`.

  Please note that this is considered a temporary solution to avoid
  stabilizing diverging implementations. Their implementations will
  likely be reintroduced later.
2017-02-07 03:08:01 +09:00