Commit Graph

47 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
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
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 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
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
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
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
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 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 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 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
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
Ken Tossell 3303127415 Fixed build against rust nightly.
Added 'use' statements for cmd::Ordering, ops::{Add, Sub}, borrow::IntoCow, num::ToPrimitive

Changed deriving -> derive. Changed [x, ..N] -> [x; N].

Made format(f: &fmt::Formatter) return fmt::Result instead of
IoResult. Had to raise generic errors in a couple of cases where
IoResult's fields were being set (but these errors were being thrown
out anyway).

Temporarily set #![feature(old_orphan_check)] because

Thanks for @eddyb for explaining the format() situation.
2015-01-03 17:45:07 -05:00
Kang Seonghoon e982cd1851 0.1.5: language changes.
- Add and Sub requires a value instead of a reference.
- Tuple indexing is now ungated.

Fixes #15.
2014-12-17 10:29:48 +09:00
klutzy 37d85ffd3b Update for upstream changes 2014-12-13 20:29:06 +09:00
Kang Seonghoon 920a681d54 better documentation, some additional APIs.
- `Date/Time - Duration` is now supported. (duh!)
- `with_offset` methods have been added.
- `LocalResult` now implements common traits.
- `LocalResult` has several methods to propagate errors.
  this makes the initialization from untrusted sources easier
  (`off.ymd_opt(y,m,d).and_hms_opt(h,n,s).single()`).
2014-11-28 23:53:22 +09:00
Kang Seonghoon 86665d0a7f 0.1.2: no more `num` dependency, multidispatched addition.
- `num` dependency is gone. It was only used for floored division
  and it is not hard to copy only that portion from num.
- `Duration + Date` (or so) was blocked by rust-lang/rust#7590,
  which has been subsequently fixed.
- Removed unused `unsafe` checks.
2014-11-24 14:52:07 +09:00
Kang Seonghoon ec6c874042 language changes: namespaced enums, no more std::num::{Zero,Bounded}. 2014-11-19 10:59:32 +09:00
Kang Seonghoon 10c580f664 switches to std::time::duration::Duration. 2014-08-31 14:43:26 +09:00
Kang Seonghoon f1931ad21e added `chrono::format` module and `format` methods.
this is a saner replacement for `time::strftime`; it does not allocate
the additional memory.
2014-08-01 04:08:19 +09:00
Kang Seonghoon 9d52c6d2f1 added constructors from timestamp; added `UTC::{today,now}`. 2014-07-31 10:09:54 +09:00
Kang Seonghoon 95f5c0c095 splitted naive types into their own modules. 2014-07-29 16:17:26 +09:00