Commit Graph

66 Commits

Author SHA1 Message Date
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
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
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 c118a3985f
Serialization cleanup for 0.3.
- Rustc-serialize now uses the same serialization format as Serde.
  This also means that the older format (naturally derived from
  the internals) is no longer supported.

- Serialization support only existed for rustc-serialize has been
  (temporarily) removed. This affects `Date<Tz>` and all individual
  time zone types. This does *not* affect `DateTime<Tz>` as it has
  individual support per `Tz`.

  Please note that this is considered a temporary solution to avoid
  stabilizing diverging implementations. Their implementations will
  likely be reintroduced later.
2017-02-07 03:08:01 +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
Ashley Mannix 898e266e02 update for serde 0.9 2017-02-01 20:02:22 +10:00
János Illés 076a54532f Stop using clone() on Copy types
https://github.com/Manishearth/rust-clippy/wiki#clone_on_copy
2016-10-02 01:17:13 +02:00
Kang Seonghoon 6cc5d18696 Merge pull request #89 from dtolnay/bincode
Support deserializing from bincode
2016-08-17 09:45:45 +09:00
David Tolnay c3cd76af16
Add bincode serde tests 2016-08-16 18:08:19 -04:00
Kang Seonghoon 582f1166f2
Documentation and complete rewrite for `NaiveDateTime` operations.
- `NaiveDateTime` is now almost completely annotated with examples.

- Introduced `NaiveTime::overflowing_{add,sub}` for the correct
  handling of overflow/underflow of `NaiveTime`.

- `NaiveDateTime +/- Duration` operation is rewritten with those
  methods, eliminating any problem against leap seconds. (Thus this
  is yet another slight breaking change, but considered a bug fix.)
2016-08-17 00:41:08 +09:00
David Tolnay c3b9a26bb0 Support deserializing from bincode
Bincode is a minimal format that expects the Deserialize
implementation to tell it what type of data it should
expect to see.
2016-08-16 02:54:14 -04:00
Kang Seonghoon 0393cae36d Standardized the doc example format for shortened methods.
Especially for naives types, methods can be too long to fit in
one line. Previously ad-hoc closures have been used for extreme
cases; this commit will update them to the following form:

    use anything::needs::to::be::imported;

    let shortened = SomeType::long_name_to_be_shortened;

    assert_eq!(shortened(...), ...);

It should be noted that the shortened name is no longer arbitrary;
it should be either the original method name, or when it gets too
long, a name with adjectives and clauses removed. The abbreviation
is now consistent, and restricted to the following:

- `num_days` -> `ndays`; `num_secs` -> `nsecs`
- `hms_milli` -> `hmsm`; - `hms_micro` -> `hmsu`; `hms_nano` -> `hmsn`

The goal is to make examples NOT look alike tests, and more alike
the actual code. (Well, not always possible but I'm trying.)
2016-08-08 03:34:00 +09:00
Kang Seonghoon 62d289fc85 Added documentations for `NaiveTime` and `NaiveDateTime` methods.
Also slightly edited the `format` and `format_with_items` docs to be
more unobstructive (i.e. implicit `use` from previous blocks).
2016-08-08 03:04:39 +09:00
Kang Seonghoon 69d7a86c1c Subtraction fixes for NaiveTime.
Again, this time with more thorough tests and documentation.
2016-08-07 02:32:09 +09: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 cb9fd7fbe1 0.2.25: Fixed warnings from 0.2.24. Duh. 2016-08-04 03:44:31 +09:00
Kang Seonghoon ad6253f653 Proper (de)serialization format handling.
For a while Chrono's serialization support was barely working,
i.e. usable but never been safe. While it wouldn't cause any memory
unsafety, attacker can fabricate an input that will make most users
confused (e.g. seemingly same Date which doesn't compare equally).
This commit will properly error for those cases.

It was also problematic that the generated rustc-serialize format is
very inefficient, especially for JSON. Due to the backward
compatibillity this commit does NOT fix them (likely to be in 0.3),
but this does try to define the exact format and define tons of
tests to detect any change to the serialization.

There are several remaining problems in the serialization format;
the serde implementation seems good, but it is unable to distinguish
some cases of leap seconds (practically won't matter, but still).
The rustc-serialize implementation would require a massive redesign.
For now, I postpone those issues to 0.3 (what a convenient excuse).

Fixes #42.
2016-08-04 03:22:12 +09:00
Kang Seonghoon 4475ee5a48 More cross links and detailed examples for docs.
Also fixed some broken links (hard to catch from source files).
2016-08-01 03:23:46 +09:00
Kang Seonghoon 932e29aa94 Better documentation and cross-references for naive types. 2016-08-01 01:02:32 +09:00
Ryan Lewis f8630fce81 Update serde to 0.7.0
rename visit_str to serialize_str
rename E::syntax(&str) to E::Custom(String)
rename deserializer.visit to deserialize.deserialize
2016-03-03 20:54:47 +13:00
Martin Risell Lilja d8f2a3e7d8 Added serde support for DateTime, NaiveDate, NaiveTime and NaiveDateTime. 2015-11-19 00:12:13 +01:00
Kang Seonghoon 24bc15fdd3 more documentation for `NaiveTime`; some terminology updates. 2015-09-12 02:41:38 +09:00
Kang Seonghoon acf4eab102 more documentation, finishing examples for chrono::naive::date. 2015-09-06 21:30:09 +09:00
Kang Seonghoon 5bff8170ff added more examples to chrono::naive::date. 2015-06-03 00:33:45 +09:00
Kang Seonghoon 6d4054a3a7 some more docs for NaiveDate. 2015-05-03 14:38:27 +09:00
Jisoo Park b5281af9f3 Add optional rustc-serialize support 2015-04-28 18:42:18 +09:00
Eunchong Yu 2ced2b1fb2 Exclude benchmark-related tests by default
This features can be enabled to use the cfg flag 'bench'.
2015-04-26 15:53:39 +09:00
Eunchong Yu d84588eb49 Remove unstable feature 'zero_one' and use the impl of 'num' crate 2015-04-26 15:41:18 +09:00
Jisoo Park 14a44aef2b Language update 2015-04-24 16:45:53 +09:00
Jisoo Park f69d8ecd9a Update to the latest nightly 2015-04-04 20:49:06 +09:00
Kang Seonghoon 98c5f3a2b1 0.2.7: language changes.
- Feature flags are now required on the doctests.

- New lints for trivial casts. We are now not going to change
  the internal implementation type for `NaiveDate`, so that's fine.
2015-03-27 11:35:34 +09:00
Kang Seonghoon a5bd6c040e 0.2.6: language changes and dependency updates.
- `range` is now deprecated.

- `str_char` feature gate is split out from `collections`.
2015-03-21 22:01:52 +09:00
Kang Seonghoon 848d828e24 started adding examples to the doc comments. 2015-03-16 01:09:02 +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 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 637784c8ef renamed `from_str` methods to `parse_from_str`.
so that we can safely implement `FromStr` traits for those types.
also updates READMEs and rewires `%+` specifier of `StrftimeItems`
to a new RFC 3339 formatting item.
2015-02-15 21:27:12 +09:00
Kang Seonghoon c7f132cca2 added `format_with_items` methods to every types. 2015-02-14 12:34:31 +09:00
Kang Seonghoon 7eb9a1a983 public interfaces for parser are now available. 2015-02-05 02:16:35 +09:00
Kang Seonghoon 3d00a0fd5a added `checked_{add,sub}` methods to `[Naive]Date[Time]` types.
- Existing `+` and `-` operators use them, and properly panics with
  a correct error message on overflow/underflow.
2015-02-04 16:19:54 +09:00
Kang Seonghoon 43ee68b522 new formatter design!
- Format string is internally represented as a series of formatting
  items. Items can be directly given to now-public `format::format`
  function as well.

- Format string parser is separated to `format::strftime` module.
  This is to allow for potentional alternative formatting syntaxes.

- `DelayedFormat` now receives an iterator for formatting items.
2015-02-04 16:19:54 +09:00
Kang Seonghoon cf5e2f322f 0.1.15: language changes.
- `std::fmt::Show` is now `std::fmt::Debug`.
- `std::fmt::String` is now `std::fmt::Display`.
2015-01-24 17:45:12 +09:00
Kang Seonghoon ca84749869 0.1.13: language changes and fmt::String supports.
- Every type modulo `LocalResult` and `Offset` now implements
  `std::fmt::String`, so `.to_string()` can be used.
  The exact format has been changed for better looking output.

- `std::fmt::Show` are intended for "stricter" output,
  which mostly means the strict ISO 8601 format.
  `DelayedFormat` also implements this, but only for inspection.

- `Offset` should implement `Show` but can omit `String`.
  The old `name` method is merged into `String` implementations.
2015-01-10 03:27:24 +09:00
Kang Seonghoon d79c460fc4 0.1.12: language changes, removed ops for Duration in the lhs.
- Feature flags used are all accepted.
- Orphan check workaround is no longer required.
- Impl reachability rules prevent the addition of `Duration + others`,
  as `Duration` is not implemented in this crate. Removed the impl;
  use `others + Duration` as a workaround.
2015-01-08 02:08:41 +09:00