Commit Graph

199 Commits

Author SHA1 Message Date
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
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 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