Skip to content

Commit

Permalink
Let Time internals always be in UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Nov 24, 2017
1 parent 5ec821b commit 3b6e63e
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 226 deletions.
10 changes: 5 additions & 5 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,8 @@ describe "File" do
filename = "#{__DIR__}/data/temp_write.txt"
File.write(filename, "")

atime = Time.new(2000, 1, 2)
mtime = Time.new(2000, 3, 4)
atime = Time.utc(2000, 1, 2)
mtime = Time.utc(2000, 3, 4)

File.utime(atime, mtime, filename)

Expand All @@ -971,8 +971,8 @@ describe "File" do
end

it "raises if file not found" do
atime = Time.new(2000, 1, 2)
mtime = Time.new(2000, 3, 4)
atime = Time.utc(2000, 1, 2)
mtime = Time.utc(2000, 3, 4)

expect_raises Errno, "Error setting time to file" do
File.utime(atime, mtime, "#{__DIR__}/nonexistent_file")
Expand All @@ -994,7 +994,7 @@ describe "File" do

it "sets file times to given time" do
filename = "#{__DIR__}/data/temp_touch.txt"
time = Time.new(2000, 3, 4)
time = Time.utc(2000, 3, 4)
begin
File.touch(filename, time)

Expand Down
19 changes: 1 addition & 18 deletions spec/std/time/location_spec.cr
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
require "spec"

private def with_env(name, value)
previous = ENV[name]?
begin
ENV[name] = value
yield
ensure
ENV[name] = previous
end
end

private ZONEINFO_ZIP = File.join(__DIR__, "..", "data", "zoneinfo.zip")

private def with_zoneinfo(path = ZONEINFO_ZIP)
with_env("ZONEINFO", path) do
yield
end
end
require "./spec_helper"

class Time::Location
def __cached_range
Expand Down
17 changes: 17 additions & 0 deletions spec/std/time/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def with_env(name, value)
previous = ENV[name]?
begin
ENV[name] = value
yield
ensure
ENV[name] = previous
end
end

ZONEINFO_ZIP = File.join(__DIR__, "..", "data", "zoneinfo.zip")

def with_zoneinfo(path = ZONEINFO_ZIP)
with_env("ZONEINFO", path) do
yield
end
end
Loading

0 comments on commit 3b6e63e

Please sign in to comment.