Commit Graph

418 Commits

Author SHA1 Message Date
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
Eric Findlay 701a3a548a Corrected spelling error. 2017-02-21 11:53:46 +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 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
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 04fd1413a8
Chrono is now under the Chronotope org; switch to docs.rs.
All CI accounts are now moved to the new organization (unfortunately
Appveyor does not automatically move the build history though).

Since it's a mess to redirect everything to chronotope.github.io,
I've taken this as an opportunity to switch to docs.rs---this seems
to be better than the manual management nowadays.

Updated other files as accordingly.
2017-02-06 05:49:32 +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
Jonas mg d411f05032 Update mod.rs
Derive trait `Eq` in `ParseError`.
2016-12-08 18:17:26 +00:00
Alex Mikhalev 538f303ed5 Added impl FromStr, Serialize, Deserialize for Weekday 2016-12-06 20:07:39 -07:00
Richard Petrie d2cd4c9815 Documentation had the wrong relative path
Feel free to destroy this PR and fix in a branch as you see fit.
2016-12-02 12:54:32 -06:00
Alex Mikhalev cebb2483d9 Added #[derive(Hash)] for Weekday enum
This is so it can at least be used in a HashSet, if not in a BTreeSet
because it does not impl Ord.
2016-11-14 08:53:58 -07:00
Brandon W Maister a4c1cc6ed2 Improve docs around constructing DateTime objects
This provides examples for most of the constructor-like methods on
`TimeZone`, examples on the various `Offset` impls, and links
`NaiveDateTime` to `TimeZone` so that it's more obvious how you're
supposed to do things.

This is related to #88, which is something that I ran into when I
started using rust-chrono.
2016-11-12 16:09:08 -05:00
Jim Turner 881e6c2dcc Clarify that Duration is an "accurate" duration
The ISO 8601 format includes both "nominal" (year, month, week, and
day) and "accurate" (hour, minute, and second) components. However, the
`Duration` type only represents an "accurate" duration because
arithmetic with nominal components is not defined in ISO 8601.
2016-10-04 19:07:11 -04:00
János Illés 978b64ff33 support Add/Sub assignment operators for Naive types.
Requires Rust 1.8 or higher.
2016-10-02 15:38:06 +02:00
János Illés abdad54884 Use char type instead of single-char Strings
https://github.com/Manishearth/rust-clippy/wiki#single_char_pattern
2016-10-02 01:17:13 +02:00
János Illés 124ff48de8 Remove redundant closure
https://github.com/Manishearth/rust-clippy/wiki#redundant_closure
2016-10-02 01:17:13 +02: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 603ac1bc1c 0.2.24: Serialization updates.
- Serde 0.8 is now supported. (#86)

- The deserialization implementation for rustc-serialize now properly
  verifies the input. Also tons of tests have been added. (#42)
2016-08-04 03:37:33 +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 ae9be4a6f3 0.2.23: Documentation and minor bug fixes.
- Tons of documentation updates! (#77, #78, #80, #82 and my own
  changes as well)

- `DateTime::timestamp_subsec_{millis,micros,nanos}` methods have
  been added. (#81)

- When the system time records a leap second,
  the nanosecond component was mistakenly reset to zero. (#84)

- `Local` offset misbehaves in Windows for August and later,
  due to the long-standing libtime bug (dates back to mid-2015).
  Workaround has been implemented. (#85)
2016-08-03 01:18:33 +09:00
Kang Seonghoon 5f8c6e611a Workaround for rust-lang-deprecated/time#137.
In Windows libtime populate `time::Tm` from `SYSTEMTIME`, which
unfortunately does not contain `tm_yday`. It tries to calculate it
from other fields, but... as one can say it is completely wrong.
Since other fields are copied in verbatim we work around this
problem by using a less efficient method.

Fixes #85.
2016-08-03 00:38:08 +09:00
Kang Seonghoon 00858c6363 More cross-references. 2016-08-02 20:52:45 +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
Sergey V. Galtsev a5be5cc592 Fix spilling of exceeding `tm_sec` into `tm_nsec` in `tm_to_datetime()`. 2016-07-31 00:42:11 +03:00
Kang Seonghoon f41de9b41f Documentation cleanup.
- The main documentation (`src/lib.rs` AND `README.md`) now properly
  link to other types when rendered.

- The role of `TimeZone` trait is explained more thoroughly.

(Hopefully) fixes #82.
2016-07-26 03:48:08 +09:00
Kang Seonghoon 0b3218289f Fixed warnings from rust-lang/rfcs#1445. 2016-07-26 03:48:05 +09:00
Ben Eills bb50154d8c Add functions to get milli/micro/nano-seconds from a DateTime (#81)
* Add functions to get milli/micro/nano-seconds from a DateTime

Using the underlying naive::NaiveTime fractional part, we compute
the number of milli/micro/nano-seconds since the last second boundary.

The reason for not computing elapsed time since 1970 is because we
would hit potential issues of i64s not being large enough (the range
would be strictly smaller than the 64bit-timestamp range, causing
compatibility issues).

* Rename subsecond functions

Renamed accessors to subsec_{nano,micro,milli}, as suggested
in pull request comment.  Also added warnings for leap second
consitions causing these values to exceed the normal range
of 0..10^n.

Fixed editor's previous obnoxious whitespace changes.
2016-07-16 14:19:34 +09:00
Kang Seonghoon 8efc85ce9f 0.2.22: Fixes on `%.6f` and `%.9f` on whole seconds.
- `%.6f` and `%.9f` used to print only three digits
  when the nanosecond part is zero. (#71)

- The documentation for `%+` has been updated
  to reflect the current status. (#71)
2016-04-22 08:54:57 +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
Kang Seonghoon d869643a33 0.2.21: a slight bug fix.
- `Fixed::LongWeekdayName` was unable to recognize `"sunday"`. (#66)
- Slight documentation addition. (#65)
2016-03-29 09:00:49 +09:00
Joe Wilm 097ab04a69 Update RFC850 test to check all weekdays 2016-03-28 09:57:29 -07:00
Joe Wilm 33516cc9f1 Fix parsing LongWeekday for Sunday
Only `Sun` was consumed, and the string being parsed would have `day`
left over at the front.
2016-03-28 09:46:25 -07:00
Joe Wilm 260342a592 Add regression test for RFC850 parsing
Although not supported directly by chrono, users should be able to
specify the RFC850 format and expect it to parse properly. RFC850 is
important since HTTP/1.1 specifies

    HTTP-date = rfc1123-date | rfc850-date | asctime-date
2016-03-28 09:43:52 -07:00
Danilo Bargen 6d9f91874b Clarify timezone conversion in docs 2016-03-23 09:50:23 +01:00
Kang Seonghoon 79686de2d1 Fixed a broken test in 1.7 (missed by the local testing). 2016-03-06 00:32:21 +09:00
Kang Seonghoon 530a5ee10b 0.2.20: Updated `serde` dependency. (#63, #64) 2016-03-06 00:19:29 +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
Kang Seonghoon aa6df02436 0.2.19: `DateTime::date` (and indirectly, `Local::today`) fix. (#61) 2016-02-05 01:35:43 +09:00
Kang Seonghoon 4025d617f5 Fixed #61.
Technically it was a problem of `DateTime::date` with a lax test.
Documented the intention and guarantees on `Date` as a result.
2016-02-05 01:23:46 +09:00
Kang Seonghoon d789e3e493 0.2.18: Get rid of a superfluous `rand` dependency. (#57) 2016-01-23 14:41:12 +09:00
Kang Seonghoon d3384780d0 rustfmt'ed src/lib.rs (only). 2016-01-23 14:37:29 +09:00
Kang Seonghoon 2c11364410 0.2.17: Added a serde support for date and time types. (#51) 2015-11-22 03:27:08 +09: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 ed3727931f 0.2.16: mainly maintenance changes, with a minor formatting addition.
- Added `%.3f`, `%.6f` and `%.9f` specifier for formatting fractional seconds
  up to 3, 6 or 9 decimal digits. This is a natural extension to the existing `%f`.
  Note that this is (not yet) generic, no other value of precision is supported. (#45)

- Forbade unsized types from implementing `Datelike` and `Timelike`.
  This does not make a big harm as any type implementing them should be already sized
  to be practical, but this change still can break highly generic codes. (#46)

- Fixed a broken link in the `README.md`. (#41)

- Tons of supporting examples for the documentation have been added. More to come.
2015-09-06 21:46:03 +09:00
Kang Seonghoon acf4eab102 more documentation, finishing examples for chrono::naive::date. 2015-09-06 21:30:09 +09:00
Kang Seonghoon 37c7f78670 Merge pull request #45 from tomgco/f-parse-2
New formatters %.3f, %.6f, %.9f
2015-09-05 19:18:23 +09:00
Corey Farwell 98bc0abad9 Fix nightly warnings related to lifetimes
The following warnings appear:

```
   Compiling chrono v0.2.15 (file:///Users/coreyf/Development/rust/rust-chrono)
src/lib.rs:504:5: 504:52 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:504     fn with_year(&self, year: i32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:504:5: 504:52 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:504:5: 504:52 note: `Self` does not have a constant size known at compile-time
src/lib.rs:504     fn with_year(&self, year: i32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:504:5: 504:52 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:504     fn with_year(&self, year: i32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:504:5: 504:52 note: required by `core::option::Option`
src/lib.rs:504     fn with_year(&self, year: i32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:509:5: 509:54 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:509     fn with_month(&self, month: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:509:5: 509:54 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:509:5: 509:54 note: `Self` does not have a constant size known at compile-time
src/lib.rs:509     fn with_month(&self, month: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:509:5: 509:54 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:509     fn with_month(&self, month: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:509:5: 509:54 note: required by `core::option::Option`
src/lib.rs:509     fn with_month(&self, month: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:514:5: 514:56 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:514     fn with_month0(&self, month0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:514:5: 514:56 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:514:5: 514:56 note: `Self` does not have a constant size known at compile-time
src/lib.rs:514     fn with_month0(&self, month0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:514:5: 514:56 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:514     fn with_month0(&self, month0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:514:5: 514:56 note: required by `core::option::Option`
src/lib.rs:514     fn with_month0(&self, month0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:519:5: 519:50 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:519     fn with_day(&self, day: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:519:5: 519:50 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:519:5: 519:50 note: `Self` does not have a constant size known at compile-time
src/lib.rs:519     fn with_day(&self, day: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:519:5: 519:50 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:519     fn with_day(&self, day: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:519:5: 519:50 note: required by `core::option::Option`
src/lib.rs:519     fn with_day(&self, day: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:524:5: 524:52 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:524     fn with_day0(&self, day0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:524:5: 524:52 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:524:5: 524:52 note: `Self` does not have a constant size known at compile-time
src/lib.rs:524     fn with_day0(&self, day0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:524:5: 524:52 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:524     fn with_day0(&self, day0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:524:5: 524:52 note: required by `core::option::Option`
src/lib.rs:524     fn with_day0(&self, day0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:529:5: 529:58 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:529     fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:529:5: 529:58 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:529:5: 529:58 note: `Self` does not have a constant size known at compile-time
src/lib.rs:529     fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:529:5: 529:58 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:529     fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:529:5: 529:58 note: required by `core::option::Option`
src/lib.rs:529     fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:534:5: 534:60 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:534     fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:534:5: 534:60 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:534:5: 534:60 note: `Self` does not have a constant size known at compile-time
src/lib.rs:534     fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:534:5: 534:60 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:534     fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:534:5: 534:60 note: required by `core::option::Option`
src/lib.rs:534     fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:580:5: 580:52 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:580     fn with_hour(&self, hour: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:580:5: 580:52 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:580:5: 580:52 note: `Self` does not have a constant size known at compile-time
src/lib.rs:580     fn with_hour(&self, hour: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:580:5: 580:52 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:580     fn with_hour(&self, hour: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:580:5: 580:52 note: required by `core::option::Option`
src/lib.rs:580     fn with_hour(&self, hour: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:585:5: 585:53 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:585     fn with_minute(&self, min: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:585:5: 585:53 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:585:5: 585:53 note: `Self` does not have a constant size known at compile-time
src/lib.rs:585     fn with_minute(&self, min: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:585:5: 585:53 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:585     fn with_minute(&self, min: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:585:5: 585:53 note: required by `core::option::Option`
src/lib.rs:585     fn with_minute(&self, min: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:590:5: 590:53 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:590     fn with_second(&self, sec: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:590:5: 590:53 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:590:5: 590:53 note: `Self` does not have a constant size known at compile-time
src/lib.rs:590     fn with_second(&self, sec: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:590:5: 590:53 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:590     fn with_second(&self, sec: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:590:5: 590:53 note: required by `core::option::Option`
src/lib.rs:590     fn with_second(&self, sec: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:595:5: 595:58 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:595     fn with_nanosecond(&self, nano: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:595:5: 595:58 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:595:5: 595:58 note: `Self` does not have a constant size known at compile-time
src/lib.rs:595     fn with_nanosecond(&self, nano: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:595:5: 595:58 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:595     fn with_nanosecond(&self, nano: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:595:5: 595:58 note: required by `core::option::Option`
src/lib.rs:595     fn with_nanosecond(&self, nano: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

...because of:

https://github.com/rust-lang/rfcs/pull/1214
2015-09-05 12:01:46 +02:00
Tom Gallacher c44de1d388 Updating docs 2015-09-03 13:53:18 +01:00
Tom Gallacher b53e9d940f Refactoring matching 2015-09-03 13:43:36 +01:00
Tom Gallacher 7b31609418 Adding fixed precision for Nanosecond3, 6 and 9 2015-09-03 13:40:34 +01:00
Kang Seonghoon 68f45dae75 Fix a link in the README.
Fixes #41.
2015-08-08 13:09:44 +09:00
Kang Seonghoon 01b3ed2ada 0.2.15: more formatting specifiers and documentation fixes.
- Added padding modifiers `%_?`, `%-?` and `%0?`.

- Added new specifiers `%:z` and `%.f`.

- When `%s` specifier is used with a time zone, the time zone offset was
  ignored. This has been fixed.

- Several documentation fixes including the misleading presence of
  colons in the `%z` specifier. `%:z` was introduced partly due to this.
2015-07-05 15:26:30 +09: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 5bff8170ff added more examples to chrono::naive::date. 2015-06-03 00:33:45 +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 0d6c3ce11a a couple of documentation fixes.
- We've got 1.0.0, so no need for version pinning now.

- `%Z` is formatting-only specifier but wasn't clearly documented.
  Fixes #38.
2015-05-25 10:12:11 +09:00
Kang Seonghoon 9cff70bd04 0.2.14: fixed a subtle bug in `Naive(Date)Time` addition.
- `NaiveDateTime +/- Duration` or `NaiveTime +/- Duration` could
  have gone wrong when the `Duration` to be added is negative and
  has a fractional second part.

  This was caused by an underflow in the conversion from `Duration`
  to the parts; the lack of tests for this case allowed a bug.
  A regression test has been added to avoid further bugs. (#37)
2015-05-15 02:20:03 +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
Kang Seonghoon 6d4054a3a7 some more docs for NaiveDate. 2015-05-03 14:38:27 +09:00
Kang Seonghoon e08f0849dc well, I forgot to update the README. 2015-04-29 02:12:17 +09:00
Kang Seonghoon 90ac81e9f9 0.2.13: beta stabilization and optional rustc_serialize deps.
- This version is finally beta-compatible.

  This introduces a slight incompatibility, namely, due to
  the rewired reexport for `chrono::Duration` (which now comes
  from crates.io `time` crate).

- The optional dependency on `rustc_serialize` and relevant
  `Rustc{En,De}codable` implementations for supported types
  has been added. You will need the `rustc-serialize` Cargo
  feature to use them.
2015-04-29 02:09:04 +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 28f4c7acd2 Remove unstable feature 'std-misc' 2015-04-26 15:52:16 +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
Eunchong Yu b950d83454 Remove unstable feature 'core' 2015-04-26 15:17:01 +09:00
Eunchong Yu 878b81d72f Remove unstable slice pattern 2015-04-26 15:10:28 +09:00
Kang Seonghoon 533161cfd7 0.2.12: language changes.
- Many `std::num` traits are removed and replaced with
  the external `num` crate. For time being, thus, Chrono will
  require the dependency on `num`. This is expected to be temporary
  however.
2015-04-25 00:12:56 +09:00
Jisoo Park 14a44aef2b Language update 2015-04-24 16:45:53 +09:00
Kang Seonghoon eced570882 0.2.11: language changes.
- Replaced `thread::scoped` with `thread::spawn` to cope with
  a rare de-stabilization event.

- `#[deprecated]` is (ironically) deprecated with user crates.
  All uses of them have been replaced by doc comments.
2015-04-17 01:28:31 +09:00
Kang Seonghoon 7fd0cf124a 0.2.10: language changes.
- `Copy` requires `Clone`.
2015-04-05 03:18:49 +09:00
Jisoo Park f69d8ecd9a Update to the latest nightly 2015-04-04 20:49:06 +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
Kang Seonghoon e012702033 0.2.8: language changes.
- Slice patterns are now feature gated.

- Reformatted the `chrono::format::strftime` documentation
  with a proper table (closes #31).
2015-03-30 10:23:20 +09:00
Huon Wilson 5bbc668081 Slice patterns are now feature gated. 2015-03-29 22:09:15 +11: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
Kang Seonghoon 37be780b31 0.2.4: language changes and bug fixes. 2015-03-03 02:40:03 +09:00
Kang Seonghoon 2be6e14446 Fixes #27.
This is due to somewhat ambiguous semantics of `Date`. It cannot
really constructed without an intermediate `DateTime` much like
the removed `Time`, but it is much more useful than `Time` so
we need some reasonable meaning to it. This commit clarifies
that meaning and corrects some problems around it:

- The date itself is timezone-agnostic unless the timezone itself
  has an offset equal to or greater than one day. In all current
  time zones, the date conversion should be a no-op.

- The date may be attached some offset; that offset should have
  been occurred within the corresponding day in either the local
  time or the UTC.

- `TimeZone` is free to assign the offset within this constraint.
  For convenience, the current `Local` time zone assumes the local
  midnight or the UTC midnight.
2015-03-03 02:37:20 +09:00
Dan d85ca7564f Remove old closure kind syntax 2015-03-02 11:50:03 +00:00
Kang Seonghoon 2dbc11dcb1 0.2.3: Fixed a couple of outstanding bugs.
- `DateTime<Tz>` and `Date<Tz>` is now `Copy`/`Send` when
  `Tz::Offset` is `Copy`/`Send`. The implementations for them were
  mistakenly omitted. Fixes #25.

- `Local::from_utc_datetime` didn't set a correct offset.
  The tests for `Local` were lacking. Fixes #26.
2015-02-27 13:08:20 +09:00
Kang Seonghoon ffa86603ae 0.2.2: language & docs changes.
- `missing_docs` lint now checks for associated types.
2015-02-27 00:24:06 +09: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 e80501dcb3 forgot to update the docs for removal of `Time`... 2015-02-19 05:42:18 +09:00
Kang Seonghoon be6a721be6 0.2.0: offset reform, new format/parse module, various cleanups.
Fixes #11 and #12.
The complete list of changes is available in [CHANGELOG.md].

[CHANGELOG.md]: https://github.com/lifthrasiir/rust-chrono/blob/master/CHANGELOG.md#020-2015-02-19
2015-02-19 05:12:03 +09:00
Kang Seonghoon 6a9490522e updated docs for RFC2822/3339 and added ChangeLog. 2015-02-19 05:08:00 +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 82c9345a4d okay, new `DateTime::time` was incorrect. 2015-02-19 04:28:38 +09:00
Kang Seonghoon f39b13a14c removed timezone-aware `Time` type.
`Time` with an associated time zone is in principle possible, but
in practice it can only meaningfully constructed from an existing
`DateTime`. this makes it hard to implement other operations
natural to `NaiveTime` for `Time` (e.g. `with_*` methods), so
we simply let it go.

migration path: if you *do* happen to use `Time`, don't panic!
every operation possible to `Time` is much more possible to
`NaiveTime`. if you have to deal with a local time, first combine
it with a `NaiveDate`, convert it via `TimeZone::from_local_datetime`
then extract `Time` part again.
2015-02-19 04:17:27 +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 c1d0b0279f various doc cleanups; added `FromStr` impl for `DateTime<Local>`.
also made a small script for auto-generating `README.md` out of
the main doc comment from `src/lib.rs`.
2015-02-19 02:21:52 +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 e43cb62f10 initial implementation of `Offset` redesign (#11).
- We have splitted `Offset` into `Offset` and `OffsetState` (name
  changes in consideration). The former is used to construct and convert
  local or UTC date, and the latter is used to store the UTC offset
  inside constructed values. Some offsets are their own states as well.

- This uses lots of associated types which implementation is still in
  flux. Currently it crashes with debuginfo enabled. We've temporarily
  disabled debuginfo from `Cargo.toml`.

- This technically allows a conversion to the local time, but not yet
  tested.
2015-02-19 00:25:04 +09:00
Kang Seonghoon 46996e35e1 implemented `FromStr` for `DateTime<FixedOffset/UTC>`. 2015-02-19 00:03:58 +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 3f211dfe5f rewrote the date resolution algorithm.
this is most importantly required for negative years in `Parsed`,
which the current parser doesn't generate but is nevertheless
possible in principle. also updates tests for new fields.
2015-02-16 02:16:47 +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 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
Kang Seonghoon c7f132cca2 added `format_with_items` methods to every types. 2015-02-14 12:34:31 +09:00
Kang Seonghoon 292faa0b23 temporarily merged PR #24, to be fully integrated later. 2015-02-13 21:18:35 +09:00
Kang Seonghoon 25b8e21d29 separated a `format::scan` module from the parser.
also changes the behavior of `Numeric::Nanosecond` (`%f`) to
the left-aligned digits and allows for the wider range of time zone
offsets from -99:59 to +99:59.
2015-02-13 18:46:02 +09:00
Kang Seonghoon 2e7a213818 0.1.18: language changes.
- Replaced remaining occurrences of Show with Debug.
- Dependency upgrades.
2015-02-07 01:16:05 +09:00
Kang Seonghoon 82c63e5b40 0.2.0-dev: date/time parsing.
Basically, this should close #12 when officially released.

- Formatting syntax is now refactored out of the rendering logic.
  The main syntax is available in the `format::strftime` module,
  which also serves as a documentation for the syntax.

- A parser (modelled after `strptime(3)`) has been implemented.
  See the individual commits for the detailed implementation.

- There are two ways to get a timezone-aware value from a string:
  `Offset` or `DateTime<FixedOffset>`. The former should be used
  when the offset is known in advance (e.g. assume the local date)
  while the latter should be used when the offset is unknown.
  Naive types have a simple `from_str` method.

- There are some known problems with the parser (even after
  tons of tests), which will be sorted out in 0.2. Known issues:

  - This does not exactly handle RFC 2822 and RFC 3339, which
    subtly differs from the current implementation in
    case-sensitivity, whitespace handling and legacy syntax.
    I'd like to integrate #24 for this cause.

  - Time zone names are not recognized at all. There is even
    no means to get a name itself, not sure about the resolution.

  - `Parsed` does *not* constrain `year` to be non-negative,
    so manually prepared `Parsed` may give a negative year.
    But the current verification pass may break such cases.

  - I absolutely don't know about the parser's performance!

- `AUTHORS.txt` has been added, for what it's worth.
2015-02-05 02:53:19 +09:00
Kang Seonghoon 7eb9a1a983 public interfaces for parser are now available. 2015-02-05 02:16:35 +09:00
Kang Seonghoon 9768b57494 reworked new `format` APIs to return a proper Result and error code. 2015-02-05 00:54:25 +09:00
Kang Seonghoon aebcedf37b added `format::parse` and accompanying tests. 2015-02-04 16:31:37 +09:00
Kang Seonghoon dfa92ef56d better handling (and bug fixes) of leap seconds in `format::parsed`. 2015-02-04 16:23:04 +09:00
Kang Seonghoon b8a2ad2220 massive tests and bug fixes for `format::parsed`. 2015-02-04 16:23:04 +09:00
Kang Seonghoon 02b4c72f22 initial `format::parsed` implementation. 2015-02-04 16:22:41 +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 98d1ce01c9 language changes: replaced remaining occurrences of Show with Debug. 2015-02-04 16:17:35 +09:00
John Nagle dd4f679411 Avoid duplicate import of regex macros, which causes problems with linking
the crate into an enclosing crate.
2015-02-02 11:43:03 -08:00
Kang Seonghoon 36181b65ca 0.1.17: language changes.
- Many unstable stdlib parts require `#[feature]` flags as per
  Rust RFC #507.
2015-01-30 00:03:19 +09:00
Kang Seonghoon 7087cd156a 0.1.16: dependency fixes due to language changes. 2015-01-29 08:47:05 +09:00
John Nagle 3566c3a793 Change names of parsing functions for consistency with "chrono".
All tests pass.
2015-01-26 23:11:09 -08:00
John Nagle 203b455569 Added parsing functions for standard date formats. Tests run.
Some functions will now be renamed for consistency with the
chrono crate.
2015-01-26 22:47:25 -08: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 45765ebd13 0.1.14: fixed a missing `String` impl for `Local`.
Fixes #20. Thanks to @daboross.
2015-01-10 12:32:54 +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