Commit Graph

61 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 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 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 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
Kang Seonghoon e9401d9266
Fixed an warning and adjusted CI config for min supported version. 2017-02-06 05:03:01 +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 8b382fca45
Incremental doc updates for `NaiveDateTime`.
Also moved the leap second arithmetic examples to
`chrono::naive::time`, as it became hard to link from other pages.
2016-08-16 02:15:56 +09: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
Kang Seonghoon 66d5856354 Fixed `%.[369]f` on the whole seconds and misleading docs.
Fixes #71.
2016-04-22 00:47:01 +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 5ff21f4077 fixed a subtle bug for `Naive(Date)Time + Duration`. (#37)
The exact condition is that the `Duration` to be added is negative
and has a fractional second part. This was not a problem when
`Duration` was Chrono's own type, but a new code for external (then
libstd, now libtime) `Duration` was not tested for this condition
by accident. Consequently this condition caused an underflow in
the fractional part, resulting in a slight inaccuracy.

Fixes #37.
2015-05-15 02:06:34 +09:00
Jisoo Park b5281af9f3 Add optional rustc-serialize support 2015-04-28 18:42:18 +09:00
Kang Seonghoon 9ed34ec542 0.2.9: language changes.
- `std::num::Int` is deprecated.

- Removed one feature flag (`str_char`).
2015-04-03 17:53:44 +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 664c4d0191 merged the new offset design branch. 2015-02-19 01:48:29 +09:00
Kang Seonghoon a4f5d19d24 mass renaming from offset/state to timezone/offset. 2015-02-19 00:30:13 +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 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 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
Kang Seonghoon e97993d76a 0.1.11: language changes.
- Boxed closures are gone; some unboxed closures require an explicit
  annotation for kinds (`&:` in most cases).
2015-01-06 22:38:37 +09:00
Kang Seonghoon e2ddee2f76 0.1.9: language changes.
- `Add` and `Sub` switches to associated types.
2015-01-05 18:31:15 +09:00
Kang Seonghoon cde432ed8e bumped copyright years. 2015-01-04 15:08:25 +09:00