From 5eeb3e556ad6a08fc793362c07a707c2382e825d Mon Sep 17 00:00:00 2001 From: Christopher De Vries Date: Tue, 4 Feb 2025 16:15:04 -0500 Subject: [PATCH 1/3] initial fix for problems I saw, two test failures need to examine and add new tests --- src/gleam/time/timestamp.gleam | 2 +- src/gleam_time_ffi.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gleam/time/timestamp.gleam b/src/gleam/time/timestamp.gleam index 12ac4ac..271a6fa 100644 --- a/src/gleam/time/timestamp.gleam +++ b/src/gleam/time/timestamp.gleam @@ -300,7 +300,7 @@ fn to_calendar_from_offset( timestamp: Timestamp, offset: Int, ) -> #(Int, Int, Int, Int, Int, Int) { - let total = timestamp.seconds - { offset * 60 } + let total = timestamp.seconds + { offset * 60 } let seconds = modulo(total, 60) let total_minutes = floored_div(total, 60.0) let minutes = modulo(total, 60 * 60) / 60 diff --git a/src/gleam_time_ffi.mjs b/src/gleam_time_ffi.mjs index 1f09537..27d09aa 100644 --- a/src/gleam_time_ffi.mjs +++ b/src/gleam_time_ffi.mjs @@ -7,5 +7,5 @@ export function system_time() { } export function local_time_offset_seconds() { - return new Date().getTimezoneOffset() * 60; + return new Date().getTimezoneOffset() * -60; } From 791a16dc9f2372b65262b3f76b59e66a8170707a Mon Sep 17 00:00:00 2001 From: Christopher De Vries Date: Tue, 4 Feb 2025 16:35:42 -0500 Subject: [PATCH 2/3] Fixed the tests, but need to add a couple more tests: --- test/gleam/time/timestamp_test.gleam | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/gleam/time/timestamp_test.gleam b/test/gleam/time/timestamp_test.gleam index 95daa6e..09561df 100644 --- a/test/gleam/time/timestamp_test.gleam +++ b/test/gleam/time/timestamp_test.gleam @@ -203,15 +203,15 @@ pub fn to_rfc3339_6_test() { } pub fn to_rfc3339_7_test() { - timestamp.from_unix_seconds(60 * 60 + 60 * 5) + timestamp.from_unix_seconds(-60 * 60 - 60 * 5) |> timestamp.to_rfc3339(duration.seconds(65 * 60)) |> should.equal("1970-01-01T00:00:00+01:05") } pub fn to_rfc3339_8_test() { timestamp.from_unix_seconds(0) - |> timestamp.to_rfc3339(duration.seconds(-120 * 60)) - |> should.equal("1970-01-01T02:00:00-02:00") + |> timestamp.to_rfc3339(duration.seconds(120 * 60)) + |> should.equal("1970-01-01T02:00:00+02:00") } pub fn to_rfc3339_9_test() { From 1600ab15aedacb1e757709917e082d03284f9bad Mon Sep 17 00:00:00 2001 From: Christopher De Vries Date: Tue, 4 Feb 2025 16:50:55 -0500 Subject: [PATCH 3/3] Added two tests to switch from UTC to EST (-05:00) and EST to UTC --- test/gleam/time/timestamp_test.gleam | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/gleam/time/timestamp_test.gleam b/test/gleam/time/timestamp_test.gleam index 09561df..e2f3204 100644 --- a/test/gleam/time/timestamp_test.gleam +++ b/test/gleam/time/timestamp_test.gleam @@ -356,6 +356,25 @@ pub fn rfc3339_string_timestamp_rfc3339_string_roundtrip_property_test() { original_timestamp == roundtrip_timestamp } +// Eastern US Timezone round trip tests +pub fn rfc3339_string_timestamp_rfc3339_string_roundtrip_to_est_test() { + let assert Ok(date_time) = + timestamp.parse_rfc3339("2025-02-04T13:00:00+00:00") + + date_time + |> timestamp.to_rfc3339(duration.seconds(-18_000)) + |> should.equal("2025-02-04T08:00:00-05:00") +} + +pub fn rfc3339_string_timestamp_rfc3339_string_roundtrip_from_est_test() { + let assert Ok(date_time) = + timestamp.parse_rfc3339("2025-02-04T13:00:00-05:00") + + date_time + |> timestamp.to_rfc3339(calendar.utc_offset) + |> should.equal("2025-02-04T18:00:00Z") +} + // Check against OCaml Ptime reference implementation. // // These test cases include leap seconds.