Skip to content

Commit 7476e53

Browse files
Treat GMT as a legacy alias of UTC (#16292)
Support GMT as a valid time zone identifier, even without a zoneinfo database. Historically, it has been used as a generic name in a similar manner as UTC. As the use case in #16277 shows, GMT is relevant for data exchange.
1 parent 9a38916 commit 7476e53

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

spec/std/time/location_spec.cr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ class Time::Location
103103
Location.load("").should eq Location::UTC
104104
Location.load("Etc/UTC").should eq Location::UTC
105105
end
106+
107+
with_zoneinfo("nonexistent_zipfile.zip") do
108+
Location.load("UTC").should eq Location::UTC
109+
Location.load("").should eq Location::UTC
110+
Location.load("Etc/UTC").should eq Location::UTC
111+
end
112+
end
113+
114+
it "treats GMT as special case" do
115+
with_zoneinfo do
116+
Location.load("GMT").should eq Location::UTC
117+
Location.load("Etc/GMT").should eq Location::UTC
118+
end
119+
120+
with_zoneinfo("nonexistent_zipfile.zip") do
121+
Location.load("GMT").should eq Location::UTC
122+
Location.load("Etc/GMT").should eq Location::UTC
123+
end
106124
end
107125

108126
describe "validating name" do

src/time/location.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class Time::Location
320320
# :nodoc:
321321
def self.load?(name : String, & : String? ->) : Location?
322322
case name
323-
when "", "UTC", "Etc/UTC"
323+
when "", "UTC", "Etc/UTC", "GMT", "Etc/GMT"
324324
# `UTC` is a special identifier, empty string represents a fallback mechanism.
325325
# `Etc/UTC` is technically a tzdb identifier which could potentially point to anything.
326326
# But we map it to `Location::UTC` directly for convenience which allows it to work

0 commit comments

Comments
 (0)