Skip to content

Commit

Permalink
Merge branch 'master' into sqlx-jiff
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun committed Jan 5, 2025
2 parents 9d4000c + 737076a commit c6590fe
Show file tree
Hide file tree
Showing 25 changed files with 2,656 additions and 338 deletions.
52 changes: 49 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,61 @@
# CHANGELOG

0.1.19 (TBD)
============
TODO
0.1.21 (2025-01-04)
===================
This release includes a new API for setting the unit designator label in a
friendly formatted duration for zero-length durations.

Enhancements:

* [#192](https://github.com/BurntSushi/jiff/issues/192):
Add option to the friendly printer for setting the unit when writing a
zero-length duration.


0.1.20 (2025-01-03)
===================
This release inclues a new type, `Pieces`, in the `jiff::fmt::temporal`
sub-module. This exposes the individual components of a parsed Temporal
ISO 8601 datetime string. It allows users of Jiff to circumvent the checks
in the higher level parsing routines that prevent you from shooting yourself
in the foot.

For example, parsing into a `Zoned` will return an error for raw RFC 3339
timestamps like `2025-01-03T22:03-05` because there is no time zone annotation.
Without a time zone, Jiff cannot do time zone aware arithmetic and rounding.
Instead, such a datetime can only be parsed into a `Timestamp`. This lower
level `Pieces` API now permits users of Jiff to parse this string into its
component parts and assemble it into a `Zoned` if they so choose.

Enhancements:

* [#188](https://github.com/BurntSushi/jiff/issues/188):
Add `fmt::temporal::Pieces` for granular datetime parsing and formatting.


0.1.19 (2025-01-02)
===================
This releases includes a UTF-8 related bug fix and a few enhancements.

Firstly, a `Span`'s default `Display` implementation now writes uppercase
unit designator labels. That means you'll get `P1Y2M3DT4H5M6S` instead
of `P1y2m3dT4h5m6s` by default. You can restore previous behavior via
`jiff::fmt::temporal::SpanPrinter::lowercase`. This change was made to improve
interoperability.

Secondly, `SignedDuration` now supports rounding via `SignedDuration::round`.
Note that it only supports rounding time units (hours or smaller). In order to
round with calendar units, you'll still need to use a `Span`.

Enhancements:

* [#130](https://github.com/BurntSushi/jiff/issues/130):
Document value ranges for methods like `year`, `day`, `hour` and so on.
* [#187](https://github.com/BurntSushi/jiff/issues/187):
Add a rounding API (for time units only) on `SignedDuration`.
* [#190](https://github.com/BurntSushi/jiff/issues/190):
`Span` and `SignedDuration` now use uppercase unit designator labels in their
default ISO 8601 `Display` implementation.

Bug fixes:

Expand Down
2 changes: 1 addition & 1 deletion COMPARE.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ use jiff::{Span, ToSpan};
fn main() -> anyhow::Result<()> {
let span = 5.years().months(2).days(1).hours(20);
let json = serde_json::to_string_pretty(&span)?;
assert_eq!(json, "\"P5y2m1dT20h\"");
assert_eq!(json, "\"P5Y2M1DT20H\"");

let got: Span = serde_json::from_str(&json)?;
assert_eq!(got, span);
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jiff"
version = "0.1.18" #:version
version = "0.1.21" #:version
authors = ["Andrew Gallant <[email protected]>"]
license = "Unlicense OR MIT"
repository = "https://github.com/BurntSushi/jiff"
Expand Down
4 changes: 2 additions & 2 deletions src/civil/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,11 +1635,11 @@ impl Date {
///
/// // The default limits durations to using "days" as the biggest unit.
/// let span = d1.until(d2)?;
/// assert_eq!(span.to_string(), "P8456d");
/// assert_eq!(span.to_string(), "P8456D");
///
/// // But we can ask for units all the way up to years.
/// let span = d1.until((Unit::Year, d2))?;
/// assert_eq!(span.to_string(), "P23y1m24d");
/// assert_eq!(span.to_string(), "P23Y1M24D");
///
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/civil/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1775,11 +1775,11 @@ impl DateTime {
///
/// // The default limits durations to using "days" as the biggest unit.
/// let span = dt1.until(dt2)?;
/// assert_eq!(span.to_string(), "P8456dT12h5m29.9999965s");
/// assert_eq!(span.to_string(), "P8456DT12H5M29.9999965S");
///
/// // But we can ask for units all the way up to years.
/// let span = dt1.until((Unit::Year, dt2))?;
/// assert_eq!(span.to_string(), "P23y1m24dT12h5m29.9999965s");
/// assert_eq!(span.to_string(), "P23Y1M24DT12H5M29.9999965S");
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
///
Expand Down
4 changes: 2 additions & 2 deletions src/civil/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,12 +1198,12 @@ impl Time {
///
/// // The default limits spans to using "hours" as the biggest unit.
/// let span = t1.until(t2)?;
/// assert_eq!(span.to_string(), "PT12h5m29.9999965s");
/// assert_eq!(span.to_string(), "PT12H5M29.9999965S");
///
/// // But we can ask for smaller units, like capping the biggest unit
/// // to minutes instead of hours.
/// let span = t1.until((Unit::Minute, t2))?;
/// assert_eq!(span.to_string(), "PT725m29.9999965s");
/// assert_eq!(span.to_string(), "PT725M29.9999965S");
///
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
Expand Down
13 changes: 7 additions & 6 deletions src/fmt/friendly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ format when using the `std::fmt::Display` trait implementation:
use jiff::{SignedDuration, ToSpan};
let span = 2.months().days(35).hours(2).minutes(30);
assert_eq!(format!("{span}"), "P2m35dT2h30m"); // ISO 8601
assert_eq!(format!("{span}"), "P2M35DT2H30M"); // ISO 8601
assert_eq!(format!("{span:#}"), "2mo 35d 2h 30m"); // "friendly"
let sdur = SignedDuration::new(2 * 60 * 60 + 30 * 60, 123_456_789);
assert_eq!(format!("{sdur}"), "PT2h30m0.123456789s"); // ISO 8601
assert_eq!(format!("{sdur}"), "PT2H30M0.123456789S"); // ISO 8601
assert_eq!(format!("{sdur:#}"), "2h 30m 123ms 456µs 789ns"); // "friendly"
```
Expand Down Expand Up @@ -467,10 +467,11 @@ P1Y2M3DT4H59M1.1S
P1y2m3dT4h59m1.1S
```
When all of the unit designators are capital letters in particular, everything
runs together and it's hard for the eye to distinguish where digits stop and
letters begin. Using lowercase letters for unit designators helps somewhat,
but this is an extension to ISO 8601 that isn't broadly supported.
When all of the unit designators are capital letters in particular (which
is the default), everything runs together and it's hard for the eye to
distinguish where digits stop and letters begin. Using lowercase letters for
unit designators helps somewhat, but this is an extension to ISO 8601 that
isn't broadly supported.
The "friendly" format resolves both of these problems by permitting sub-second
components and allowing the use of whitespace and longer unit designator labels
Expand Down
Loading

0 comments on commit c6590fe

Please sign in to comment.