Commit Graph

369 Commits

Author SHA1 Message Date
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
Thomas Bytheway 90c75885d0 Rename ts_nano_seconds to ts_nanoseconds 2018-05-24 13:44:12 +01:00
Thomas Bytheway cdb6170f02 Add serde functions for nanosecond timestamps 2018-05-18 11:05:03 +01: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
Brandon W Maister a9618c8e9d
Merge branch 'master' into feature_clock 2018-04-03 05:54:17 -07:00
Brandon W Maister a060684abe
Merge pull request #174 from quodlibetor/deprecated-warnings-for-rustc_serialize
Deprecated warnings in cargo output for rustc-serialize feature
2018-04-03 05:52:58 -07:00
Toby Dimmick d5d5fd92b7 impl Sub<T> for <T> for Date/Time types 2018-04-03 13:42:03 +01:00
Jethro Beekman 5e68c60bb2 Add clock feature 2018-04-02 08:35:27 -07: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
Jethro Beekman 6c398ae6f4 Remove dependencies from oldtime::Duration on rest of time crate 2018-03-30 16:08:45 -07:00
Jethro Beekman 5e730ebe4d Vendor oldtime::duration module from time crate
https://github.com/rust-lang-deprecated/time/blob/master/src/duration.rs
2018-03-30 16:08:45 -07: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
Brandon W Maister 1a983261e3 Ensure that `SecondsFormat` can be expanded semver-safely 2018-03-26 22:10:21 -04:00
Brandon W Maister c9609ea6c9
Merge pull request #217 from dekellum/round
Add SubsecRound trait
2018-03-05 23:23:47 -05:00
David Kellum 449d7277b9 Rename SubSecondRound to SubsecRound
Per review request.
2018-03-05 12:57:26 -08:00
David Kellum 08b7e0bc6b Fix prelude SubSecondRound 2018-03-05 10:40:50 -08:00
David Kellum cb3a73aa86 Rename to (round/trunc)_subsecs; add doc tests 2018-03-05 10:38:48 -08:00
David Kellum 74ec7aa5b2 Improve up/down variable naming 2018-03-04 18:27:36 -08: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
Brandon W Maister 2ee549f84f Allow a clippy lint that depends on rust 1.17 2018-03-04 09:18:02 -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
David Kellum b5acb0ed95 Add SubSecondRound extension trait with impl for Timelike 2018-01-30 12:12:16 -08:00
Brandon W Maister ff962d452c
Merge pull request #205 from dekellum/rfc3339pz
Add DateTime to_rfc3339p(z) methods, tests
2018-01-29 22:16:53 -05:00
David Kellum e8fdbdf41d Rustdoc and naming improvements 2018-01-26 11:42:08 -08:00
David Kellum 1a0ebe7e30 Add more specific SecondsFormat and offer single to_rfc3339_opts 2018-01-25 14:25:04 -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
David Kellum efb0f3b015 Clippy no likey a match on bool 2018-01-18 11:07:23 -08:00
David Kellum 0e6d1d49b7 cleanup name resolution for backward compatibility
so it builds with rustc 1.13
2018-01-18 11:07:23 -08:00
David Kellum 353a7bbbc4 Use const for compat with rustc 1.13-16
Was using static but that's only supported as of rustc 1.17 (rust
these older versions. Also continue using the copious explicit 'static
lifetimes for the same compatibility, despite the clippy lint.
2018-01-18 11:07:23 -08:00
David Kellum d2bf1494b1 Add DateTime to_rfc3339p(z) methods, tests
These additions allow convenient control of RFC 3339 formatted output:

 * Number of subsecond digits to display

 * Whether to use the 'Z' variant, instead of "+00:00" for TZ offset
   0, UTC.

...while remaining faithful to the RFC 3339. The implementation uses
the existing formatting Item mechanism.

github: cc: #157 #178
2018-01-18 11:07:23 -08:00
David Kellum 9742ecccc5 Allow (clippy) needless_pass_by_value on signed_duration_since
Current clippy is probably correct, but its a breaking change that
isn't appropriate now. Add allow's to get the build working again.

Also these Date(Time)::signed_duration_since cases appear to match
there `Naive` counterparts, where clippy isn't complaining. If its
fixed in the future, should probably be changed across the board, not
just here.
2018-01-17 11:49:06 -08:00
David Kellum 4748225550 allow(const_static_lifetime) is for feature cargo-clippy 2018-01-12 16:17:53 -08:00
David Kellum f93c8a993d Add top level clippy allow const_static_lifetime
github: cc: #205
2018-01-12 15:16:06 -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
Jordan Petridis 1286ad12d3
Merge branch 'master' of https://github.com/chronotope/chrono 2017-10-09 15:30:08 +03:00
Jordan Petridis 57c98a409e
Added underscores on long numbers. 2017-10-09 14:47:07 +03:00
Jordan Petridis 532c025a77
Minor doc wording changes. 2017-10-09 02:03:18 +03: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
Jordan Petridis 7e2f2e0bea
Added examples/doctests for how to get a datetime from an epoch and vice versa. 2017-09-29 19:24:40 +03:00
Brandon W Maister b3adf050f5 Merge pull request #185 from kosta/readme-timestamps
Add doc comment to lib.rs: Conversion from and to EPOCH timestamps
2017-09-26 20:50:59 -04:00
Xidorn Quan 0eeb4746f2 fix rfc2822 parsing to allow omitting second 2017-09-19 21:52:07 +10:00
Kosta Welke 0853499bec Add doc comment to lib.rs: Conversion from and to EPOCH timestamps 2017-09-04 15:04:07 +02:00
Jonas Bushart 4eacc1416e Additional tests which test parsing of %s in combination with %f/%.3f/... 2017-07-15 16:27:56 +02: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 927763b6b3 Merge pull request #173 from quodlibetor/doc-timestamp-opt
Mention timestamp_opt in the docs for timestamp
2017-07-09 20:44:57 -05: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 ec6c31e863 Mention timestamp_opt in the docs for timestamp
Influenced by #110
2017-07-09 16:19:34 -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 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 de7f0f64f7 Fix Clippy lints: needless_pass_by_value 2017-07-09 15:10:26 -05:00
Brandon W Maister c63a012253 Fix Clippy lints: needless_lifetimes 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 fac6ff44c9 Fix Clippy lints: needless_return 2017-06-24 13:12:33 -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 136302cc04
Added `From` implementations between `SystemTime` and `DateTime`.
Due to the obvious lack of time zone information in `SystemTime`,
`SystemTime` can only be converted to `DateTime<Utc>` (in UTC) or
`DateTime<Local>` (in the local time zone), while any `DateTime<Tz>`
can be converted to `SystemTime`.
2017-06-22 01:48:06 +09:00
Kang Seonghoon 8ea2d3f236
Merge branch 'master' into naive_assign 2017-06-22 01:12:18 +09: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 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
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
Kang Seonghoon 388c04002b
Bumped the version number. This marks the beginning of 0.4.0 series.
- Added a mention to Chrono-tz.
2017-06-21 03:27:46 +09:00
Kang Seonghoon 52de957c60
I forgot to update the README and docs link (whoops).
Fixes #149.
2017-05-11 01:50:19 +09:00
Ben Boeckel ede06d6beb date: mention that `NaiveDate` is better for serialization
Fixes #92.
2017-05-05 19:02:42 +09:00
Kang Seonghoon dcf193323b
0.3.1: Minor maintenance release, Serde 1.0 support.
- Serde 1.0 is now supported. (#142)

  Technically this is a breaking change, but the minor version was not
  effective in avoiding dependency breakages anyway (because Cargo
  will silently compile two versions of crates). Provided that this is
  likely the last breakage from Serde, we tolerate
  this more-than-last-minute change in this version.

- `Weekday` now implements `FromStr`, `Serialize` and `Deserialize`.
  (#113)

- Fixed a bug that the leap second can be mapped wrongly
  in the local tz with some conditions. (#130)

- Some changes to the tests to avoid previously known issues.

Note that the actually published version is very slightly different
from the repository because no published version of bincode supports
Serde 1.0 right now.
2017-05-02 03:13:00 +09:00
Kang Seonghoon fcb74481ee
Updated Weekday impls for serde to 1.0. 2017-05-02 02:37:54 +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 35d1a73ad9 Merge pull request #113 from amikhalev/weekday-serde
Added impl FromStr, Serialize, Deserialize for Weekday
2017-05-02 02:12:54 +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