Skip to content

Commit

Permalink
Merge pull request #7 from herwinw/datetime_and_epoch
Browse files Browse the repository at this point in the history
Remove hack to prevent years < 1970 in DateTime
  • Loading branch information
hsbt authored Dec 21, 2016
2 parents 30e4230 + 7a7a3af commit 7d61f34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 1 addition & 7 deletions lib/xmlrpc/datetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,10 @@ def initialize(year, month, day, hour, min, sec)
end

# Return a Time object of the date/time which represents +self+.
# If the <code>@year</code> is below 1970, this method returns +nil+,
# because Time cannot handle years below 1970.
#
# The timezone used is GMT.
def to_time
if @year >= 1970
Time.gm(*to_a)
else
nil
end
Time.gm(*to_a)
end

# Return a Date object of the date which represents +self+.
Expand Down
14 changes: 11 additions & 3 deletions test/test_datetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,18 @@ def test_to_time1
end

def test_to_time2
dt = createDateTime()
dt.year = 1969
y, m, d, h, mi, s = 1969, 3, 24, 12, 0, 5
dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
time = dt.to_time

assert_nil(dt.to_time)
assert_not_nil(time)

assert_equal(y, time.year)
assert_equal(m, time.month)
assert_equal(d, time.day)
assert_equal(h, time.hour)
assert_equal(mi, time.min)
assert_equal(s, time.sec)
end

def test_to_date1
Expand Down

0 comments on commit 7d61f34

Please sign in to comment.