Commit Graph

56 Commits

Author SHA1 Message Date
Waldir Pimenta 176dfeff87 Reword 'same to' --> 'same as' 2019-12-29 22:27:59 +00: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 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
Michal Srb 0b8c248791 Fix build with rust 1.13.0 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 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 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
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
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 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 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 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
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
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 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
Kang Seonghoon 41d5584900 Merge pull request #114 from tredoe/patch-1
Update mod.rs
2017-02-07 04:12:02 +09:00
Kang Seonghoon 0ac41c70b1
Minor additions to formatting items.
- Formatting item types are no longer `Copy`.

- `Numeric` and `Fixed` items now have `Internal` variants reserved
  for the future expansion. It had been hard to expand the items
  without totally breaking the backward compatibility (as per
  the API evolution guideline of RFC 1105).

- `Item::Owned{Literal,Space}` for the owned variant of
  `Item::{Literal,Space}` has been added.

Closes #76.
2017-02-07 04:05:05 +09:00
Kang Seonghoon 7ea1ce5080
`FixedOffset` is now the official "fixed offset value" type.
This may sound strange, but the final type for the offset "value" was
originally `time::Duration` (returned by `Offset::local_minus_utc`).
This caused a lot of problems becaus adding `Duration` fully interacts
with leap seconds and `Duration` itself is somewhat deprecated.

This commit entirely replaces this role of `Duration` with
`FixedOffset`. So if we had `Offset` and `Duration` to represent
the "storage" offset type and the offset "value" in the past,
we now have `Offset` and `FixedOffset`. Storage-to-value conversion is
called to "fix" the offset---an apt term for the type.

The list of actual changes:

- The time zone offset is now restricted to UTC-23:59:59 through
  UTC+23:59:59, and no subsecond value is allowed. As described above,
  `FixedOffset` is now fully used for this purpose.

- One can now add and subtract `FixedOffset` to/from timelike values.
  Replaces a temporary `chrono::offset::add_with_leapsecond` function.
  Datelike & non-timelike values are never affected by the offset.

- UTC and local views to `Date<Tz>` are now identical. We keep
  relevant methods for the consistency right now.

- `chrono::format::format` now receives `FixedOffset` in place of
  `(Old)Duration`.

- `Offset` now has a `fix` method to resolve, or to "fix" the
  "storage" offset (`Offset`) to the offset "value" (`FixedOffset`).

- `FixedOffset::{local_minus_utc, utc_minus_local}` methods are added.
  They no longer depend on `Duration` as well.
2017-02-07 03:43:59 +09:00
Kang Seonghoon c63ef14734
`time::Duration` is no longer the sole duration type described.
Due to the backward compatibility we won't be going to remove support
for `time::Duration` in 0.3, and the initial 0.3.0 release won't have
proper `std::time::Duration` support (haven't finalized the logics).
However we will reserve proper names and signatures for the upcoming
`std::time::Duration` support---the "older" duration type will be
referred as "signed" in the names.

- Added a `chrono::prelude` module. This does not have the (old)
  `Duration` type reexported, so the documentation has now correctly
  replaced all occurrences of `chrono::Duration`. The existing
  `chrono::Duration` reexport itself remains for the compatibility.

- Avoided using a plain `Duration` type in the signature, to avoid
  any ambiguity.

- Renamed `checked_{add,sub}` to `checked_{add,sub}_signed`.

- Subtraction operator between two instants has been removed and
  replaced with `signed_duration_since`. This follows the naming
  chosen by `std::time::SystemTime` etc., and the version for newer
  `std::time::Duration` will be named to `duration_since`.
2017-02-06 09:39:32 +09:00
Kang Seonghoon de4df91421
Removed all remaining mentions of rust-chrono (very old name). 2017-02-06 06:15:57 +09:00
Jonas mg d411f05032 Update mod.rs
Derive trait `Eq` in `ParseError`.
2016-12-08 18:17:26 +00:00
Kang Seonghoon d50546a592 More documentation for NaiveTime, and addition fixes.
While writing documentation tests for NaiveTime it was found that
the addition involving leap seconds is *still* slightly broken.
(A consequence of having less tests, well.) The addition routine
has been rewritten to be explicit about leap seconds while passing
all other tests, so the rewrite does not change the intention.
2016-08-06 19:32:01 +09:00
Kang Seonghoon 00858c6363 More cross-references. 2016-08-02 20:52:45 +09:00
Kang Seonghoon 66d5856354 Fixed `%.[369]f` on the whole seconds and misleading docs.
Fixes #71.
2016-04-22 00:47:01 +09:00
Tom Gallacher 7b31609418 Adding fixed precision for Nanosecond3, 6 and 9 2015-09-03 13:40:34 +01:00
Kang Seonghoon 1f40b03ab9 new formatting specifiers to `strftime` syntax.
- Padding modifiers `%_?`, `%-?` and `%0?` are implemented.
  They are glibc extensions which seem to be reasonably widespread
  (e.g. Ruby).

- Added `%:z` specifier and corresponding formatting items
  which is essentially same to `%z` but with a colon.

- Added a new specifier `%.f` which precision adapts from the input.
  Also clearly documented the differences between `%f` and `%.f`. (#40)
2015-07-05 15:00:11 +09:00
Kang Seonghoon 0466a4bf30 documentation fix and some slight bug fix.
- The time zone offset is printed without a colon, but the documentation
  had that inverted. (#39)

- `chrono::format::strftime`'s specifier table is tested throughly.

- When `%s` specifier is used with a time zone, the time zone offset was
  ignored. This has been fixed.
2015-05-29 02:26:01 +09:00
Kang Seonghoon 04b179502c 0.2.5: language changes, mostly overflow changes. 2015-03-06 00:23:51 +09:00
Dan d85ca7564f Remove old closure kind syntax 2015-03-02 11:50:03 +00:00
Kang Seonghoon c11b6deb5a 0.2.1: language changes.
- `std::hash` has been renewed.

- `DelayedFormat` no longer has a redundant lifetime.
2015-02-21 18:15:11 +09:00
Kang Seonghoon 30322bbc89 added `parse_from_rfc{2822,3339}`/`to_rfc{2822,3339}` methods to DateTime. 2015-02-19 04:57:21 +09:00
Kang Seonghoon e997403c10 `num_seconds_from_unix_epoch` is gone, long live `timestamp`!
this is partly because... we are using the simple name `timestamp`
in the `Parsed` anyway. that value is so widespread enough that
its name can be simply THE timestamp. old methods have been marked
deprecated.
2015-02-19 02:45:29 +09:00
Kang Seonghoon 76b0873722 added `FromStr` impls to naive date and time types.
also, previously `Numeric::Nanosecond` had a special left-aligned
parsing behavior. this commit replaces that with a newly designated
`Fixed::Nanosecond` which also handles an empty string which is
possible with an integral number of seconds.
2015-02-18 23:27:12 +09:00
Kang Seonghoon ca865e3c24 added more tests for non-four-digit years and fixed edge cases. 2015-02-18 00:00:30 +09:00
Kang Seonghoon 0399ba1849 weakened the non-negative requirement of year/isoyear fields.
accepts ISO 8601-ish `+YYYYY` or `-YYYYY` notations. this is needed
for the bijectivity of `to_string` and an upcoming `from_str`.
2015-02-17 22:18:39 +09:00
Kang Seonghoon 6937470405 created `format::parse` module.
this new module encompasses John Nagle's original RFC 2822 and 3337
parsers, updated to fully compatible to the actual standard.
the contributed `parse` module has been merged into it.
2015-02-15 21:02:44 +09:00