Skip to content

Commit

Permalink
Add timestamp round-trip property test
Browse files Browse the repository at this point in the history
  • Loading branch information
mooreryan committed Jan 21, 2025
1 parent e1cf6e3 commit 0e41d8d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/gleam/time/timestamp_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,21 @@ pub fn timestamp_rfc3339_string_timestamp_roundtrip_property_test() {
timestamp.compare(timestamp, parsed_timestamp) == order.Eq
}

pub fn rfc3339_string_timestamp_rfc3339_string_roundtrip_property_test() {
use date_time <- qcheck.given(rfc3339_generator.date_time_generator(
with_leap_second: True,
second_fraction_spec: rfc3339_generator.Default,
avoid_erlang_errors: False,
))

let assert Ok(original_timestamp) = timestamp.parse_rfc3339(date_time)

let assert Ok(roundtrip_timestamp) =
original_timestamp |> timestamp.to_rfc3339(0) |> timestamp.parse_rfc3339

timestamp.compare(original_timestamp, roundtrip_timestamp) == order.Eq
}

// Check against OCaml Ptime reference implementation.
//
// These test cases include leap seconds.
Expand Down

0 comments on commit 0e41d8d

Please sign in to comment.