-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquarter_spec.rb
54 lines (45 loc) · 1.55 KB
/
quarter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Quarter" do
let (:q1) {Quarter.new(1, 2009)}
let (:q2) {Quarter.new(2, 2009)}
let (:q3) {Quarter.new(3, 2009)}
let (:q4) {Quarter.new(4, 2009)}
it "can be newed up" do
quarter = Quarter.new(1, 2009)
quarter.number.should == 1
quarter.year.should == 2009
end
it "can initialize from any date" do
quarter = Quarter.from(DateTime.new(2009, 2, 1))
quarter.year.should == 2009
quarter.number.should == 1
quarter = Quarter.from(DateTime.new(2009, 7, 15))
quarter.year.should == 2009
quarter.number.should == 3
end
it "sets the start date correctly" do
q1.start_date.should == DateTime.new(2009, 1, 1)
q2.start_date.should == DateTime.new(2009, 4, 1)
q3.start_date.should == DateTime.new(2009, 7, 1)
q4.start_date.should == DateTime.new(2009, 10, 1)
end
it "sets the end date correctly" do
q1.end_date.should == DateTime.new(2009, 3, 31)
q2.end_date.should == DateTime.new(2009, 6, 30)
q3.end_date.should == DateTime.new(2009, 9, 30)
q4.end_date.should == DateTime.new(2009, 12, 31)
end
it "can iterate over quarters" do
range = (q1..q3)
range.first.should == q1
range.to_a.length.should == 3
range.end.should == q3
end
it "is a daterange" do
q1.months.to_a.length.should == 3
end
it "can calculate the number of quarters in a daterange correctly" do
range = SimpleRange.new(DateTime.new(2009, 1, 1), DateTime.new(2009, 7, 15))
range.quarters.to_a.length.should == 3
end
end