Commit Graph

386 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 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
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
Brandon W Maister 371cf6d29b Adjust timezones after doing Duration addition
The internal, tz-independent timestamp was valid, but since the timezone offset
could change as you add or subtract a second or two you would get
nonsense/nonexistent times when you observed them.

Fixes #318
2019-09-02 14:58:54 -04:00
Brandon W Maister 6ce91fbfbb allow deprecated inclusive range patterns
We still support ancient Rust.
2019-08-31 15:40:11 -04:00
eV cc073a650f remove cargo web / compile time error 2019-08-22 08:09:56 +00:00
eV f21b1fbf21 Fix emscripten and guard against cargo test + wasm32-unknown-unknown 2019-08-16 22:46:10 +00:00
eV 5d38faeb40 fix local timezone, add tests 2019-08-16 09:35:56 +00:00
Joey Ezechiels 8bfaca9f9b Add {Utc,Local}::now() constructor versions for the `wasm32` arch
While likely providing only incomplete support for WebAssembly, this
commit opens up chrono for use on the wasm32 architecture.
2019-08-16 07:46:02 +00:00
Brandon W Maister 7412469623
Merge pull request #325 from chronotope/double-check-negative-odd-timestamp-millis
Add a test for negative odd-numbered timestamp_millis
2019-08-06 21:25:35 -04:00
Lane Kolbly c80878ce4e Change src/lib rather than readme directly 2019-07-18 07:37:37 -05:00
Brandon W Maister f0ea789a9c Add a test for negative odd-numbered timestamp_millis
Just in case, because of #324
2019-06-27 20:40:35 -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
Guillaume Gomez b7003373f2 Add doc-comment to test README examples and fix README examples 2019-04-30 23:29:57 +02:00
kennytm 20a0ab7a47
Mark `FixedOffset::{local_minus_utc, utc_minus_local}` as `#[inline]`. 2019-04-22 03:07:01 +08:00
kennytm d3dc9c0e10
derive {Copy, Eq, Hash} for LocalResult. 2019-04-21 15:42:11 +08:00
Brandon W Maister bcdc66a4f8
Merge pull request #271 from mqudsi/offset_convert
Add std::convert::From conversion between different DateTime offsets
2019-04-08 12:37:01 -04:00
Mahmoud Al-Qudsi ad6872c498 Predicate `Local` conversion fns on `clock` feature 2019-04-08 10:06:30 -05:00
Brandon W Maister 97cc89e1fa Merge remote-tracking branch 'origin/master' into feature/option 2019-04-07 17:54:08 -04:00
Brandon W Maister 5dc8a68dde
Merge pull request #308 from jean-airoldie/time_zone_from_nanos
Add timestamp_nanos generated method for TimeZone
2019-04-07 17:41:52 -04:00
Brandon W Maister 855a894393 Don't warn on deprecated trim functions 2019-03-31 19:03:18 -04: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
jean-airoldie c92544923d Add timestamp_nanos generated method for TimeZone 2019-03-06 10:32:40 -05:00
Andrei Nesterov 662c76294b
Add Serialize/Deserialize for Option<DateTime> 2019-01-27 09:17:42 -08:00
Casey Marshall b39597f537 Fix panic for negative inputs to timestamp_millis.
This patch fixes the case where a negative millisecond offset is passed
to Timezone::timestamp_millis and timestamp_millis_opt and adds a test
case for it. Without this patch, calling timestamp_offset with a
negative value will panic with an overflow like this:

```
---- tests::test_parse_samples stdout ----
thread 'tests::test_parse_samples' panicked at 'attempt to multiply with
overflow',
/home/c/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.6/src/offset/mod.rs:349:34
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a
verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing:👿:unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:221
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:477
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:391
   6: rust_begin_unwind
             at libstd/panicking.rs:326
   7: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   8: core::panicking::panic
             at libcore/panicking.rs:52
   9: chrono::offset::TimeZone::timestamp_millis_opt
             at
/home/c/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.6/src/offset/mod.rs:349
  10: chrono::offset::TimeZone::timestamp_millis
             at
/home/c/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.6/src/offset/mod.rs:327
```
2018-12-02 11:26:42 -06:00
Brandon W Maister 5dc483990a
Merge pull request #282 from 3point2/doc-grammar
Grammar fix for docs
2018-11-26 23:23:36 -05:00
Vasili Revelas 8abaae199e Grammar fix for docs 2018-10-27 13:09:32 +03:00
Pascal Bach fd22be2c8f Correct link to standard Durtation
The link mentioning standard Duration was still linking to the
Duration from the time crate
2018-10-09 23:19:59 +02:00
Mahmoud Al-Qudsi 973c603d7a Add basic conversion test 2018-09-05 19:08:46 -05:00