weekling 1.0.0

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.
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2012
4
+
5
+ This file is part of Weekling.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ # Helper file to allow loading by gem name. Includes namespace Aef::Weekling
21
+ # into Object and extends Date, DateTime and Time to support to_year, to_week
22
+ # and to_week_day.
23
+
24
+ require 'aef/weekling'
25
+
26
+ Object.method(:include).call(Aef::Weekling)
27
+
28
+ Integer.method(:include).call(Aef::Weekling::CoreExtensions::ToYear)
29
+
30
+ [Date, Time, DateTime].each do |klass|
31
+ klass.method(:include).call(Aef::Weekling::CoreExtensions::ToYear)
32
+ klass.method(:include).call(Aef::Weekling::CoreExtensions::ToWeekAndWeekDay)
33
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2012
4
+
5
+ This file is part of Weekling.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ # Require this file if you don't want the Aef::Weekling namespace to be
21
+ # included into Object and don't want Date, DateTime and Time to be extended
22
+ # to support to_year, to_week and to_week_day.
23
+
24
+ require 'aef/weekling'
@@ -0,0 +1,81 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2012
4
+
5
+ This file is part of Weekling.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ require 'spec_helper'
21
+ require 'weekling'
22
+
23
+ describe "weekling gem" do
24
+ it "should include the Aef namespace into Object" do
25
+ Object.should include Aef::Weekling
26
+ Year.should equal Aef::Weekling::Year
27
+ Week.should equal Aef::Weekling::Week
28
+ WeekDay.should equal Aef::Weekling::WeekDay
29
+ end
30
+
31
+ shared_examples_for "convertible to year" do
32
+ it "should be convertible to year" do
33
+ subject.should respond_to(:to_year)
34
+ subject.to_year.should be_a(Aef::Weekling::Year)
35
+ end
36
+ end
37
+
38
+ shared_examples_for "convertible to week" do
39
+ it "should be convertible to week" do
40
+ subject.should respond_to(:to_week)
41
+ subject.to_week.should be_a(Aef::Weekling::Week)
42
+ end
43
+ end
44
+
45
+ shared_examples_for "convertible to week day" do
46
+ it "should be convertible to week day" do
47
+ subject.should respond_to(:to_week_day)
48
+ subject.to_week_day.should be_a(Aef::Weekling::WeekDay)
49
+ end
50
+ end
51
+
52
+ describe Integer do
53
+ subject { 123 }
54
+
55
+ it_should_behave_like "convertible to year"
56
+ end
57
+
58
+ describe Date do
59
+ subject { described_class.today }
60
+
61
+ it_should_behave_like "convertible to year"
62
+ it_should_behave_like "convertible to week"
63
+ it_should_behave_like "convertible to week day"
64
+ end
65
+
66
+ describe DateTime do
67
+ subject { described_class.now }
68
+
69
+ it_should_behave_like "convertible to year"
70
+ it_should_behave_like "convertible to week"
71
+ it_should_behave_like "convertible to week day"
72
+ end
73
+
74
+ describe Time do
75
+ subject { described_class.now }
76
+
77
+ it_should_behave_like "convertible to year"
78
+ it_should_behave_like "convertible to week"
79
+ it_should_behave_like "convertible to week day"
80
+ end
81
+ end
@@ -0,0 +1,607 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2012
4
+
5
+ This file is part of Weekling.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ require 'spec_helper'
21
+ require 'aef/weekling/week_day'
22
+ require 'ostruct'
23
+
24
+ describe Aef::Weekling::WeekDay do
25
+ [:today, :now].each do |method|
26
+ context ".#{method}" do
27
+ it "should generate a representation of the current day as week day" do
28
+ today = Date.today
29
+
30
+ week_day = described_class.method(method).call
31
+
32
+ week_day.week.year.should eql Aef::Weekling::Year.new(today.year)
33
+ week_day.week.index.should eql today.cweek
34
+ week_day.index.should eql ((today.wday - 1) % 7) + 1
35
+ end
36
+ end
37
+ end
38
+
39
+ context ".parse" do
40
+ it "should recognize an ancient week day" do
41
+ week_day = described_class.parse('-1503-W50-6')
42
+
43
+ week_day.week.should eql Aef::Weekling::Week.new(-1503, 50)
44
+ week_day.index.should eql 6
45
+ end
46
+
47
+ it "should recognize a normal week day" do
48
+ week_day = described_class.parse('2011-W30-1')
49
+
50
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 30)
51
+ week_day.index.should eql 1
52
+ end
53
+
54
+ it "should recognize a post apocalyptic week day" do
55
+ week_day = described_class.parse('50023-W03-7')
56
+
57
+ week_day.week.should eql Aef::Weekling::Week.new(50023, 3)
58
+ week_day.index.should eql 7
59
+ end
60
+
61
+ it "should report being unable to parse the given String" do
62
+ lambda{
63
+ described_class.parse('no week day!')
64
+ }.should raise_error(ArgumentError, 'No week day found for parsing')
65
+ end
66
+ end
67
+
68
+ context ".new" do
69
+ it "should complain about a param of invalid type" do
70
+ lambda {
71
+ described_class.new(123)
72
+ }.should raise_error(ArgumentError, 'A single argument must either respond to #week and #index or to #to_date')
73
+ end
74
+
75
+ it "should complain about less than one argument" do
76
+ lambda {
77
+ described_class.new
78
+ }.should raise_error(ArgumentError, 'wrong number of arguments (0 for 1..3)')
79
+ end
80
+
81
+ it "should complain about more than three arguments" do
82
+ lambda {
83
+ described_class.new(123, 456, 789, 123)
84
+ }.should raise_error(ArgumentError, 'wrong number of arguments (4 for 1..3)')
85
+ end
86
+
87
+ it "should allow to create a weekday by a given year, week index and day index" do
88
+ week_day = described_class.new(2011, 1, 6)
89
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 1)
90
+ week_day.index.should eql 6
91
+ end
92
+
93
+ it "should allow to create a weekday by a given year, week index and day symbol" do
94
+ week_day = described_class.new(2011, 1, :saturday)
95
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 1)
96
+ week_day.index.should eql 6
97
+ end
98
+
99
+ it "should allow to create a weekday by a given WeekDay object" do
100
+ old_week_day = described_class.new(2011, 1, 6)
101
+
102
+ week_day = described_class.new(old_week_day)
103
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 1)
104
+ week_day.index.should eql 6
105
+ end
106
+
107
+ it "should allow to create a weekday by a given Week object and day index" do
108
+ week_day = described_class.new(Aef::Weekling::Week.new(2011, 1), 3)
109
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 1)
110
+ week_day.index.should eql 3
111
+ end
112
+
113
+ it "should allow to create a weekday by a given Week object and day symbol" do
114
+ week_day = described_class.new(Aef::Weekling::Week.new(2011, 1), :wednesday)
115
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 1)
116
+ week_day.index.should eql 3
117
+ end
118
+
119
+ it "should allow to create a weekday by a given Date object" do
120
+ date = Date.new(2011, 4, 6)
121
+
122
+ week_day = described_class.new(date)
123
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 14)
124
+ week_day.index.should eql 3
125
+ end
126
+
127
+ it "should allow to create a weekday by a given DateTime object" do
128
+ datetime = DateTime.parse('2011-04-06T16:45:30')
129
+
130
+ week_day = described_class.new(datetime)
131
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 14)
132
+ week_day.index.should eql 3
133
+ end
134
+
135
+ it "should allow to create a weekday by a given Time object" do
136
+ datetime = Time.parse('2011-04-06T16:45:30')
137
+
138
+ week_day = described_class.new(datetime)
139
+ week_day.week.should eql Aef::Weekling::Week.new(2011, 14)
140
+ week_day.index.should eql 3
141
+ end
142
+
143
+ it "should complain about a day index below 1" do
144
+ lambda {
145
+ described_class.new(Aef::Weekling::Week.today, 0)
146
+ }.should raise_error(ArgumentError)
147
+ end
148
+
149
+ it "should complain about a day index above 7" do
150
+ lambda {
151
+ described_class.new(Aef::Weekling::Week.today, 8)
152
+ }.should raise_error(ArgumentError)
153
+ end
154
+
155
+ it "should complain about an invalid day symbol" do
156
+ lambda {
157
+ described_class.new(Aef::Weekling::Week.today, :poopsday)
158
+ }.should raise_error(ArgumentError)
159
+ end
160
+ end
161
+
162
+ context "#== (type independent equality)" do
163
+ it "should be true if week and index match" do
164
+ week = described_class.new(2012, 1, 3)
165
+ other = described_class.new(2012, 1, 3)
166
+
167
+ week.should == other
168
+ end
169
+
170
+ it "should be true if week and index match, independent of the other object's type" do
171
+ week = described_class.new(2012, 1, 3)
172
+
173
+ other = OpenStruct.new
174
+ other.week = Aef::Weekling::Week.new(2012, 1)
175
+ other.index = 3
176
+
177
+ week.should == other
178
+ end
179
+
180
+ it "should be false if week matches but not index" do
181
+ week = described_class.new(2012, 1, 2)
182
+ other = described_class.new(2012, 1, 4)
183
+
184
+ week.should_not == other
185
+ end
186
+
187
+ it "should be false if week matches but not index, independent of the other object's type" do
188
+ week = described_class.new(2012, 1, 2)
189
+
190
+ other = OpenStruct.new
191
+ other.week = Aef::Weekling::Week.new(2012, 1)
192
+ other.index = 4
193
+
194
+ week.should_not == other
195
+ end
196
+
197
+ it "should be false if index matches but not week" do
198
+ week = described_class.new(2011, 15, 1)
199
+ other = described_class.new(2011, 17, 1)
200
+
201
+ week.should_not == other
202
+ end
203
+
204
+ it "should be false if index matches but not week, independent of the other object's type" do
205
+ week = described_class.new(2011, 15, 1)
206
+
207
+ other = OpenStruct.new
208
+ other.week = Aef::Weekling::Week.new(2011, 17)
209
+ other.index = 1
210
+
211
+ week.should_not == other
212
+ end
213
+
214
+ it "should be false if both index and week do not match" do
215
+ week = described_class.new(2012, 23, 1)
216
+ other = described_class.new(2005, 14, 5)
217
+
218
+ week.should_not == other
219
+ end
220
+
221
+ it "should be false if both index and year do not match, independent of the other object's type" do
222
+ week = described_class.new(2012, 23, 1)
223
+
224
+ other = OpenStruct.new
225
+ other.week = Aef::Weekling::Week.new(2005, 14)
226
+ other.index = 5
227
+
228
+ week.should_not == other
229
+ end
230
+ end
231
+
232
+ context "#eql? (type dependent equality)" do
233
+ it "should be true if week and index match" do
234
+ week = described_class.new(2012, 1, 3)
235
+ other = described_class.new(2012, 1, 3)
236
+
237
+ week.should eql other
238
+ end
239
+
240
+ it "should be false if week matches but not index" do
241
+ week = described_class.new(2012, 1, 2)
242
+ other = described_class.new(2012, 1, 4)
243
+
244
+ week.should_not eql other
245
+ end
246
+
247
+ it "should be false if index matches but not week" do
248
+ week = described_class.new(2011, 15, 1)
249
+ other = described_class.new(2011, 17, 1)
250
+
251
+ week.should_not eql other
252
+ end
253
+
254
+ it "should be false if both index and week do not match" do
255
+ week = described_class.new(2012, 23, 1)
256
+ other = described_class.new(2005, 14, 4)
257
+
258
+ week.should_not eql other
259
+ end
260
+ end
261
+
262
+ context "#hash" do
263
+ it "should return Integers" do
264
+ a_week_day = described_class.new(2012, 5, 4)
265
+ another_week_day = described_class.new(2012, 5, 5)
266
+
267
+ a_week_day.hash.should be_a(Integer)
268
+ another_week_day.hash.should be_a(Integer)
269
+ end
270
+
271
+ it "should discriminate a week-day from another one" do
272
+ a_week_day = described_class.new(2012, 5, 4)
273
+ another_week_day = described_class.new(2012, 5, 5)
274
+
275
+ a_week_day.hash.should_not == another_week_day.hash
276
+ end
277
+ end
278
+
279
+ context "#<=>" do
280
+ it "should correctly determine the order of week days based on week" do
281
+ lower_week_day = described_class.new(2011, 13, 3)
282
+ higher_week_day = described_class.new(2012, 50, 3)
283
+
284
+ lower_week_day.should < higher_week_day
285
+ end
286
+
287
+ it "should correctly determine the order of week days based on year, independent of type" do
288
+ lower_week_day = described_class.new(2011, 13, 3)
289
+
290
+ higher_week_day = OpenStruct.new
291
+ higher_week_day.week = Aef::Weekling::Week.new(2012, 50)
292
+ higher_week_day.index = 3
293
+
294
+ lower_week_day.should < higher_week_day
295
+ end
296
+
297
+ it "should correctly determine the order of week days based on index" do
298
+ lower_week_day = described_class.new(2011, 15, 2)
299
+ higher_week_day = described_class.new(2011, 15, 3)
300
+
301
+ lower_week_day.should < higher_week_day
302
+ end
303
+
304
+ it "should correctly determine the order of week days based on index, independent of type" do
305
+ lower_week_day = described_class.new(2011, 15, 2)
306
+
307
+ higher_week_day = OpenStruct.new
308
+ higher_week_day.week = Aef::Weekling::Week.new(2011, 15)
309
+ higher_week_day.index = 3
310
+
311
+ lower_week_day.should < higher_week_day
312
+ end
313
+
314
+ it "should prioritize the order weeks when determining the order of week days" do
315
+ lower_week_day = described_class.new(2012, 13, 4)
316
+ higher_week_day = described_class.new(2012, 14, 3)
317
+
318
+ lower_week_day.should < higher_week_day
319
+ end
320
+
321
+ it "should prioritize the order weeks when determining the order of week days, independent of type" do
322
+ lower_week_day = described_class.new(2012, 13, 4)
323
+
324
+ higher_week_day = OpenStruct.new
325
+ higher_week_day.week = Aef::Weekling::Week.new(2012, 14)
326
+ higher_week_day.index = 3
327
+
328
+ lower_week_day.should < higher_week_day
329
+ end
330
+ end
331
+
332
+ context "#to_s" do
333
+ it "should be able to display an ancient week day" do
334
+ week_day = described_class.new(-1503, 50, 3)
335
+
336
+ week_day.to_s.should eql '-1503-W50-3'
337
+ end
338
+
339
+ it "should be able to display a normal week" do
340
+ week_day = described_class.new(2011, 30, 7)
341
+
342
+ week_day.to_s.should eql '2011-W30-7'
343
+ end
344
+
345
+ it "should be able to display a post apocalyptic week" do
346
+ week_day = described_class.new(50023, 3, 1)
347
+
348
+ week_day.to_s.should eql '50023-W03-1'
349
+ end
350
+ end
351
+
352
+ context "#inspect" do
353
+ it "should be able to display an ancient week day" do
354
+ week_day = described_class.new(-1503, 50, 3)
355
+
356
+ week_day.inspect.should eql '#<Aef::Weekling::WeekDay: -1503-W50-3>'
357
+ end
358
+
359
+ it "should be able to display a normal week" do
360
+ week_day = described_class.new(2011, 30, 7)
361
+
362
+ week_day.inspect.should eql '#<Aef::Weekling::WeekDay: 2011-W30-7>'
363
+ end
364
+
365
+ it "should be able to display a post apocalyptic week" do
366
+ week_day = described_class.new(50023, 3, 1)
367
+
368
+ week_day.inspect.should eql '#<Aef::Weekling::WeekDay: 50023-W03-1>'
369
+ end
370
+ end
371
+
372
+ context "#to_date" do
373
+ it "should translate to the Date of the day" do
374
+ week_day = described_class.new(2011, 30, 3)
375
+
376
+ week_day.to_date.should eql Date.new(2011, 7, 27)
377
+ end
378
+
379
+ it "should translate to the Date of the day in edge cases early in the year" do
380
+ week_day = described_class.new(2010, 52, 6)
381
+
382
+ week_day.to_date.should eql Date.new(2011, 1, 1)
383
+ end
384
+
385
+ it "should translate to the Date of the day in edge cases late in the year" do
386
+ week_day = described_class.new(2011, 52, 7)
387
+
388
+ week_day.to_date.should eql Date.new(2012, 1, 1)
389
+ end
390
+ end
391
+
392
+ context "#to_week_date" do
393
+ it "should return itself" do
394
+ week_day = described_class.new(2011, 30, 6)
395
+ week_day.to_week_day.should equal(week_day)
396
+ end
397
+ end
398
+
399
+ [:next, :succ].each do |method|
400
+ context "##{method}" do
401
+ it "should return the next week day" do
402
+ described_class.new(2011, 19, 3).method(method).call.should eql described_class.new(2011, 19, 4)
403
+ end
404
+
405
+ it "should return the next week day at the end of a week" do
406
+ described_class.new(2011, 30, 7).method(method).call.should eql described_class.new(2011, 31, 1)
407
+ end
408
+
409
+ it "should return the next week day at the end of a year with 52 weeks" do
410
+ described_class.new(2000, 52, 7).method(method).call.should eql described_class.new(2001, 1, 1)
411
+ end
412
+
413
+ it "should return the next week day at the end of a year with 53 weeks" do
414
+ described_class.new(1998, 53, 7).method(method).call.should eql described_class.new(1999, 1, 1)
415
+ end
416
+ end
417
+ end
418
+
419
+ [:previous, :pred].each do |method|
420
+ context "##{method}" do
421
+ it "should return the previous week day" do
422
+ described_class.new(2011, 20, 3).method(method).call.should eql described_class.new(2011, 20, 2)
423
+ end
424
+
425
+ it "should return the previous week day at the beginning of a week" do
426
+ described_class.new(2011, 9, 1).method(method).call.should eql described_class.new(2011, 8, 7)
427
+ end
428
+
429
+ it "should return the previous week day at the beginning of a year following a year with 52 weeks" do
430
+ described_class.new(2001, 1, 1).method(method).call.should eql described_class.new(2000, 52, 7)
431
+ end
432
+
433
+ it "should return the previous week day at the beginning of a year following a year with 53 weeks" do
434
+ described_class.new(1999, 1, 1).method(method).call.should eql described_class.new(1998, 53, 7)
435
+ end
436
+ end
437
+ end
438
+
439
+ context "#+" do
440
+ it "should be able to add a positive amount of days" do
441
+ (described_class.new(1996, 51, 4) + 2).should eql described_class.new(1996, 51, 6)
442
+ end
443
+
444
+ it "should be able to add a positive amount of days so that the result isn't in the week anymore'" do
445
+ (described_class.new(1996, 51, 4) + 4).should eql described_class.new(1996, 52, 1)
446
+ end
447
+
448
+ it "should be able to add a positive amount of days so that the result isn't in the year anymore'" do
449
+ (described_class.new(1996, 51, 4) + 12).should eql described_class.new(1997, 1, 2)
450
+ end
451
+
452
+ it "should be able to add a positive amount of days so that the result isn't in the year with 53 weeks anymore'" do
453
+ (described_class.new(1998, 51, 4) + 20).should eql described_class.new(1999, 1, 3)
454
+ end
455
+
456
+ it "should be able to add a negative amount of days" do
457
+ (described_class.new(1996, 2, 4) + -2).should eql described_class.new(1996, 2, 2)
458
+ end
459
+
460
+ it "should be able to add a negative amount of days so that the result isn't in the week anymore'" do
461
+ (described_class.new(1996, 2, 4) + -5).should eql described_class.new(1996, 1, 6)
462
+ end
463
+
464
+ it "should be able to add a negative amount of days so that the result isn't in the year anymore'" do
465
+ (described_class.new(1996, 2, 4) + -15).should eql described_class.new(1995, 52, 3)
466
+ end
467
+
468
+ it "should be able to add a negative amount of days so that the result is in the previous year with 53 weeks'" do
469
+ (described_class.new(1999, 2, 1) + -10).should eql described_class.new(1998, 53, 5)
470
+ end
471
+
472
+ it "should be able to add zero days" do
473
+ (described_class.new(1996, 51, 4) + 0).should eql described_class.new(1996, 51, 4)
474
+ end
475
+ end
476
+
477
+ context "#-" do
478
+ it "should be able to subtract a positive amount of days" do
479
+ (described_class.new(1996, 2, 4) - 2).should eql described_class.new(1996, 2, 2)
480
+ end
481
+
482
+ it "should be able to subtract a positive amount of days so that the result isn't in the week anymore'" do
483
+ (described_class.new(1996, 2, 4) - 5).should eql described_class.new(1996, 1, 6)
484
+ end
485
+
486
+ it "should be able to subtract a positive amount of days so that the result isn't in the year anymore'" do
487
+ (described_class.new(1996, 2, 4) - 15).should eql described_class.new(1995, 52, 3)
488
+ end
489
+
490
+ it "should be able to subtract a positive amount of days so that the result is in the previous year with 53 weeks'" do
491
+ (described_class.new(1999, 2, 1) - 10).should eql described_class.new(1998, 53, 5)
492
+ end
493
+
494
+ it "should be able to subtract a negative amount of days" do
495
+ (described_class.new(1996, 51, 4) - -2).should eql described_class.new(1996, 51, 6)
496
+ end
497
+
498
+ it "should be able to subtract a negative amount of days so that the result isn't in the week anymore'" do
499
+ (described_class.new(1996, 51, 4) - -4).should eql described_class.new(1996, 52, 1)
500
+ end
501
+
502
+ it "should be able to subtract a negative amount of days so that the result isn't in the year anymore'" do
503
+ (described_class.new(1996, 51, 4) - -12).should eql described_class.new(1997, 1, 2)
504
+ end
505
+
506
+ it "should be able to subtract a negative amount of days so that the result isn't in the year with 53 weeks anymore'" do
507
+ (described_class.new(1998, 51, 4) - -20).should eql described_class.new(1999, 1, 3)
508
+ end
509
+
510
+ it "should be able to subtract zero days" do
511
+ (described_class.new(1996, 51, 4) - 0).should eql described_class.new(1996, 51, 4)
512
+ end
513
+ end
514
+
515
+ context "weekday methods" do
516
+ it "should report monday" do
517
+ week_day = described_class.new(2011, 17, 1)
518
+ week_day.monday?.should be_true
519
+ week_day.tuesday?.should be_false
520
+ week_day.wednesday?.should be_false
521
+ week_day.thursday?.should be_false
522
+ week_day.friday?.should be_false
523
+ week_day.saturday?.should be_false
524
+ week_day.sunday?.should be_false
525
+ week_day.weekend?.should be_false
526
+ week_day.to_sym.should eql :monday
527
+ end
528
+
529
+ it "should report tuesday" do
530
+ week_day = described_class.new(2011, 17, 2)
531
+ week_day.monday?.should be_false
532
+ week_day.tuesday?.should be_true
533
+ week_day.wednesday?.should be_false
534
+ week_day.thursday?.should be_false
535
+ week_day.friday?.should be_false
536
+ week_day.saturday?.should be_false
537
+ week_day.sunday?.should be_false
538
+ week_day.weekend?.should be_false
539
+ week_day.to_sym.should eql :tuesday
540
+ end
541
+
542
+ it "should report wednesday" do
543
+ week_day = described_class.new(2011, 17, 3)
544
+ week_day.monday?.should be_false
545
+ week_day.tuesday?.should be_false
546
+ week_day.wednesday?.should be_true
547
+ week_day.thursday?.should be_false
548
+ week_day.friday?.should be_false
549
+ week_day.saturday?.should be_false
550
+ week_day.sunday?.should be_false
551
+ week_day.weekend?.should be_false
552
+ week_day.to_sym.should eql :wednesday
553
+ end
554
+
555
+ it "should report thursday" do
556
+ week_day = described_class.new(2011, 17, 4)
557
+ week_day.monday?.should be_false
558
+ week_day.tuesday?.should be_false
559
+ week_day.wednesday?.should be_false
560
+ week_day.thursday?.should be_true
561
+ week_day.friday?.should be_false
562
+ week_day.saturday?.should be_false
563
+ week_day.sunday?.should be_false
564
+ week_day.weekend?.should be_false
565
+ week_day.to_sym.should eql :thursday
566
+ end
567
+
568
+ it "should report friday" do
569
+ week_day = described_class.new(2011, 17, 5)
570
+ week_day.monday?.should be_false
571
+ week_day.tuesday?.should be_false
572
+ week_day.wednesday?.should be_false
573
+ week_day.thursday?.should be_false
574
+ week_day.friday?.should be_true
575
+ week_day.saturday?.should be_false
576
+ week_day.sunday?.should be_false
577
+ week_day.weekend?.should be_false
578
+ week_day.to_sym.should eql :friday
579
+ end
580
+
581
+ it "should report saturday" do
582
+ week_day = described_class.new(2011, 17, 6)
583
+ week_day.monday?.should be_false
584
+ week_day.tuesday?.should be_false
585
+ week_day.wednesday?.should be_false
586
+ week_day.thursday?.should be_false
587
+ week_day.friday?.should be_false
588
+ week_day.saturday?.should be_true
589
+ week_day.sunday?.should be_false
590
+ week_day.weekend?.should be_true
591
+ week_day.to_sym.should eql :saturday
592
+ end
593
+
594
+ it "should report sunday" do
595
+ week_day = described_class.new(2011, 17, 7)
596
+ week_day.monday?.should be_false
597
+ week_day.tuesday?.should be_false
598
+ week_day.wednesday?.should be_false
599
+ week_day.thursday?.should be_false
600
+ week_day.friday?.should be_false
601
+ week_day.saturday?.should be_false
602
+ week_day.sunday?.should be_true
603
+ week_day.weekend?.should be_true
604
+ week_day.to_sym.should eql :sunday
605
+ end
606
+ end
607
+ end