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.