Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollup a number of recent PRs #165

Merged
merged 7 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# CHANGELOG

0.1.16 (TBD)
============
TODO

Enhancements:

* [#143](https://github.com/BurntSushi/jiff/pull/143):
Add `Hash` implementation for `Zoned` and `Timestamp`.

Bug fixes:

* [#138](https://github.com/BurntSushi/jiff/issues/138):
Fix deserialization in `serde_yml` and `serde_yaml` crates.
* [#161](https://github.com/BurntSushi/jiff/pull/161):
Fix `serde` dependency configuration so that it builds in no-std mode.


0.1.15 (2024-11-30)
===================
This release fixes a bug where Jiff would sometimes fail to parse TZif files
Expand All @@ -11,6 +28,8 @@ clamping the out-of-range transitions to Jiff's supported range.
This bug only seems to occur in some environments where their TZif files
contain more extreme values than what is typically found.

Bug fixes:

* [#163](https://github.com/BurntSushi/jiff/issues/163):
Fix a bug where Jiff would fail to parse some TZif files.

Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ members = [
# https://docs.rs/jiff/*/#crate-features
[features]
default = ["std", "tz-system", "tzdb-bundle-platform", "tzdb-zoneinfo"]
std = ["alloc"]
alloc = []
std = ["alloc", "serde?/std"]
alloc = ["serde?/alloc"]
serde = ["dep:serde"]
logging = ["dep:log"]

Expand Down Expand Up @@ -77,7 +77,7 @@ js = ["dep:wasm-bindgen", "dep:js-sys"]
[dependencies]
jiff-tzdb = { version = "0.1.1", path = "jiff-tzdb", optional = true }
log = { version = "0.4.21", optional = true }
serde = { version = "1.0.203", optional = true }
serde = { version = "1.0.203", optional = true, default-features = false }

# Note that the `cfg` gate for the `tzdb-bundle-platform` must repeat the
# target gate on this dependency. The intent is that `tzdb-bundle-platform`
Expand Down Expand Up @@ -110,6 +110,7 @@ jiff = { path = "./", features = ["serde"] }
quickcheck = { version = "1.0.3", default-features = false }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
serde_yml = "0.0.12"
tabwriter = "1.4.0"
time = { version = "0.3.36", features = ["local-offset", "macros", "parsing"] }
tzfile = "0.1.3"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ improve datetime handling in JavaScript.

[![Build status](https://github.com/BurntSushi/jiff/workflows/ci/badge.svg)](https://github.com/BurntSushi/jiff/actions)
[![Crates.io](https://img.shields.io/crates/v/jiff.svg)](https://crates.io/crates/jiff)
[![Docs.rs](https://img.shields.io/docsrs/jiff)](https://docs.rs/jiff)

Dual-licensed under MIT or the [UNLICENSE](https://unlicense.org/).

Expand Down
32 changes: 30 additions & 2 deletions src/civil/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ impl Date {
///
/// # Example
///
/// This example shows how to created a zoned value with a fixed time zone
/// This example shows how to create a zoned value with a fixed time zone
/// offset:
///
/// ```
Expand Down Expand Up @@ -2490,7 +2490,7 @@ impl<'de> serde::Deserialize<'de> for Date {
}
}

deserializer.deserialize_bytes(DateVisitor)
deserializer.deserialize_str(DateVisitor)
}
}

Expand Down Expand Up @@ -3651,6 +3651,8 @@ fn day_of_year(year: Year, day: i16) -> Result<Date, Error> {

#[cfg(test)]
mod tests {
use std::io::Cursor;

use crate::{civil::date, tz::TimeZone, Timestamp, ToSpan};

use super::*;
Expand Down Expand Up @@ -4006,4 +4008,30 @@ mod tests {
d1 == got
}
}

/// # `serde` deserializer compatibility test
///
/// Serde YAML used to be unable to deserialize `jiff` types,
/// as deserializing from bytes is not supported by the deserializer.
///
/// - <https://github.com/BurntSushi/jiff/issues/138>
/// - <https://github.com/BurntSushi/jiff/discussions/148>
#[test]
fn civil_date_deserialize_yaml() {
let expected = date(2024, 10, 31);

let deserialized: Date = serde_yml::from_str("2024-10-31").unwrap();

assert_eq!(deserialized, expected);

let deserialized: Date =
serde_yml::from_slice("2024-10-31".as_bytes()).unwrap();

assert_eq!(deserialized, expected);

let cursor = Cursor::new(b"2024-10-31");
let deserialized: Date = serde_yml::from_reader(cursor).unwrap();

assert_eq!(deserialized, expected);
}
}
34 changes: 32 additions & 2 deletions src/civil/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ impl DateTime {
///
/// # Example
///
/// This example shows how to created a zoned value with a fixed time zone
/// This example shows how to create a zoned value with a fixed time zone
/// offset:
///
/// ```
Expand Down Expand Up @@ -2604,7 +2604,7 @@ impl<'de> serde::Deserialize<'de> for DateTime {
}
}

deserializer.deserialize_bytes(DateTimeVisitor)
deserializer.deserialize_str(DateTimeVisitor)
}
}

Expand Down Expand Up @@ -4134,6 +4134,8 @@ impl DateTimeWith {

#[cfg(test)]
mod tests {
use std::io::Cursor;

use crate::{
civil::{date, time},
RoundMode, ToSpan, Unit,
Expand Down Expand Up @@ -4277,4 +4279,32 @@ mod tests {
assert_eq!(12, core::mem::size_of::<DateTime>());
}
}

/// # `serde` deserializer compatibility test
///
/// Serde YAML used to be unable to deserialize `jiff` types,
/// as deserializing from bytes is not supported by the deserializer.
///
/// - <https://github.com/BurntSushi/jiff/issues/138>
/// - <https://github.com/BurntSushi/jiff/discussions/148>
#[test]
fn civil_datetime_deserialize_yaml() {
let expected = datetime(2024, 10, 31, 16, 33, 53, 123456789);

let deserialized: DateTime =
serde_yml::from_str("2024-10-31 16:33:53.123456789").unwrap();

assert_eq!(deserialized, expected);

let deserialized: DateTime =
serde_yml::from_slice("2024-10-31 16:33:53.123456789".as_bytes())
.unwrap();

assert_eq!(deserialized, expected);

let cursor = Cursor::new(b"2024-10-31 16:33:53.123456789");
let deserialized: DateTime = serde_yml::from_reader(cursor).unwrap();

assert_eq!(deserialized, expected);
}
}
31 changes: 30 additions & 1 deletion src/civil/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ impl<'de> serde::Deserialize<'de> for Time {
}
}

deserializer.deserialize_bytes(TimeVisitor)
deserializer.deserialize_str(TimeVisitor)
}
}

Expand Down Expand Up @@ -3144,6 +3144,8 @@ impl TimeWith {

#[cfg(test)]
mod tests {
use std::io::Cursor;

use crate::{civil::time, ToSpan};

use super::*;
Expand Down Expand Up @@ -3360,4 +3362,31 @@ mod tests {
let expected = max.rem_euclid(t::NANOS_PER_CIVIL_DAY.bound());
assert_eq!(got, expected);
}

/// # `serde` deserializer compatibility test
///
/// Serde YAML used to be unable to deserialize `jiff` types,
/// as deserializing from bytes is not supported by the deserializer.
///
/// - <https://github.com/BurntSushi/jiff/issues/138>
/// - <https://github.com/BurntSushi/jiff/discussions/148>
#[test]
fn civil_time_deserialize_yaml() {
let expected = time(16, 35, 4, 987654321);

let deserialized: Time =
serde_yml::from_str("16:35:04.987654321").unwrap();

assert_eq!(deserialized, expected);

let deserialized: Time =
serde_yml::from_slice("16:35:04.987654321".as_bytes()).unwrap();

assert_eq!(deserialized, expected);

let cursor = Cursor::new(b"16:35:04.987654321");
let deserialized: Time = serde_yml::from_reader(cursor).unwrap();

assert_eq!(deserialized, expected);
}
}
32 changes: 31 additions & 1 deletion src/signed_duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2063,12 +2063,14 @@ impl<'de> serde::Deserialize<'de> for SignedDuration {
}
}

deserializer.deserialize_bytes(SignedDurationVisitor)
deserializer.deserialize_str(SignedDurationVisitor)
}
}

#[cfg(test)]
mod tests {
use std::io::Cursor;

use super::*;

#[test]
Expand Down Expand Up @@ -2186,4 +2188,32 @@ mod tests {
assert_eq!(None, add((i64::MAX, 1), (0, 999_999_999)));
assert_eq!(None, add((i64::MIN, -1), (0, -999_999_999)));
}

/// # `serde` deserializer compatibility test
///
/// Serde YAML used to be unable to deserialize `jiff` types,
/// as deserializing from bytes is not supported by the deserializer.
///
/// - <https://github.com/BurntSushi/jiff/issues/138>
/// - <https://github.com/BurntSushi/jiff/discussions/148>
#[test]
fn signed_duration_deserialize_yaml() {
let expected = SignedDuration::from_secs(123456789);

let deserialized: SignedDuration =
serde_yml::from_str("PT34293h33m9s").unwrap();

assert_eq!(deserialized, expected);

let deserialized: SignedDuration =
serde_yml::from_slice("PT34293h33m9s".as_bytes()).unwrap();

assert_eq!(deserialized, expected);

let cursor = Cursor::new(b"PT34293h33m9s");
let deserialized: SignedDuration =
serde_yml::from_reader(cursor).unwrap();

assert_eq!(deserialized, expected);
}
}
38 changes: 37 additions & 1 deletion src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3562,7 +3562,7 @@ impl<'de> serde::Deserialize<'de> for Span {
}
}

deserializer.deserialize_bytes(SpanVisitor)
deserializer.deserialize_str(SpanVisitor)
}
}

Expand Down Expand Up @@ -5998,6 +5998,8 @@ fn clamp_relative_span(

#[cfg(test)]
mod tests {
use std::io::Cursor;

use crate::{civil::date, RoundMode};

use super::*;
Expand Down Expand Up @@ -6359,4 +6361,38 @@ mod tests {
quickcheck::TestResult::from_bool(nanos == got.to_invariant_nanoseconds())
}
}

/// # `serde` deserializer compatibility test
///
/// Serde YAML used to be unable to deserialize `jiff` types,
/// as deserializing from bytes is not supported by the deserializer.
///
/// - <https://github.com/BurntSushi/jiff/issues/138>
/// - <https://github.com/BurntSushi/jiff/discussions/148>
#[test]
fn span_deserialize_yaml() {
let expected = Span::new()
.years(1)
.months(2)
.weeks(3)
.days(4)
.hours(5)
.minutes(6)
.seconds(7);

let deserialized: Span =
serde_yml::from_str("P1y2m3w4dT5h6m7s").unwrap();

assert_eq!(deserialized, expected);

let deserialized: Span =
serde_yml::from_slice("P1y2m3w4dT5h6m7s".as_bytes()).unwrap();

assert_eq!(deserialized, expected);

let cursor = Cursor::new(b"P1y2m3w4dT5h6m7s");
let deserialized: Span = serde_yml::from_reader(cursor).unwrap();

assert_eq!(deserialized, expected);
}
}
Loading