From 05b44f8609894115ac926604d988370d67c357fe Mon Sep 17 00:00:00 2001 From: femto Date: Mon, 8 Jan 2024 16:22:22 +0800 Subject: [PATCH 1/8] supports "Etc/UTC" --- src/time/location.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time/location.cr b/src/time/location.cr index d84c1ab14218..6eb8a5a0e37b 100644 --- a/src/time/location.cr +++ b/src/time/location.cr @@ -277,7 +277,7 @@ class Time::Location # `Location`, unless the time zone database has been updated in between. def self.load(name : String) : Location case name - when "", "UTC" + when "", "UTC","Etc/UTC" UTC when "Local" local From 86a02e013588a0f1b1d9cb6a67ebd24371b3290a Mon Sep 17 00:00:00 2001 From: femto Date: Mon, 8 Jan 2024 16:23:53 +0800 Subject: [PATCH 2/8] supports "Etc/UTC" --- src/time/location.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time/location.cr b/src/time/location.cr index 6eb8a5a0e37b..aea323dba404 100644 --- a/src/time/location.cr +++ b/src/time/location.cr @@ -277,7 +277,7 @@ class Time::Location # `Location`, unless the time zone database has been updated in between. def self.load(name : String) : Location case name - when "", "UTC","Etc/UTC" + when "", "UTC", "Etc/UTC" UTC when "Local" local From 73a4c908c71eaf7fd93dd660cc420ed0013cb980 Mon Sep 17 00:00:00 2001 From: femto Date: Mon, 8 Jan 2024 19:57:38 +0800 Subject: [PATCH 3/8] adds "Etc/UTC" for load_local --- src/time/location.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time/location.cr b/src/time/location.cr index aea323dba404..4bcdea71816b 100644 --- a/src/time/location.cr +++ b/src/time/location.cr @@ -348,7 +348,7 @@ class Time::Location # `Location::UTC` is returned. def self.load_local : Location case tz = ENV["TZ"]? - when "", "UTC" + when "", "UTC", "Etc/UTC" return UTC when Nil if localtime = Crystal::System::Time.load_localtime From f052b90eaac99bbca4de01cd8ed456ebc5de5f10 Mon Sep 17 00:00:00 2001 From: femto Date: Mon, 8 Jan 2024 20:05:16 +0800 Subject: [PATCH 4/8] adds docs / fix spec --- spec/std/time/location_spec.cr | 2 +- src/time/location.cr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/std/time/location_spec.cr b/spec/std/time/location_spec.cr index bcf7595cffd8..04702b70d129 100644 --- a/spec/std/time/location_spec.cr +++ b/spec/std/time/location_spec.cr @@ -69,7 +69,7 @@ class Time::Location Location.load("").should eq Location::UTC # Etc/UTC could be pointing to anything - Location.load("Etc/UTC").should_not eq Location::UTC + Location.load("Etc/UTC").should eq Location::UTC end end diff --git a/src/time/location.cr b/src/time/location.cr index 4bcdea71816b..5ee35c121a90 100644 --- a/src/time/location.cr +++ b/src/time/location.cr @@ -236,7 +236,7 @@ class Time::Location # # *name* is understood to be a location name in the IANA Time # Zone database, such as `"America/New_York"`. As special cases, - # `"UTC"` and empty string (`""`) return `Location::UTC`, and + # `"UTC"` `"Etc/UTC"` and empty string (`""`) return `Location::UTC`, and # `"Local"` returns `Location.local`. # # The implementation uses a list of system-specific paths to look for a time @@ -339,7 +339,7 @@ class Time::Location # The environment variable `ENV["TZ"]` is consulted for finding the time zone # to use. # - # * `"UTC"` and empty string (`""`) return `Location::UTC` + # * `"UTC"`, `"Etc/UTC"` and empty string (`""`) return `Location::UTC` # * Any other value (such as `"Europe/Berlin"`) is tried to be resolved using # `Location.load`. # * If `ENV["TZ"]` is not set, the system's local time zone data will be used From 47966101f6d301489b74d57ca30189c2744eb2f6 Mon Sep 17 00:00:00 2001 From: femto Date: Tue, 9 Jan 2024 17:39:49 +0800 Subject: [PATCH 5/8] Update spec/std/time/location_spec.cr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Johannes Müller --- spec/std/time/location_spec.cr | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/std/time/location_spec.cr b/spec/std/time/location_spec.cr index 04702b70d129..78e27a230fde 100644 --- a/spec/std/time/location_spec.cr +++ b/spec/std/time/location_spec.cr @@ -67,8 +67,6 @@ class Time::Location with_zoneinfo do Location.load("UTC").should eq Location::UTC Location.load("").should eq Location::UTC - - # Etc/UTC could be pointing to anything Location.load("Etc/UTC").should eq Location::UTC end end From 9b6a1df448f01659436cfd1d58615f0cea924a0c Mon Sep 17 00:00:00 2001 From: femto Date: Tue, 9 Jan 2024 17:40:11 +0800 Subject: [PATCH 6/8] Update src/time/location.cr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Johannes Müller --- src/time/location.cr | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/time/location.cr b/src/time/location.cr index 5ee35c121a90..27ae24c4235d 100644 --- a/src/time/location.cr +++ b/src/time/location.cr @@ -278,7 +278,11 @@ class Time::Location def self.load(name : String) : Location case name when "", "UTC", "Etc/UTC" - UTC + # `UTC` is a special identifier, empty string represents a fallback mechanism. + # `Etc/UTC` is technically a tzdb identifier which could potentially point to anything. + # But we map it to `Location::UTC` directly for convenience which allows it to work + # without a copy of the database. + UTC when "Local" local when .includes?(".."), .starts_with?('/'), .starts_with?('\\') From b1cecd1aac74b03296e923a245fedfe013226f45 Mon Sep 17 00:00:00 2001 From: femto Date: Tue, 9 Jan 2024 17:40:29 +0800 Subject: [PATCH 7/8] Update src/time/location.cr Co-authored-by: George Dietrich --- src/time/location.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time/location.cr b/src/time/location.cr index 27ae24c4235d..96663d109746 100644 --- a/src/time/location.cr +++ b/src/time/location.cr @@ -236,7 +236,7 @@ class Time::Location # # *name* is understood to be a location name in the IANA Time # Zone database, such as `"America/New_York"`. As special cases, - # `"UTC"` `"Etc/UTC"` and empty string (`""`) return `Location::UTC`, and + # `"UTC"`, `"Etc/UTC"` and empty string (`""`) return `Location::UTC`, and # `"Local"` returns `Location.local`. # # The implementation uses a list of system-specific paths to look for a time From 06cccd6f15cf3f8474a2c33438f7cc7bb1cf30dc Mon Sep 17 00:00:00 2001 From: femto Date: Tue, 9 Jan 2024 20:42:15 +0800 Subject: [PATCH 8/8] idention --- src/time/location.cr | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/time/location.cr b/src/time/location.cr index 96663d109746..7e0e8f160cb9 100644 --- a/src/time/location.cr +++ b/src/time/location.cr @@ -278,11 +278,11 @@ class Time::Location def self.load(name : String) : Location case name when "", "UTC", "Etc/UTC" - # `UTC` is a special identifier, empty string represents a fallback mechanism. - # `Etc/UTC` is technically a tzdb identifier which could potentially point to anything. - # But we map it to `Location::UTC` directly for convenience which allows it to work - # without a copy of the database. - UTC + # `UTC` is a special identifier, empty string represents a fallback mechanism. + # `Etc/UTC` is technically a tzdb identifier which could potentially point to anything. + # But we map it to `Location::UTC` directly for convenience which allows it to work + # without a copy of the database. + UTC when "Local" local when .includes?(".."), .starts_with?('/'), .starts_with?('\\')