Commit Graph

300 Commits

Author SHA1 Message Date
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
Kang Seonghoon 883b656d49 0.1.10: language changes.
- `std::str::SendStr` is now `std::string::CowString<'static>`.
2015-01-06 10:44:08 +09:00
David Ross 1b04bc3697 Fixed build against lastest rust nightly, ad9e75938.
- updated all usages of SendStr to CowString<'static>
2015-01-06 00:20:40 +00: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 94df51861f 0.1.8: language changes.
- #[deriving] is now #[derive].
- prelude no longer imports many items by default.
- [T, ..n] is no longer valid.
- a temporary fix for #[derive(Hash)] failing out.
- the formatting error uses a dedicated type instead of `IoError`.
2015-01-04 15:14:57 +09:00
Kang Seonghoon 29428d0adf slight cleanup for chrono::format. 2015-01-04 15:11:18 +09:00
Kang Seonghoon cde432ed8e bumped copyright years. 2015-01-04 15:08:25 +09:00
Kang Seonghoon 50d73002d8 language changes: precedence change. 2015-01-04 15:05:56 +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 e53a8b0b01 oops, updated README.md. 2015-01-02 13:48:58 +09:00
Ken Tossell 221e58eca6 Removed reflexive type specifier from Date<Off>'s Eq implementation 2015-01-01 17:18:37 -05:00
Kang Seonghoon bf4ded9f07 0.1.6: fixed tests per language changes and .travis.yml.
This also switches to the crates.io dependency unconditionally.
2014-12-25 16:47:10 +09: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
Kang Seonghoon 389e58f727 added BIG limitations section to the README. 2014-12-13 22:16:38 +09:00
Kang Seonghoon 407ad383c5 fixed an edge case with date-changing offsets. 2014-12-13 21:53:53 +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 9e6576e37e language changes: MaybeOwned is deprecated, long live CowString! 2014-11-28 21:32:14 +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 0a04ae1aa9 0.1.1: language changes, updated documentations.
- `std::fmt::WriteError` is now `std::fmt::Error`.
- abandoned rust-ci for documentations (sorry, but it didn't work
  nowdays ;_;), we are now publishing directly to Github pages.
2014-11-21 16:18:55 +09:00
Kang Seonghoon e947b4eec6 language changes: str::shift_slice_char has been updated. 2014-11-20 13:09:16 +09:00
Kang Seonghoon ec6c874042 language changes: namespaced enums, no more std::num::{Zero,Bounded}. 2014-11-19 10:59:32 +09:00
Colin Ray fd5f8b7f34 Fix lint warning on deny(missing_doc) 2014-11-02 17:03:19 -06:00
Steve Klabnik 59892f1511 fail -> panic 2014-10-30 00:23:09 -04:00
Eunchong Yu 850e1d8654 Follow rustc master (1add4dedc 2014-10-10) 2014-10-12 00:56:49 +09:00
Kang Seonghoon d6e0c3f266 language changes: `extern crate A = "B";` -> `extern crate "B" as A;`. 2014-09-12 18:53:06 +09:00
Kang Seonghoon 10c580f664 switches to std::time::duration::Duration. 2014-08-31 14:43:26 +09:00
Kang Seonghoon 80ed400689 added missing `.offset()` methods; UTC/FixedOffset now implement Eq. 2014-08-29 18:14:08 +09:00
Kang Seonghoon 86259a120f language changes: an array size now needs to be uint. 2014-08-19 21:52:58 +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 ed71a1037b made `Time::fmt` to use the same decimal separator as `Duration::fmt`. 2014-07-31 11:03:32 +09:00
Kang Seonghoon ead13f66d8 added the Local offset implementation. 2014-07-31 11:02:20 +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
Kang Seonghoon 586b41df54 mass renaming from `BlahBlahZ` to `NaiveBlahBlah`. 2014-07-29 15:55:40 +09:00
Kang Seonghoon 32c3ee85e8 initial `Offset` implementations. 2014-07-29 15:41:47 +09:00
Kang Seonghoon 07d98709df fixed a bug on `DateTimeZ::add` with the negative fractional `Duration`. 2014-07-29 15:38:24 +09:00
Kang Seonghoon c7c3052892 made every type `Clone`able; added `and_*` constructors to `DateZ`.
it allows for, say, `DateZ::from_ymd(2014,1,2).and_hms(3,4,5)`.
2014-07-29 15:36:35 +09:00
Kang Seonghoon f77c8435c2 changed the internal representation of TimeZ. 2014-07-29 01:05:30 +09:00
Kang Seonghoon d5f652e656 renamed `n<foo>s` to `num_<foo>s` and changed their semantics.
`Duration` now has a `to_tuple` method which corresponds to
the original `(dur.ndays(), dur.nseconds(), dur.nnanoseconds())`.
new `num_*s()` methods in `Duration` always return the integral
number of specified units in the duration.

cf. rust-lang/rust#15934
2014-07-25 21:00:32 +09:00
Kang Seonghoon 9300f2481c renamed `chrono:📅:{MIN,MAX}` to `chrono:📅:{MINZ,MAXZ}`.
this is because we are going to add `MIN` and `MAX` for
timezone-aware `Date`s later.
2014-07-25 19:24:32 +09:00
Kang Seonghoon 4dbd00dca2 added all missing docs. 2014-07-25 18:12:51 +09:00
Kang Seonghoon 2f35fbc0fd changed the decimal point from `,` to `.`. (cf. rust-lang/rust#15934)
ISO 8601 allows for both but prefers `,`, which was a main reason
for its use in rust-chrono. but this is too alien given other usages of
decimal points in Rust, so I guess it is better to switch to `.`.
2014-07-25 17:35:49 +09:00
Kang Seonghoon 110c7de7d3 added docs to `Duration`; added `Duration::new_opt`; removed `{MIN,MAX}_{DAYS,YEAR}`.
the minimum and maximum for `DateZ` and `Duration` is now provided via
dedicated constants `{date,duration}::{MIN,MAX}`, much like built-in
`std::int` and others. they also now implements `std::num::Bounded`.

cf. rust-lang/rust#15934
2014-07-25 17:05:26 +09:00
Kang Seonghoon f7065f1625 fixed erratic `fmt` behaviors with format specifiers. (rust-lang/rust#15934) 2014-07-25 16:20:39 +09:00
Kang Seonghoon b79f6b302b major API surgeries.
- added a new example.
- reexported all public APIs in the crate root.
- made all constructors fail on the invalid arguments by default;
  `*_opt()` variants have been added for the original behavior.
- same for `DateZ::{succ,pred}`.
- fixed a missing overflow check from `TimeZ::from_hms_{milli,micro}`.
2014-07-20 02:51:57 +09:00
Kang Seonghoon dce4ec8f45 the public API now uses i32/u32 instead of int/uint for integers.
closes #1.
2014-07-20 02:00:33 +09:00
Kang Seonghoon b5a2340214 updated .travis.yml to use install.sh for Cargo; src/chrono -> src. 2014-07-15 13:20:48 +09:00
Kang Seonghoon 39d723fc6f eliminated #![feature(globs)]. 2014-07-15 12:53:40 +09:00
Kang Seonghoon 11b2a10247 added Cargo support and updated .travis.yml; language changes: ToStr -> ToString. 2014-07-13 00:12:13 +09:00
Kang Seonghoon 75d90a56fa language changes: {,Total}{Eq,Ord} -> {Partial,}{Eq,Ord}. 2014-06-01 01:36:59 +09:00
Kang Seonghoon b11484613f fixed an unintentionally overflowing Duration constructors; made tests valid on 32-bit platform. 2014-05-31 00:12:38 +09:00
Kang Seonghoon c697e1fd92 language changes: to_owned() on &str is being deprecated. 2014-05-30 02:18:27 +09:00
Kang Seonghoon 28ceb1e3db language changes: std::fmt is moved to core and now independent of std I/O. 2014-05-23 23:45:12 +09:00
Kang Seonghoon ddab09459b language changes: ~"str" -> "str".to_owned(). 2014-05-16 17:04:21 +09:00
Kang Seonghoon f8a05676b7 language changes: BenchHarness -> Bencher. 2014-04-27 04:39:48 +09:00
Kang Seonghoon e40be225fe added (not yet well-tested) mult/div ops for Duration. 2014-04-07 03:16:33 +09:00
Kang Seonghoon f7c03b536f language changes: priv tuple-like fields are now default as well. 2014-04-04 18:09:22 +09:00
Kang Seonghoon 87c45837c8 Duration::days is now i32 (not int), related methods apply the new limits for days. 2014-04-04 00:41:40 +09:00
Kang Seonghoon b24b5b46a3 proper licensing, added README. 2014-04-02 02:14:57 +09:00
Kang Seonghoon 5516dc630d language changes: #[]; -> #![], priv fields by default; added .travis.yml. 2014-04-02 01:30:52 +09:00
Kang Seonghoon 0f6ccf0728 switched the internal Date representation from Mdf to Of; made most Date operations representation-agnostic. 2014-03-31 15:34:21 +09:00
Kang Seonghoon 75c21b0c3e fixed some issues on negative division/modulo. 2014-03-31 14:33:47 +09:00
Kang Seonghoon c9ec9ee63f DateTimeZ now supports arithmetic operations. 2014-03-30 05:13:44 +09:00
Kang Seonghoon 49737e992f DateZ now supports arithmetic operations. 2014-03-30 04:52:37 +09:00
Kang Seonghoon 877ceaeca0 TimeZ supports arithmetic operations. 2014-03-30 00:12:50 +09:00
Kang Seonghoon 27d4daad11 added Duration; DateZ::fmt now formats the out-of-range years correctly. 2014-03-29 17:20:39 +09:00
Kang Seonghoon 715a35caa6 {Date,Time,DateTime} -> {DateZ,TimeZ,DateTimeZ}, in order to distinguish them from the timezone-aware types. 2014-03-28 21:56:38 +09:00
Kang Seonghoon 646b6c27b9 initial commit. 2014-03-28 20:38:11 +09:00