Skip to content

Commit

Permalink
Rename Time#add_span to Time#shift
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Aug 22, 2018
1 parent cb72387 commit c7817da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions spec/std/time/time_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe Time do
(time == time.clone).should be_true
end

describe "#add_span" do
describe "#shift" do
it "adds hours, minutes, seconds" do
t1 = Time.utc(2002, 2, 25, 15, 25, 13)
t2 = t1 + Time::Span.new 3, 54, 1
Expand Down Expand Up @@ -142,10 +142,10 @@ describe Time do
location = Time::Location.fixed(offset)

time = Time.new(1, 1, 1, location: location)
time.add_span(0, 1).should eq Time.new(1, 1, 1, nanosecond: 1, location: location)
time.add_span(0, 0).should eq time
time.shift(0, 1).should eq Time.new(1, 1, 1, nanosecond: 1, location: location)
time.shift(0, 0).should eq time
expect_raises(ArgumentError) do
time.add_span(0, -1)
time.shift(0, -1)
end
end
end
Expand All @@ -155,17 +155,17 @@ describe Time do
location = Time::Location.fixed(offset)

time = Time.new(9999, 12, 31, 23, 59, 59, nanosecond: 999_999_999, location: location)
time.add_span(0, -1).should eq Time.new(9999, 12, 31, 23, 59, 59, nanosecond: 999_999_998, location: location)
time.add_span(0, 0).should eq time
time.shift(0, -1).should eq Time.new(9999, 12, 31, 23, 59, 59, nanosecond: 999_999_998, location: location)
time.shift(0, 0).should eq time
expect_raises(ArgumentError) do
time.add_span(0, 1)
time.shift(0, 1)
end
end
end

it "adds zero span" do
time = Time.now
time.add_span(0, 0).should eq time
time.shift(0, 0).should eq time
end

describe "adds days" do
Expand Down
10 changes: 5 additions & 5 deletions src/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,16 @@ struct Time

# Returns a copy of this `Time` with *span* added.
#
# See `#add_span` for details.
# See `#shift` for details.
def +(span : Time::Span) : Time
add_span span.to_i, span.nanoseconds
shift span.to_i, span.nanoseconds
end

# Returns a copy of this `Time` with *span* subtracted.
#
# See `#add_span` for details.
# See `#shift` for details.
def -(span : Time::Span) : Time
add_span -span.to_i, -span.nanoseconds
shift -span.to_i, -span.nanoseconds
end

# Returns a copy of this `Time` with *span* added.
Expand Down Expand Up @@ -594,7 +594,7 @@ struct Time
# There is no explicit limit on the input values but the addition must result
# in a valid time between `0001-01-01 00:00:00.0` and
# `9999-12-31 23:59:59.999_999_999`. Otherwise `ArgumentError` is raised.
def add_span(seconds : Int, nanoseconds : Int) : Time
def shift(seconds : Int, nanoseconds : Int) : Time
if seconds == 0 && nanoseconds == 0
return self
end
Expand Down
2 changes: 1 addition & 1 deletion src/time/format/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Time::Format
end

time = Time.new @year, @month, @day, @hour, @minute, @second, nanosecond: @nanosecond, location: location
time = time.add_span 0, @nanosecond_offset
time = time.shift 0, @nanosecond_offset

time
end
Expand Down

0 comments on commit c7817da

Please sign in to comment.