timetress 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,6 +34,12 @@ Timetress.next_christmas
34
34
  => #<Date: 2012-12-25>
35
35
  ```
36
36
 
37
+ ```
38
+ # On Christmas Day, 2012
39
+ Timetress.previous_christmas
40
+ => #<Date: 2011-12-25>
41
+ ```
42
+
37
43
  ### Public Holidays (Norway only)
38
44
 
39
45
  > A public holiday, national holiday or legal holiday is a holiday generally established by law and is usually a non-working day during the year.
@@ -102,11 +102,26 @@ module Timetress
102
102
  the_day
103
103
  end
104
104
 
105
+ def previous_holiday(holiday, given_date)
106
+ given_date ||= Date.today
107
+
108
+ unless given_date.respond_to?(:asctime)
109
+ raise ArgumentError.new("#{given_date.inspect} must be a date or time object")
110
+ end
111
+
112
+ the_day = self.send(holiday.to_sym, given_date.year)
113
+
114
+ if the_day >= given_date
115
+ the_day = self.send(holiday.to_sym, given_date.year - 1)
116
+ end
117
+ the_day
118
+ end
119
+
105
120
  def method_missing(method, *args, &block)
106
121
  if method.to_s =~ /^next_(.*)$/
107
122
  next_holiday($1, args.first)
108
- elsif method.to_s =~ /(.*)_for_season/
109
- holiday_for_season($1, *args)
123
+ elsif method.to_s =~ /^previous_(.*)$/
124
+ previous_holiday($1, args.first)
110
125
  else
111
126
  super
112
127
  end
@@ -1,3 +1,3 @@
1
1
  module Timetress
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -130,6 +130,35 @@ describe Timetress::Holiday do
130
130
  it "rejects integer input" do
131
131
  lambda { Timetress::Norway.next_pi_day(1) }.should raise_error(ArgumentError)
132
132
  end
133
+ end
134
+
135
+ describe "previous pi day" do
136
+ let(:last_pi_day) { Date.new(2010, 3, 14) }
137
+ let(:pi_day) { Date.new(2011, 3, 14) }
138
+
139
+ it "is this year if it has passed" do
140
+ Timetress.previous_pi_day(pi_day + 1).should eq(pi_day)
141
+ end
142
+
143
+ it "is last year if today is pi day" do
144
+ Timetress.previous_pi_day(pi_day).should eq(last_pi_day)
145
+ end
146
+
147
+ it "is last year if it is coming up" do
148
+ Timetress.previous_pi_day(pi_day - 1).should eq(last_pi_day)
149
+ end
133
150
 
151
+ it "default is relative to today" do
152
+ Timetress::Norway.previous_pi_day.should eq(Timetress::Norway.previous_pi_day(Date.today))
153
+ end
154
+
155
+ it "rejects string input" do
156
+ lambda { Timetress::Norway.previous_pi_day("a string") }.should raise_error(ArgumentError)
157
+ end
158
+
159
+ it "rejects integer input" do
160
+ lambda { Timetress::Norway.previous_pi_day(1) }.should raise_error(ArgumentError)
161
+ end
134
162
  end
163
+
135
164
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timetress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70165893417640 !ruby/object:Gem::Requirement
16
+ requirement: &70185762816380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70165893417640
24
+ version_requirements: *70185762816380
25
25
  description: Answers the age-old question 'When is mothersday this year?'
26
26
  email:
27
27
  - katrina.owen@gmail.com