Skip to content

Commit

Permalink
Remove representation of floating time from Time
Browse files Browse the repository at this point in the history
Floating time should not be represented as an instance of `Time` to avoid undefined operations through type safety (see crystal-lang#5332).
This commit removes all implementation details regarding floating time, including the special location `Location::UNSPECIFIED`.

Breaking changes:
* Calls to `Time.new` and `Time.now` are now in the local time zone by
default.
* `Time.parse`, `Time::Format.new` and `Time::Format.parse` don't specify a default location.
  If none is included in the time format and no default argument is provided, the parse method wil raise an exception because there is no way to know how such a value should be represented as an instance of `Time`.
  Applications expecting time values without time zone should provide default location to apply in such a case.
  • Loading branch information
straight-shoota committed Dec 23, 2017
1 parent 49fb03e commit a9946ec
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 243 deletions.
22 changes: 3 additions & 19 deletions spec/std/time/location_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Time::Location
summer_time.offset.should eq 7200
summer_time.dst?.should be_true

location.unspecified?.should be_false
location.utc?.should be_false
location.fixed?.should be_false

Expand Down Expand Up @@ -81,12 +80,14 @@ class Time::Location
end

context "with ZONEINFO" do
it "loads from custom source" do
it "loads from custom directory" do
with_zoneinfo(File.join(__DIR__, "..", "data", "zoneinfo")) do
location = Location.load("Foo/Bar")
location.name.should eq "Foo/Bar"
end
end

it "loads from custom zipfile" do
with_zoneinfo(ZONEINFO_ZIP) do
location = Location.load("Asia/Jerusalem")
location.not_nil!.name.should eq "Asia/Jerusalem"
Expand Down Expand Up @@ -122,7 +123,6 @@ class Time::Location
location = Location::UTC
location.name.should eq "UTC"

location.unspecified?.should be_false
location.utc?.should be_true
location.fixed?.should be_true

Expand All @@ -137,21 +137,6 @@ class Time::Location
zone.dst?.should be_false
end

it "UNSPECIFIED" do
location = Location::UNSPECIFIED
location.name.should eq "UNSPECIFIED"

location.unspecified?.should be_true
location.utc?.should be_false
location.fixed?.should be_false
location.local?.should be_false

zone = location.lookup(Time.now)
zone.name.should eq "UNSPECIFIED"
zone.offset.should eq 0
zone.dst?.should be_false
end

it ".local" do
with_env("TZ", nil) do
Location.local.name.should eq "Local"
Expand All @@ -171,7 +156,6 @@ class Time::Location
location.zones.should eq [Zone.new("Fixed", 1800, false)]
location.transitions.size.should eq 0

location.unspecified?.should be_false
location.utc?.should be_false
location.fixed?.should be_true
location.local?.should be_false
Expand Down
Loading

0 comments on commit a9946ec

Please sign in to comment.