metra_schedule 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -3,7 +3,20 @@ module MetraSchedule
3
3
  module TimeExtension
4
4
  def to_today
5
5
  if self.hour >= 0 and self.hour <= 2 # Midnight to 2AM counts as the same day
6
- Time.local(Time.now.year, Time.now.month, Time.now.day+1, self.hour, self.min, self.sec)
6
+ if Time.now.month >= 12 and Time.now.day >= 31 #Dec 31st, can't overflow the months to 13
7
+ year = Time.now.year + 1
8
+ month = 1
9
+ day = 1
10
+ elsif Time.now.day >= 31 #Any 31st of the month, can't overflow days to 32
11
+ year = Time.now.year
12
+ month = Time.now.month + 1
13
+ day = 1
14
+ else #Otherwise just increment our day
15
+ year = Time.now.year
16
+ day = Time.now.day + 1
17
+ month = Time.now.month
18
+ end
19
+ Time.local(year, month, day, self.hour, self.min, self.sec)
7
20
  else
8
21
  Time.local(Time.now.year, Time.now.month, Time.now.day, self.hour, self.min, self.sec)
9
22
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{metra_schedule}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Blake Smith"]
12
- s.date = %q{2010-02-03}
12
+ s.date = %q{2010-03-31}
13
13
  s.description = %q{metra_schedule provides a ruby object interface to the Chicago metra train schedule}
14
14
  s.email = %q{blakesmith0@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -10,9 +10,42 @@ class TestTimeExtension < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def test_to_today_midnight_inclusive
13
+ Timecop.freeze(2009, 8, 28, 9, 30, 45)
13
14
  sample = Time.local(2009, 5, 5, 0, 30, 45)
14
15
  today = Time.now
15
- expected = Time.local(today.year, today.month, today.day+1, sample.hour, sample.min, sample.sec)
16
+ expected = Time.local(2009, 8, 29, 0, 30, 45)
17
+ assert_equal(expected, sample.to_today)
18
+ end
19
+
20
+ def test_to_today_on_31st
21
+ Timecop.freeze(2010, 3, 31, 9, 30, 45)
22
+ sample = Time.local(2009, 5, 5, 0, 30, 45)
23
+ today = Time.now
24
+ expected = Time.local(2010, 4, 1, 0, 30, 45)
25
+ assert_equal(expected, sample.to_today)
26
+ end
27
+
28
+ def test_to_today_on_31st_in_dec_after_midnight
29
+ Timecop.freeze(2010, 12, 31, 9, 30, 45)
30
+ sample = Time.local(2009, 5, 5, 0, 30, 45)
31
+ today = Time.now
32
+ expected = Time.local(2011, 1, 1, 0, 30, 45)
33
+ assert_equal(expected, sample.to_today)
34
+ end
35
+
36
+ def test_to_today_in_dec_after_midnight
37
+ Timecop.freeze(2010, 12, 21, 9, 30, 45)
38
+ sample = Time.local(2009, 5, 5, 0, 30, 45)
39
+ today = Time.now
40
+ expected = Time.local(2010, 12, 22, 0, 30, 45)
41
+ assert_equal(expected, sample.to_today)
42
+ end
43
+
44
+ def test_to_today_in_dec_before_midnight
45
+ Timecop.freeze(2010, 12, 21, 9, 30, 45)
46
+ sample = Time.local(2009, 5, 5, 11, 30, 45)
47
+ today = Time.now
48
+ expected = Time.local(2010, 12, 21, 11, 30, 45)
16
49
  assert_equal(expected, sample.to_today)
17
50
  end
18
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metra_schedule
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Smith
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-03 00:00:00 -06:00
12
+ date: 2010-03-31 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency