Commit Graph

17 Commits

Author SHA1 Message Date
Brandon W Maister 2839d8d7db Put wasm-bindgen and js-sys behind a wasm-bindgen feature gate
Fixes #334
2019-09-03 09:05:15 -04:00
eV f21b1fbf21 Fix emscripten and guard against cargo test + wasm32-unknown-unknown 2019-08-16 22:46:10 +00:00
Joey Ezechiels 8bfaca9f9b Add {Utc,Local}::now() constructor versions for the `wasm32` arch
While likely providing only incomplete support for WebAssembly, this
commit opens up chrono for use on the wasm32 architecture.
2019-08-16 07:46:02 +00:00
Jethro Beekman 5e68c60bb2 Add clock feature 2018-04-02 08:35:27 -07:00
Kang Seonghoon 7b9b0c4437
Renamed `chrono::UTC` to `chrono::Utc`.
Fixes #148.
2017-06-22 00:33:17 +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 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
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 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
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
Jisoo Park b5281af9f3 Add optional rustc-serialize support 2015-04-28 18:42:18 +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 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