Commit Graph

515 Commits

Author SHA1 Message Date
Brandon W Maister 6f69ab758b Merge pull request #162 from quodlibetor/update-serde-docs
Update serde docs
2017-06-21 18:41:20 -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
Kang Seonghoon 4be3962e31 Merge commit '58dcb4ff' 2017-06-21 03:52:19 +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
Igor Gnatenko 58dcb4ffd7 bincode doesn't have serde feature
It is built-in.
2017-06-16 10:03:24 +02:00
Kang Seonghoon 52de957c60
I forgot to update the README and docs link (whoops).
Fixes #149.
2017-05-11 01:50:19 +09:00
Kang Seonghoon a91981af02
Bump the bincode dependency.
Fixes the CI test.
2017-05-05 19:06:45 +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
Kang Seonghoon 62195bea6f Merge pull request #142 from KodrAus/feat/serde-1.0
Upgrade to serde 1.0
2017-05-02 01:53:05 +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 5dcd528d77 Merge pull request #140 from TheZoq2/patch-1
Update code snippets in readme to use syntax highlighting
2017-04-19 00:35:34 +09: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
Frans Skarman 5d07a5d9c1 Update code snippets to use syntax highlighting 2017-04-10 22:24:32 +02:00
Kang Seonghoon 06810bc573 Merge pull request #134 from ericfindlay/master
Corrected spelling error.
2017-02-21 11:56:17 +09:00
Eric Findlay 701a3a548a Corrected spelling error. 2017-02-21 11:53:46 +09:00
Kang Seonghoon 0571ebf09c Merge pull request #132 from ericfindlay/master
Corrected spelling error
2017-02-21 02:44:59 +09:00
Eric Findlay 3d36feb234 Corrected spelling error 2017-02-20 16:04:32 +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 1afa60f377
Test with multiple time zones.
Previously Chrono was mainly tested in UTC (Travis) and UTC+9 (the
maintainer's local time zone), but we have frequently seen bugs that
only appear in time zones behind UTC. This commit makes the test run all
unit tests three times, in different time zones (UTC, UTC+9:30 and
UTC-4 for now---the choice is mostly arbitrary but tries to cover DST
and half-hour offsets for the future). Travis already ran them three
times (for rust-serialize and Serde) so this won't slow the CI down.

Closes #130.
2017-02-14 03:15:07 +09:00
Kang Seonghoon 73a3ec5514
Fixed a bug that the leap second can be mapped wrongly in the local tz.
Turns out to be a relic of pre-FixedOffset offset calculation code. Only
manifests itself when the local time zone is behind UTC.

Fixes #128.
2017-02-14 03:08:24 +09:00
Kang Seonghoon db9b98f691
0.3.0: Planned breaking changes to the existing interface.
So this is a much delayed major release, but this should not really
change how you use Chrono---only the "required" breakages have been
done (e.g. anything hindering API evolution). The "big" release used to
be 0.3, but due to the dependency changes we are forced to push that to
0.4. I've took this opportunity to push all known planned breaking
changes to 0.3, so this should be quite stable for a moment.

See `CHANGELOG.md` for the full list of changes, but most importantly:

- `chrono::prelude` module has been added for proper glob imports.

- `FixedOffset` is now the official "value" type for time zone offsets.

- Serde 0.9 support has landed, and serialization format used by
  rustc-serialize and Serde has been now synchronized.

- Formatting items have been slightly adjusted to be future-proof.

Fixes #126.
2017-02-07 05:52:07 +09:00
Kang Seonghoon 7b17d68474 Fixed warnings in the nightly. 2017-02-07 05:51:56 +09:00
Kang Seonghoon d7d152eff1
Avoid passing nanoseconds to the OS APIs at all. (#123)
Windows still seems to have an issue---it does not accept 60 in the
second field at all. Let's see if not passing it around improves the
situation.
2017-02-07 05:22:12 +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 96b5ba391b
Fixed a panic when the Local offset receives a leap second.
Fixes #123.
2017-02-07 04:26:29 +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 2b5553ee76 Made `Parsed` not fully destructible.
So that we can add more fields without breaking a major compatibility
(as per RFC 1105).
2017-02-07 03:14:03 +09:00
Kang Seonghoon 36c45f2e02 Removed methods deprecated in 0.2. 2017-02-07 03:13:55 +09:00