Make utc? case-insensitive#5
Conversation
There was a problem hiding this comment.
Build & Tests
CI passes (macOS test, lint, format check, docs gen all green). No local Carp toolchain to run on this machine.
Findings
The change is small and correct. The TODO asked whether utc? should be case-insensitive; this PR answers yes and implements it cleanly.
What works well:
- Decomposing the
Timezonestruct and lowercasing only the name while still checking delta and dst exactly is the right approach. - The fallback path when
tzisNothingstill works:(Timezone.zero)has name"", which lowercased is still"", so the second branch correctly returns false, and(Maybe.nothing? (tz dt))in the first branch handles it. - Tests cover uppercase, lowercase, and mixed-case names.
String.ascii-to-loweris appropriate here since timezone abbreviations are ASCII.
One observation (non-blocking):
Datetime.=at line 873 uses(= &(Maybe.from @(tz a) @&Timezone.utc) &(Maybe.from @(tz b) @&Timezone.utc)), which comparesTimezonestructs with derived=(i.e. case-sensitive on name). This means two datetimes that are identical except one has tz name"UTC"and the other"utc"would compare as not-equal, even thoughutc?would return true for both. That is arguably a separate concern and outside the scope of this PR, but worth noting for consistency down the road.
No CHANGELOG exists in this repo, so nothing to update there.
Verdict: merge
Clean, focused change that resolves the TODO correctly. CI is green. Ship it.
hellerve
left a comment
There was a problem hiding this comment.
Before we merge: what is the reason to answer the question the comment asked with „yes“?
|
Good question. The rationale: Timezone abbreviations commonly arrive with inconsistent casing from external sources — HTTP Date headers use "GMT", IANA/Olson databases use "UTC", user input might be "utc" or "Utc", and parsers from other ecosystems often normalize differently. Since This matches the convention in timezone libraries across languages (Python's |
Resolves the TODO at the
utc?function: timezone name comparison is now case-insensitive usingString.ascii-to-lower, so"utc","Utc","UTC"etc. all match. The delta and dst? fields are still checked exactly.Adds tests for lowercase and mixed-case timezone names.
Note: the existing test suite has a pre-existing build failure (C codegen issue with the
TMstruct'sconst char *tm_zonefield). This PR does not affect that — the new logic was verified with a standalone compilation test.Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.