Commit Graph

101 Commits

Author SHA1 Message Date
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 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 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 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 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
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 6ce91fbfbb allow deprecated inclusive range patterns
We still support ancient Rust.
2019-08-31 15:40:11 -04:00
Brandon W Maister b1592e0e22 Add parse tests for fws and leading-0 to RFC2822 2019-06-24 22:05:06 -04:00
wyhaya a1d304b035 Add '0' to RFC2822 2019-06-24 22:05:06 -04:00
Samokhin Ilya 5b0818e0a1 changed back from impl Trait in fn parameter to support older compiler versions 2019-06-23 10:09:47 +03:00
Samokhin Ilya f57ac3671e add test and format every item into String first, then pad it 2019-06-23 09:43:06 +03:00
SamokhinIlya 8b2444c27f DelayFormat now works with alignment and width 2019-06-21 23:44:49 +03:00
Brandon W Maister 855a894393 Don't warn on deprecated trim functions 2019-03-31 19:03:18 -04:00
Brandon W Maister df4912a33f Test formatting with more precise nanoseconds
There is some specific behavior around writing out truncated nanos that we want
to be sure to preserve.
2018-06-13 23:00:31 -04:00
Evan Schwartz 11cfb3696e Move NanosecondXNoDot to internal enum
To avoid adding new variants to the public enum (see https://github.com/chronotope/chrono/pull/251#issuecomment-396692148)
2018-06-12 14:53:49 -04:00
Evan Schwartz 937189ee52 Take exactly num digits specified for nanosecond fixed
Error if it's too long or short, and don't take any more digits
2018-06-12 10:51:38 -04:00
Evan Schwartz 8a2b09962a Only parse up to max number of digits for nanoseconds w/o dots 2018-06-12 10:51:38 -04:00
Evan Schwartz 074e92fc63 Document millisecond format without the dot 2018-06-12 10:51:36 -04:00
Evan Schwartz f9d3094d4e Test nanosecond parsing without the dot 2018-06-12 10:51:07 -04:00
Evan Schwartz 1de3658433 Add nanoseconds without dots 2018-06-12 10:51:07 -04:00
Brandon W Maister c3207a5811 Use the `InternalFixed` struct for TimezoneOffsetPermissive
It is the backcompat scheme that we have. In the 5.x timeline we will add the
more-standard and significantly-more-pleasant-to-expand `#[doc(hidden)]
__DoNotMatchAgainstMe` trick.
2018-06-07 21:46:57 -04:00
Brandon W Maister 9991c2b0ed Rust 1.13 does not support elided lifetimes in const. 2018-06-07 21:46:57 -04:00
Brandon W Maister 95f6a2be1c Add %#z as "Permissive" timezone parsing
This allows you to parse a timezone that:

* Is either `Z` or an actual offset
* Contains no minutes, just the hour

Fixes #219
2018-06-07 21:46:57 -04:00
Philipp Hansch 3fb0b614e8
Revert "Allow a false-positive clippy lint"
The issue has been fixed with the latest clippy release and we don't
have to `allow` anymore.

This reverts commit 7f990144cc.
2018-04-01 12:40:14 +02:00
Brandon W Maister 2a825edd5c
Merge pull request #221 from cuviper/num-no_std
Use no_std-compatible num dependencies
2018-03-04 18:21:50 -05:00
Brandon W Maister 7f990144cc Allow a false-positive clippy lint
rust-lang-nursery/rust-clippy#2475 , we'll revert this commit when that's
fixed.
2018-03-04 09:51:41 -05: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
kennytm 8a6a99018a
Fix a markdown rendering difference warning.
Rust is going to change its Markdown rendering engine from hoedown to
pulldown-cmark. In pulldown, a table row starting with just whitespaces
will cause that whole cell disappeared. This causes rendering difference
between the two engines.

To fix this, we add leading and trailing `|` to the rows so that empty
cells are correctly rendered.
2018-01-22 02:34:15 +08:00
Brandon W Maister 5bb493976b Add a note and example to DateTime::parse_from_str
The note points out that `NaiveDateTime::parse_from_str` is required if you
don't know the offset, and the example demonstrates that.

Closes #183
2017-10-09 21:23:22 -04: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
Xidorn Quan 0eeb4746f2 fix rfc2822 parsing to allow omitting second 2017-09-19 21:52:07 +10:00
Jonas Bushart 5124c0c324 Fix Allow parsing of timestamps with additional subsecond precision
Fixes https://github.com/chronotope/chrono/issues/175
2017-07-14 11:32:15 +02:00
Brandon W Maister ce6ea4d8d1 deny(missing_debug_implementations) 2017-07-09 15:23:07 -05:00
Brandon W Maister 330504792b Fix Clippy lints: match_same_arms 2017-07-09 15:10:26 -05:00
Brandon W Maister 0dc4e3a416 Fix Clippy lints: type_complexity 2017-07-09 15:10:26 -05:00
Brandon W Maister 96b31283d0 Fix Clippy lints: if_same_then_else 2017-07-09 15:10:26 -05:00
Brandon W Maister 4a70e160fb Fix Clippy lints: or_fun_call 2017-07-09 15:10:26 -05:00
Brandon W Maister fd6036a8b9 Fix Clippy lints: assign_op_pattern 2017-07-09 15:10:26 -05:00
Brandon W Maister fac6ff44c9 Fix Clippy lints: needless_return 2017-06-24 13:12:33 -05:00
Kang Seonghoon 72c1752068
Much more complete explanation for the `chrono::format` module.
Fixes #131, I hope!
2017-06-22 00:55:23 +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
Kang Seonghoon c86f5924b0
Limited what `.parse::<Weekday>()` parses to match with scanning.
Amends #113.
2017-05-02 02:31:02 +09:00
Kang Seonghoon 7b17d68474 Fixed warnings in the nightly. 2017-02-07 05:51:56 +09:00