Skip to content

Commit

Permalink
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spec/std/time/time_spec.cr
Original file line number Diff line number Diff line change
@@ -619,6 +619,13 @@ describe Time do
end
end

it "does diff of utc vs local time" do
local = Time.now
utc = local.to_utc
(utc - local).should eq(0.seconds)
(local - utc).should eq(0.seconds)
end

typeof(Time.now.year)
typeof(1.minute.from_now.year)
typeof(1.minute.ago.year)
8 changes: 7 additions & 1 deletion src/time.cr
Original file line number Diff line number Diff line change
@@ -213,7 +213,13 @@ struct Time
end

def -(other : Time)
Span.new(ticks - other.ticks)
if local? && other.utc?
self - other.to_local
elsif utc? && other.local?
self - other.to_utc
else
Span.new(ticks - other.ticks)
end
end

def self.now : self

0 comments on commit 803a20f

Please sign in to comment.