Commit Graph

418 Commits

Author SHA1 Message Date
Brandon W Maister 371cf6d29b Adjust timezones after doing Duration addition
The internal, tz-independent timestamp was valid, but since the timezone offset
could change as you add or subtract a second or two you would get
nonsense/nonexistent times when you observed them.

Fixes #318
2019-09-02 14:58:54 -04:00
Brandon W Maister 6ce91fbfbb allow deprecated inclusive range patterns
We still support ancient Rust.
2019-08-31 15:40:11 -04:00
eV cc073a650f remove cargo web / compile time error 2019-08-22 08:09:56 +00:00
eV f21b1fbf21 Fix emscripten and guard against cargo test + wasm32-unknown-unknown 2019-08-16 22:46:10 +00:00
eV 5d38faeb40 fix local timezone, add tests 2019-08-16 09:35:56 +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
Brandon W Maister 7412469623
Merge pull request #325 from chronotope/double-check-negative-odd-timestamp-millis
Add a test for negative odd-numbered timestamp_millis
2019-08-06 21:25:35 -04:00
Lane Kolbly c80878ce4e Change src/lib rather than readme directly 2019-07-18 07:37:37 -05:00
Brandon W Maister f0ea789a9c Add a test for negative odd-numbered timestamp_millis
Just in case, because of #324
2019-06-27 20:40:35 -04:00
Brandon W Maister b1592e0e22 Add parse tests for fws and leading-0 to RFC2822 2019-06-24 22:05:06 -04:00
wyhaya a1d304b035 Add '0' to RFC2822 2019-06-24 22:05:06 -04:00
Samokhin Ilya 5b0818e0a1 changed back from impl Trait in fn parameter to support older compiler versions 2019-06-23 10:09:47 +03:00
Samokhin Ilya f57ac3671e add test and format every item into String first, then pad it 2019-06-23 09:43:06 +03:00
SamokhinIlya 8b2444c27f DelayFormat now works with alignment and width 2019-06-21 23:44:49 +03:00
Guillaume Gomez b7003373f2 Add doc-comment to test README examples and fix README examples 2019-04-30 23:29:57 +02:00
kennytm 20a0ab7a47
Mark `FixedOffset::{local_minus_utc, utc_minus_local}` as `#[inline]`. 2019-04-22 03:07:01 +08:00
kennytm d3dc9c0e10
derive {Copy, Eq, Hash} for LocalResult. 2019-04-21 15:42:11 +08:00
Brandon W Maister bcdc66a4f8
Merge pull request #271 from mqudsi/offset_convert
Add std::convert::From conversion between different DateTime offsets
2019-04-08 12:37:01 -04:00
Mahmoud Al-Qudsi ad6872c498 Predicate `Local` conversion fns on `clock` feature 2019-04-08 10:06:30 -05:00
Brandon W Maister 97cc89e1fa Merge remote-tracking branch 'origin/master' into feature/option 2019-04-07 17:54:08 -04:00
Brandon W Maister 5dc8a68dde
Merge pull request #308 from jean-airoldie/time_zone_from_nanos
Add timestamp_nanos generated method for TimeZone
2019-04-07 17:41:52 -04:00
Brandon W Maister 855a894393 Don't warn on deprecated trim functions 2019-03-31 19:03:18 -04:00
Brandon W Maister 33800c876b Add docs around panic behavior around timestamp_nanos
Document panic behavior that should have been documented better.

Resolves #310
2019-03-31 19:03:18 -04:00
jean-airoldie c92544923d Add timestamp_nanos generated method for TimeZone 2019-03-06 10:32:40 -05:00
Andrei Nesterov 662c76294b
Add Serialize/Deserialize for Option<DateTime> 2019-01-27 09:17:42 -08:00
Casey Marshall b39597f537 Fix panic for negative inputs to timestamp_millis.
This patch fixes the case where a negative millisecond offset is passed
to Timezone::timestamp_millis and timestamp_millis_opt and adds a test
case for it. Without this patch, calling timestamp_offset with a
negative value will panic with an overflow like this:

```
---- tests::test_parse_samples stdout ----
thread 'tests::test_parse_samples' panicked at 'attempt to multiply with
overflow',
/home/c/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.6/src/offset/mod.rs:349:34
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a
verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing:👿:unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:221
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:477
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:391
   6: rust_begin_unwind
             at libstd/panicking.rs:326
   7: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   8: core::panicking::panic
             at libcore/panicking.rs:52
   9: chrono::offset::TimeZone::timestamp_millis_opt
             at
/home/c/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.6/src/offset/mod.rs:349
  10: chrono::offset::TimeZone::timestamp_millis
             at
/home/c/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.6/src/offset/mod.rs:327
```
2018-12-02 11:26:42 -06:00
Brandon W Maister 5dc483990a
Merge pull request #282 from 3point2/doc-grammar
Grammar fix for docs
2018-11-26 23:23:36 -05:00
Vasili Revelas 8abaae199e Grammar fix for docs 2018-10-27 13:09:32 +03:00
Pascal Bach fd22be2c8f Correct link to standard Durtation
The link mentioning standard Duration was still linking to the
Duration from the time crate
2018-10-09 23:19:59 +02:00
Mahmoud Al-Qudsi 973c603d7a Add basic conversion test 2018-09-05 19:08:46 -05:00
Mahmoud Al-Qudsi 7f4d0da7f1 Add doc ccomments for conversions between `DateTime` flavors
Documentation added to both `impl`s and functions so that they are
visible to both users perusing the online documentation and in
autocomplete/intellisense engines.
2018-09-05 18:25:32 -05:00
Brandon W Maister 2e563bc652 Make README.md match lib.rs mod documentation
And fail CI in the future if `make readme` isn't run when it is needed.

CC conversation in #185, where the README didn't get updated for a year after
lib.rs was improved.
2018-08-25 16:24:07 -04:00
Alex Sayers 892bbf3f3a Add NaiveDate::from_ymwd_opt, implement from_ymwd in terms of it 2018-08-13 11:29:02 +09:00
Alex Sayers 4ffd411654 Add NaiveDate::from_ymwd
This contructor allows you to make a NaiveDate by specifying eg. "the
2nd Friday of March 2017".  It contains a couple of panics, but these
are consistent with the behaviour of the other NaiveDate constructors.
2018-08-13 11:29:02 +09:00
Mahmoud Al-Qudsi 855d5f2772 Add initial implementation of std::convert::From for DateTime offsets
Adds conversion to/from Utc, Local, and FixedOffset. Originally planned
to go through NaiveDateTime, but it seems that is not necessary?
2018-08-11 22:12:11 -05:00
Brandon W Maister 369ce72987
Merge pull request #252 from quodlibetor/negative-timestamps
Add doctests around negative timestamps
2018-07-28 17:07:04 -04:00
Brandon W Maister 55538b5b9c
Merge pull request #268 from quodlibetor/TimeZone-timestamp-millis
Add `timestamp_millis` and `timestamp_millis_opt`
2018-07-28 16:41:34 -04:00
Brandon W Maister a58a833324 Add doctests for negative timestamps 2018-07-28 16:40:26 -04:00
Brandon W Maister 5481dec823 Don't warn on an unknown allowed clippy lint 2018-07-28 15:25:37 -04:00
Brandon W Maister 19955ac992 Add `timestamp_millis` and `timestamp_millis_opt`
Fixes #264
2018-07-28 15:18:32 -04:00
Brandon W Maister 512f21d481
Merge pull request #258 from novacrazy/extra-serde
Extra serde modules for various timestamp formats.
2018-07-28 14:45:42 -04:00
storyfeet 611abbd7ae trivially copy pass by ref 2018-07-18 21:38:37 -04:00
storyfeet b9b09b8e11 Tried to make it easier to find specifiers 2018-07-18 21:38:37 -04:00
novacrazy a88ee8f719 Fix doc 2018-07-18 04:45:11 -05:00
novacrazy 4a66b17bd0 Add docs/tests and fix math 2018-07-04 14:12:36 -05:00
novacrazy 5df91c3985 Add WIP millisecond serde implementation 2018-07-04 10:38:39 -05:00
寧靜 a99dee655e Update fixed.rs 2018-06-24 05:45:24 +08:00
Brandon W Maister df4912a33f Test formatting with more precise nanoseconds
There is some specific behavior around writing out truncated nanos that we want
to be sure to preserve.
2018-06-13 23:00:31 -04:00
Evan Schwartz 11cfb3696e Move NanosecondXNoDot to internal enum
To avoid adding new variants to the public enum (see https://github.com/chronotope/chrono/pull/251#issuecomment-396692148)
2018-06-12 14:53:49 -04:00
Evan Schwartz 937189ee52 Take exactly num digits specified for nanosecond fixed
Error if it's too long or short, and don't take any more digits
2018-06-12 10:51:38 -04:00
Evan Schwartz 8a2b09962a Only parse up to max number of digits for nanoseconds w/o dots 2018-06-12 10:51:38 -04:00
Evan Schwartz 074e92fc63 Document millisecond format without the dot 2018-06-12 10:51:36 -04:00
Evan Schwartz f9d3094d4e Test nanosecond parsing without the dot 2018-06-12 10:51:07 -04:00
Evan Schwartz 1de3658433 Add nanoseconds without dots 2018-06-12 10:51:07 -04:00
Brandon W Maister c3207a5811 Use the `InternalFixed` struct for TimezoneOffsetPermissive
It is the backcompat scheme that we have. In the 5.x timeline we will add the
more-standard and significantly-more-pleasant-to-expand `#[doc(hidden)]
__DoNotMatchAgainstMe` trick.
2018-06-07 21:46:57 -04:00
Brandon W Maister 9991c2b0ed Rust 1.13 does not support elided lifetimes in const. 2018-06-07 21:46:57 -04:00
Brandon W Maister 95f6a2be1c Add %#z as "Permissive" timezone parsing
This allows you to parse a timezone that:

* Is either `Z` or an actual offset
* Contains no minutes, just the hour

Fixes #219
2018-06-07 21:46:57 -04:00
Thomas Bytheway 90c75885d0 Rename ts_nano_seconds to ts_nanoseconds 2018-05-24 13:44:12 +01:00
Thomas Bytheway cdb6170f02 Add serde functions for nanosecond timestamps 2018-05-18 11:05:03 +01:00
Thomas Bytheway cc613976a4 Add functions to present DateTime in nanoseconds since epoch 2018-05-18 11:04:39 +01:00
Brandon W Maister ebd16f49d2
Merge pull request #237 from tobz1000/datetime-diff-sub
impl Sub<T> for T for Date/Time types
2018-04-03 19:30:15 -07:00
Toby Dimmick 19466e6ff4 Move `SubAssign<OldDuration> next to `Sub<OldDuration` 2018-04-03 14:16:37 +01:00
Toby Dimmick d9a50cb767 Documentation 2018-04-03 14:14:52 +01:00
Brandon W Maister a9618c8e9d
Merge branch 'master' into feature_clock 2018-04-03 05:54:17 -07:00
Brandon W Maister a060684abe
Merge pull request #174 from quodlibetor/deprecated-warnings-for-rustc_serialize
Deprecated warnings in cargo output for rustc-serialize feature
2018-04-03 05:52:58 -07:00
Toby Dimmick d5d5fd92b7 impl Sub<T> for <T> for Date/Time types 2018-04-03 13:42:03 +01:00
Jethro Beekman 5e68c60bb2 Add clock feature 2018-04-02 08:35:27 -07:00
Philipp Hansch 3fb0b614e8
Revert "Allow a false-positive clippy lint"
The issue has been fixed with the latest clippy release and we don't
have to `allow` anymore.

This reverts commit 7f990144cc.
2018-04-01 12:40:14 +02:00
Jethro Beekman 6c398ae6f4 Remove dependencies from oldtime::Duration on rest of time crate 2018-03-30 16:08:45 -07:00
Jethro Beekman 5e730ebe4d Vendor oldtime::duration module from time crate
https://github.com/rust-lang-deprecated/time/blob/master/src/duration.rs
2018-03-30 16:08:45 -07:00
Brandon W Maister 39ca2e622c Deprecated warnings in cargo output for rustc-serialize feature
Unfortunately due to rust-lang/rust#39935 placing the annotation on the `impl`s
of `Encodable`/`Decodable` for the various items have no effect whatsoever, so
we need to place it on some type that chrono actually uses internally. The only
*type* that I can find that only exists for rustc-serialize only is the
 `TsSeconds` struct.

So, marking TsSeconds deprecated causes Chrono's internal uses of `TsSeconds`
to emit deprecation warnings, both in our builds and for packages that specify
Chrono as a dependency with the `rustc-serialize` feature active. This means
that the current commit will cause a `warning: use of deprecated item:
RustcSerialize will be removed before chrono 1.0, use Serde instead` to appear
in `cargo build` output.

Unfortunately I don't think that it's possible for downstream crates to disable
the warning the warning in any way other than actually switching to Serde or
using an older chrono. That's the reason for all the `#[allow(deprecated)]`
through the code, it means that the warning appears almost exactly once,
instead of dozens of times.
2018-03-29 14:32:39 -04:00
Brandon W Maister 1a983261e3 Ensure that `SecondsFormat` can be expanded semver-safely 2018-03-26 22:10:21 -04:00
Brandon W Maister c9609ea6c9
Merge pull request #217 from dekellum/round
Add SubsecRound trait
2018-03-05 23:23:47 -05:00
David Kellum 449d7277b9 Rename SubSecondRound to SubsecRound
Per review request.
2018-03-05 12:57:26 -08:00
David Kellum 08b7e0bc6b Fix prelude SubSecondRound 2018-03-05 10:40:50 -08:00
David Kellum cb3a73aa86 Rename to (round/trunc)_subsecs; add doc tests 2018-03-05 10:38:48 -08:00
David Kellum 74ec7aa5b2 Improve up/down variable naming 2018-03-04 18:27:36 -08:00
Brandon W Maister 2a825edd5c
Merge pull request #221 from cuviper/num-no_std
Use no_std-compatible num dependencies
2018-03-04 18:21:50 -05:00
Brandon W Maister 7f990144cc Allow a false-positive clippy lint
rust-lang-nursery/rust-clippy#2475 , we'll revert this commit when that's
fixed.
2018-03-04 09:51:41 -05:00
Brandon W Maister 2ee549f84f Allow a clippy lint that depends on rust 1.17 2018-03-04 09:18:02 -05:00
Josh Stone 8f90f405d5 Use no_std-compatible num dependencies
Rather than the `num` meta-crate, use `num-integer` and `num-traits`
without default features to make them `#[no_std]`.  `num-iter` is
just a dev-dependency now for a few test cases.

The only public change is the `impl FromPrimitive for Weekday`, but this
is still the same exact trait that `num` re-exports, so this is not a
breaking change.
2018-02-23 00:07:16 -08:00
David Kellum b5acb0ed95 Add SubSecondRound extension trait with impl for Timelike 2018-01-30 12:12:16 -08:00
Brandon W Maister ff962d452c
Merge pull request #205 from dekellum/rfc3339pz
Add DateTime to_rfc3339p(z) methods, tests
2018-01-29 22:16:53 -05:00
David Kellum e8fdbdf41d Rustdoc and naming improvements 2018-01-26 11:42:08 -08:00
David Kellum 1a0ebe7e30 Add more specific SecondsFormat and offer single to_rfc3339_opts 2018-01-25 14:25:04 -08:00
kennytm 8a6a99018a
Fix a markdown rendering difference warning.
Rust is going to change its Markdown rendering engine from hoedown to
pulldown-cmark. In pulldown, a table row starting with just whitespaces
will cause that whole cell disappeared. This causes rendering difference
between the two engines.

To fix this, we add leading and trailing `|` to the rows so that empty
cells are correctly rendered.
2018-01-22 02:34:15 +08:00
David Kellum efb0f3b015 Clippy no likey a match on bool 2018-01-18 11:07:23 -08:00
David Kellum 0e6d1d49b7 cleanup name resolution for backward compatibility
so it builds with rustc 1.13
2018-01-18 11:07:23 -08:00
David Kellum 353a7bbbc4 Use const for compat with rustc 1.13-16
Was using static but that's only supported as of rustc 1.17 (rust
these older versions. Also continue using the copious explicit 'static
lifetimes for the same compatibility, despite the clippy lint.
2018-01-18 11:07:23 -08:00
David Kellum d2bf1494b1 Add DateTime to_rfc3339p(z) methods, tests
These additions allow convenient control of RFC 3339 formatted output:

 * Number of subsecond digits to display

 * Whether to use the 'Z' variant, instead of "+00:00" for TZ offset
   0, UTC.

...while remaining faithful to the RFC 3339. The implementation uses
the existing formatting Item mechanism.

github: cc: #157 #178
2018-01-18 11:07:23 -08:00
David Kellum 9742ecccc5 Allow (clippy) needless_pass_by_value on signed_duration_since
Current clippy is probably correct, but its a breaking change that
isn't appropriate now. Add allow's to get the build working again.

Also these Date(Time)::signed_duration_since cases appear to match
there `Naive` counterparts, where clippy isn't complaining. If its
fixed in the future, should probably be changed across the board, not
just here.
2018-01-17 11:49:06 -08:00
David Kellum 4748225550 allow(const_static_lifetime) is for feature cargo-clippy 2018-01-12 16:17:53 -08:00
David Kellum f93c8a993d Add top level clippy allow const_static_lifetime
github: cc: #205
2018-01-12 15:16:06 -08:00
Brandon W Maister 5bb493976b Add a note and example to DateTime::parse_from_str
The note points out that `NaiveDateTime::parse_from_str` is required if you
don't know the offset, and the example demonstrates that.

Closes #183
2017-10-09 21:23:22 -04:00
Jordan Petridis 1286ad12d3
Merge branch 'master' of https://github.com/chronotope/chrono 2017-10-09 15:30:08 +03:00
Jordan Petridis 57c98a409e
Added underscores on long numbers. 2017-10-09 14:47:07 +03:00
Jordan Petridis 532c025a77
Minor doc wording changes. 2017-10-09 02:03:18 +03:00
Brandon W Maister c3fa1b5f17 Fix Clippy lints: cast_lossless
Now (assuming clippy is right) all (~100) uses of ` as ` in the code are
actually doing casts that could potentially silently lose data. Woooo?

At least this means that new `as`s can be extra-scrutinized, and we should
probably be adding debug_assert!s for the casts in real code.
2017-10-08 18:12:20 -04:00
Brandon W Maister 268be10d79 Fix Clippy lints: unreadable_literal and inconsistent_digit_grouping
Use `_` consistently in long numeric literals.
2017-10-08 17:38:41 -04:00
Jordan Petridis 7e2f2e0bea
Added examples/doctests for how to get a datetime from an epoch and vice versa. 2017-09-29 19:24:40 +03:00