mmb-seasonal 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,5 +1,11 @@
1
- Create a calendar of date and time events and execute code based on which
2
- events are currently happening.
1
+ Create a calendar of date and time events, attach arbitrary objects to them
2
+ and ask which objects are current at any point in time.
3
+
4
+ Uses the flexible time parsing of Time.parse to be easy to use and the
5
+ timezone and DST handling of tzinfo.
6
+
7
+ Originally conceived for making web sites look and behave differently depending
8
+ on the time of day or year.
3
9
 
4
10
  Example (print holiday greetings):
5
11
 
@@ -48,8 +54,3 @@ sales.push(Seasonal::Event.new('Everything on sale', 'America/New_York',
48
54
  sales.going_on { |e| puts e }
49
55
  </code>
50
56
  </pre>
51
-
52
- Each event has an attached payload which can be any object.
53
-
54
- Uses the flexible time parsing of Time.parse to be easy to use and the
55
- timezone and DST handling of tzinfo.
data/lib/seasonal.rb CHANGED
@@ -30,10 +30,22 @@ module Seasonal
30
30
  end
31
31
  end
32
32
 
33
+ def has_year(s)
34
+ p = Time.parse(s)
35
+ p.eql?(Time.parse(s + ' ' + (p.year + 1).to_s))
36
+ end
37
+
33
38
  def end_utc
34
39
  unless ennd.nil?
35
40
  tz = TZInfo::Timezone.get(zone)
36
- tz.local_to_utc(Time.parse(ennd))
41
+ result = tz.local_to_utc(Time.parse(ennd))
42
+ # if no year is given for end and it falls before start, assume they
43
+ # meant next year
44
+ if !start.nil? and (result < start_utc) and !has_year(ennd)
45
+ result = Time.utc(result.year + 1, result.month, result.day,
46
+ result.hour, result.min, result.sec, result.usec)
47
+ end
48
+ result
37
49
  end
38
50
  end
39
51
 
data/seasonal.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "seasonal"
3
- s.version = "0.0.4"
4
- s.date = "2008-11-10"
3
+ s.version = "0.0.5"
4
+ s.date = "2009-01-13"
5
5
  s.summary = "create logic based on defined date and time events"
6
6
  s.email = "matthewm@boedicker.org"
7
7
  s.homepage = "http://github.com/mmb/seasonal"
@@ -48,6 +48,21 @@ class SeasonalTest < Test::Unit::TestCase
48
48
  assert_equal(false, e.going_on?(ennd + 1))
49
49
  end
50
50
 
51
+ def test_event_start_end_crosses_year_boundary
52
+ ss = 'dec 31'
53
+ es = 'jan 1'
54
+ start = Time.parse(ss).utc
55
+ ennd = Time.parse(es).utc
56
+ ennd = Time.utc(ennd.year + 1, ennd.month, ennd.day, ennd.hour, ennd.min,
57
+ ennd.sec, ennd.usec)
58
+
59
+ e = Seasonal::Event.new(nil, 'America/New_York', :start => ss, :end => es)
60
+ assert_equal(false, e.going_on?(start - 1))
61
+ assert(e.going_on?(start))
62
+ assert(e.going_on?(ennd))
63
+ assert_equal(false, e.going_on?(ennd + 1))
64
+ end
65
+
51
66
  def test_calendar_going_on
52
67
  calendar = Seasonal::Calendar.new
53
68
  calendar.push(Seasonal::Event.new(nil, 'America/New_York',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmb-seasonal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew M. Boedicker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-10 00:00:00 -08:00
12
+ date: 2009-01-13 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency