From 22dfa4c4487e867942af04e1cdc326ed3d960696 Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Wed, 2 Sep 2026 16:51:02 -0400 Subject: [PATCH] fix: fixed an offset issue with date formatting. --- feed.odin | 16 +++++++++++++--- feed_test.odin | 23 ++++++++++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/feed.odin b/feed.odin index 7e2acaa..98f6764 100644 --- a/feed.odin +++ b/feed.odin @@ -124,15 +124,25 @@ format_rfc822 :: proc(iso: string, allocator := context.temp_allocator) -> strin buf: [8]byte t := time.to_string_hms(date, buf[:]) + // RFC-822 zone: sign followed by two-digit hours and minutes (e.g. +0000, + // +0530, -0800). offset is in minutes. + sign := '+' + off := offset + if off < 0 { + sign = '-' + off = -off + } + return fmt.aprintf( - "%s, %02d %s %d %s %3d%2d", + "%s, %02d %s %d %s %c%02d%02d", weekday[:3], time.day(date), month[:3], time.year(date), t, - offset / 60, - offset % 60, + sign, + off / 60, + off % 60, allocator = allocator, ) } diff --git a/feed_test.odin b/feed_test.odin index 54abbfc..8be163f 100644 --- a/feed_test.odin +++ b/feed_test.odin @@ -50,11 +50,24 @@ test_format_rfc822_short_passthrough :: proc(t: ^testing.T) { @(test) test_format_rfc822_full_date :: proc(t: ^testing.T) { - got := format_rfc822("2024-01-15T10:30:00Z") - // Result is temp-allocated (reset by the test runner), so no delete. - // 2024-01-15 is a Monday. Assert the stable leading portion; the trailing - // offset rendering is intentionally left unpinned here. - testing.expect(t, strings.has_prefix(got, "Mon, 15 Jan 2024 10:30:00"), got) + // Results are temp-allocated (reset by the test runner), so no delete. + // 2024-01-15 is a Monday; wall-clock time is preserved and the zone is + // rendered as an RFC-822 ±HHMM offset. + testing.expect_value( + t, + format_rfc822("2024-01-15T10:30:00Z"), + "Mon, 15 Jan 2024 10:30:00 +0000", + ) + testing.expect_value( + t, + format_rfc822("2024-01-15T10:30:00+05:30"), + "Mon, 15 Jan 2024 10:30:00 +0530", + ) + testing.expect_value( + t, + format_rfc822("2024-01-15T10:30:00-08:00"), + "Mon, 15 Jan 2024 10:30:00 -0800", + ) } // ---------------------------------------------------------------------------