Skip to content

Commit

Permalink
Merge pull request #78 from kotp/master
Browse files Browse the repository at this point in the history
Looking for time not date objects
  • Loading branch information
kytrinyx committed Jan 26, 2015
2 parents df18e01 + 6cd1edf commit cda6a2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions gigasecond/example.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Gigasecond
SECONDS = 10**9

def self.from(date)
(date.to_time + SECONDS).to_date
def self.from(time)
(time.to_time + SECONDS).to_time
end
end
21 changes: 10 additions & 11 deletions gigasecond/gigasecond_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@
require 'time'

require_relative 'gigasecond'

class GigasecondTest < MiniTest::Unit::TestCase
class GigasecondTest < Minitest::Unit::TestCase
def test_1
gs = Gigasecond.from(Date.new(2011, 4, 25))
assert_equal Date.new(2043, 1, 1), gs
gs = Gigasecond.from(Time.new(2011, 4, 25))
assert_equal Time.new(2043, 1, 1, 0 , 46, 40), gs
end

def test_2
skip
gs = Gigasecond.from(Date.new(1977, 6, 13))
assert_equal Date.new(2009, 2, 19), gs
gs = Gigasecond.from(Time.new(1977, 6, 13))
assert_equal Time.new(2009, 2, 19, 0, 46, 40), gs
end

def test_3
skip
gs = Gigasecond.from(Date.new(1959, 7, 19))
assert_equal Date.new(1991, 3, 27), gs
gs = Gigasecond.from(Time.new(1959, 7, 19))
assert_equal Time.new(1991, 3, 27, 0, 46, 40), gs
end

def test_time_with_seconds
skip
gs = Gigasecond.from(Time.new(1959, 7, 19, 23, 59, 59))
assert_equal Date.new(1991, 3, 28), gs
assert_equal Time.new(1991, 3, 28, 0, 46, 39), gs
end

# modify the test to test your 1 Gs anniversary
def test_yourself
skip
your_birthday = Date.new(year, month, day)
your_birthday = Time.new(year, month, day)
gs = Gigasecond.from(your_birthday)
assert_equal Date.new(2009, 1, 31), gs
assert_equal Time.new(2009, 1, 31), gs
end
end

0 comments on commit cda6a2d

Please sign in to comment.