The implementation is identical to how #[derive] would do it, and we use the
implementation to add some documentation warning people not to use items with
nanosecond-level precision in hash maps unless they're sure that's what they
want.
Starting from this version the `CHANGELOG.md` file is the canonical
source for the list of significant changes. See the file for details.
Fixes#146.
Fixes#159.
Due to the obvious lack of time zone information in `SystemTime`,
`SystemTime` can only be converted to `DateTime<Utc>` (in UTC) or
`DateTime<Local>` (in the local time zone), while any `DateTime<Tz>`
can be converted to `SystemTime`.
This removes `Datelike::isoweekdate` in favor of `Datelike::iso_week`.
The original `isoweekdate` was not named in accordance with the style
guide and also used to return the day of the week which is already
provided by `Datelike::weekday`. The new design should be more
reasonable.
Note that we initially do not implement any public constructor for
`IsoWeek`. That is, the only legitimate way to get a new `IsoWeek` is
from `Datelike::iso_week`. This sidesteps the issue of boundary values
(for example the year number in the maximal date will overflow in
the week date) while giving the same power as the original API.
Partially accounts for #139. We may add additional week types
as necessary---this is the beginning.
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>
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).
I think it's a terrible API, but AFAIK rustc-serialize doesn't support anything
like serde's `with` attribute.
I think it would be better to just not include this API at all and require that
people who want to use this move to serde, which is the recommended rust
encoding/decoding library.
This introduces a newtype around DateTime and NaiveDateTime that deserlization
is implemented for.
There are two advantages to this over the previous implementation:
* It is expandable to other timestamp representations (e.g. millisecond and
microsecond timestamps)
* It works with RustcSerialize::Decodable. AFAICT Decodable will error if you
try to call more than one of the `read_*` functions in the same `decode`
invocation. This is slightly annoying compared to serde which just calls the
correct `visit_*` function for whatever type the deserializer encounters.
On the whole I think that I prefer this to the previous implementation of
deserializing timestamps (even though I don't care about RustcSerialize in the
post-1.15 world) because it is much more explicit.
On the other hand, this feels like it's introducing a lot of types, and
possibly making downstream crates introduce a variety of different structs for
ser/de and translating into different struct types.
Timestamps are defined in terms of UTC, so what this does is, if we encounter
an integer instead of a str, create a FixedOffset timestamp with an offset of
zero and create the timestamp from that.
- Serde 1.0 is now supported. (#142)
Technically this is a breaking change, but the minor version was not
effective in avoiding dependency breakages anyway (because Cargo
will silently compile two versions of crates). Provided that this is
likely the last breakage from Serde, we tolerate
this more-than-last-minute change in this version.
- `Weekday` now implements `FromStr`, `Serialize` and `Deserialize`.
(#113)
- Fixed a bug that the leap second can be mapped wrongly
in the local tz with some conditions. (#130)
- Some changes to the tests to avoid previously known issues.
Note that the actually published version is very slightly different
from the repository because no published version of bincode supports
Serde 1.0 right now.
So this is a much delayed major release, but this should not really
change how you use Chrono---only the "required" breakages have been
done (e.g. anything hindering API evolution). The "big" release used to
be 0.3, but due to the dependency changes we are forced to push that to
0.4. I've took this opportunity to push all known planned breaking
changes to 0.3, so this should be quite stable for a moment.
See `CHANGELOG.md` for the full list of changes, but most importantly:
- `chrono::prelude` module has been added for proper glob imports.
- `FixedOffset` is now the official "value" type for time zone offsets.
- Serde 0.9 support has landed, and serialization format used by
rustc-serialize and Serde has been now synchronized.
- Formatting items have been slightly adjusted to be future-proof.
Fixes#126.
The intention was to add newer methods using `std::time::Duration`
to the older names, but it will break the API compatibility anyway.
Better to completely remove them right now.
- Formatting item types are no longer `Copy`.
- `Numeric` and `Fixed` items now have `Internal` variants reserved
for the future expansion. It had been hard to expand the items
without totally breaking the backward compatibility (as per
the API evolution guideline of RFC 1105).
- `Item::Owned{Literal,Space}` for the owned variant of
`Item::{Literal,Space}` has been added.
Closes#76.
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.
- 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.
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`.
All CI accounts are now moved to the new organization (unfortunately
Appveyor does not automatically move the build history though).
Since it's a mess to redirect everything to chronotope.github.io,
I've taken this as an opportunity to switch to docs.rs---this seems
to be better than the manual management nowadays.
Updated other files as accordingly.
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.
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.
- `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.)
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.)
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.
- 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)
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.
- 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)
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.
- 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.
* 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.
- `%.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)