fat_core 0.0.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3607f0be1274b7aaf76f304d49f3520e77d660a9
4
- data.tar.gz: ad4c5ae566a070959c19c5bd6dab95c43ed0f234
3
+ metadata.gz: 8ca41250c3f9b03257b33633c7bdadea6f0e1d8b
4
+ data.tar.gz: 4af0065da337d9a77211fe4ee27802842b08f0b6
5
5
  SHA512:
6
- metadata.gz: f59a2e0bfa35cf755a4578a5daf84e614c9f11470c1fe3f94d6cfc1edf79cb4ab5a054813bc961f74edb82a0e76daee8d92e01bd0a1c5ff041b5cf5d216a916d
7
- data.tar.gz: d3fecd8a83aec2101df3f1bac6d6427773c71e73a6158b6ab456330ca5598cc44710bef01ae863d3bc787ebed4a73f41ebc9402c15d4b42e0486a71a702e2e6a
6
+ metadata.gz: a031a05bae6490638d336b9552fcbac2e7537ef4593016e9ac0bdbf158e35c9226e749799310c2569574dc68bb71cffb4c037ee0d36e6f8a8fccde60ee0c5492
7
+ data.tar.gz: a63755c81cf3bae6175810301584f2f18e2afe34bb0df1667a3c3a01eb4ffd641146f15d4994f807203a6bcce31457cb6ea1bfede45a165d0652e53fd368b247
@@ -47,6 +47,15 @@ class Period
47
47
  end
48
48
  end
49
49
 
50
+ # Return a period based on two date specs (see Date.parse_spec), a '''from'
51
+ # and a 'to' spec. If the to-spec is not given or is nil, the from-spec is
52
+ # used for both the from- and to-spec. If no from-spec is given, return
53
+ # today as the period.
54
+ def self.parse_spec(from = 'today', to = nil)
55
+ to ||= from
56
+ Period.new(Date.parse_spec(from, :from), Date.parse_spec(to, :to))
57
+ end
58
+
50
59
  # Possibly useful class method to take an array of periods and join all the
51
60
  # contiguous ones, then return an array of the disjoint periods not
52
61
  # contiguous to one another. An array of periods with no gaps should return
@@ -1,3 +1,3 @@
1
1
  module FatCore
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -4,9 +4,8 @@ describe Date do
4
4
  before :each do
5
5
  # Pretend it is this date. Not at beg or end of year, quarter,
6
6
  # month, or week. It is a Wednesday
7
- Date.stub(:current).and_return(Date.parse('2012-07-18'))
8
- Date.stub(:today).and_return(Date.parse('2012-07-18'))
9
- @test_today = Date.parse('2012-07-18')
7
+ allow(Date).to receive_messages(:today => Date.parse('2012-07-18'))
8
+ allow(Date).to receive_messages(:current => Date.parse('2012-07-18'))
10
9
  end
11
10
 
12
11
  describe "class methods" do
@@ -20,137 +19,137 @@ describe Date do
20
19
  end
21
20
 
22
21
  it "should parse plain iso dates correctly" do
23
- Date.parse_spec('2011-07-15').should eq Date.parse('2011-07-15')
24
- Date.parse_spec('2011-08-05').should eq Date.parse('2011-08-05')
22
+ expect(Date.parse_spec('2011-07-15')).to eq Date.parse('2011-07-15')
23
+ expect(Date.parse_spec('2011-08-05')).to eq Date.parse('2011-08-05')
25
24
  end
26
25
 
27
26
  it "should parse week numbers such as 'W23' or '23W' correctly" do
28
- Date.parse_spec('W1').should eq Date.parse('2012-01-02')
29
- Date.parse_spec('W23').should eq Date.parse('2012-06-04')
30
- Date.parse_spec('W23', :to).should eq Date.parse('2012-06-10')
31
- Date.parse_spec('23W').should eq Date.parse('2012-06-04')
32
- Date.parse_spec('23W', :to).should eq Date.parse('2012-06-10')
27
+ expect(Date.parse_spec('W1')).to eq Date.parse('2012-01-02')
28
+ expect(Date.parse_spec('W23')).to eq Date.parse('2012-06-04')
29
+ expect(Date.parse_spec('W23', :to)).to eq Date.parse('2012-06-10')
30
+ expect(Date.parse_spec('23W')).to eq Date.parse('2012-06-04')
31
+ expect(Date.parse_spec('23W', :to)).to eq Date.parse('2012-06-10')
33
32
  expect {
34
33
  Date.parse_spec('W83', :to)
35
34
  }.to raise_error
36
35
  end
37
36
 
38
37
  it "should parse year-week numbers such as 'YYYY-W23' or 'YYYY-23W' correctly" do
39
- Date.parse_spec('2003-W1').should eq Date.parse('2002-12-30')
40
- Date.parse_spec('2003-W1', :to).should eq Date.parse('2003-01-05')
41
- Date.parse_spec('2003-W23').should eq Date.parse('2003-06-02')
42
- Date.parse_spec('2003-W23', :to).should eq Date.parse('2003-06-08')
43
- Date.parse_spec('2003-23W').should eq Date.parse('2003-06-02')
44
- Date.parse_spec('2003-23W', :to).should eq Date.parse('2003-06-08')
38
+ expect(Date.parse_spec('2003-W1')).to eq Date.parse('2002-12-30')
39
+ expect(Date.parse_spec('2003-W1', :to)).to eq Date.parse('2003-01-05')
40
+ expect(Date.parse_spec('2003-W23')).to eq Date.parse('2003-06-02')
41
+ expect(Date.parse_spec('2003-W23', :to)).to eq Date.parse('2003-06-08')
42
+ expect(Date.parse_spec('2003-23W')).to eq Date.parse('2003-06-02')
43
+ expect(Date.parse_spec('2003-23W', :to)).to eq Date.parse('2003-06-08')
45
44
  expect {
46
45
  Date.parse_spec('2003-W83', :to)
47
46
  }.to raise_error
48
47
  end
49
48
 
50
49
  it "should parse year-quarter specs such as YYYY-NQ or YYYY-QN" do
51
- Date.parse_spec('2011-4Q', :from).should eq Date.parse('2011-10-01')
52
- Date.parse_spec('2011-4Q', :to).should eq Date.parse('2011-12-31')
53
- Date.parse_spec('2011-Q4', :from).should eq Date.parse('2011-10-01')
54
- Date.parse_spec('2011-Q4', :to).should eq Date.parse('2011-12-31')
50
+ expect(Date.parse_spec('2011-4Q', :from)).to eq Date.parse('2011-10-01')
51
+ expect(Date.parse_spec('2011-4Q', :to)).to eq Date.parse('2011-12-31')
52
+ expect(Date.parse_spec('2011-Q4', :from)).to eq Date.parse('2011-10-01')
53
+ expect(Date.parse_spec('2011-Q4', :to)).to eq Date.parse('2011-12-31')
55
54
  expect { Date.parse_spec('2011-5Q') }.to raise_error
56
55
  end
57
56
 
58
57
  it "should parse quarter-only specs such as NQ or QN" do
59
- Date.parse_spec('4Q', :from).should eq Date.parse('2012-10-01')
60
- Date.parse_spec('4Q', :to).should eq Date.parse('2012-12-31')
61
- Date.parse_spec('Q4', :from).should eq Date.parse('2012-10-01')
62
- Date.parse_spec('Q4', :to).should eq Date.parse('2012-12-31')
58
+ expect(Date.parse_spec('4Q', :from)).to eq Date.parse('2012-10-01')
59
+ expect(Date.parse_spec('4Q', :to)).to eq Date.parse('2012-12-31')
60
+ expect(Date.parse_spec('Q4', :from)).to eq Date.parse('2012-10-01')
61
+ expect(Date.parse_spec('Q4', :to)).to eq Date.parse('2012-12-31')
63
62
  expect { Date.parse_spec('5Q') }.to raise_error
64
63
  end
65
64
 
66
65
  it "should parse year-month specs such as YYYY-MM" do
67
- Date.parse_spec('2010-5', :from).should eq Date.parse('2010-05-01')
68
- Date.parse_spec('2010-5', :to).should eq Date.parse('2010-05-31')
66
+ expect(Date.parse_spec('2010-5', :from)).to eq Date.parse('2010-05-01')
67
+ expect(Date.parse_spec('2010-5', :to)).to eq Date.parse('2010-05-31')
69
68
  expect { Date.parse_spec('2010-13') }.to raise_error
70
69
  end
71
70
 
72
71
  it "should parse month-only specs such as MM" do
73
- Date.parse_spec('10', :from).should eq Date.parse('2012-10-01')
74
- Date.parse_spec('10', :to).should eq Date.parse('2012-10-31')
72
+ expect(Date.parse_spec('10', :from)).to eq Date.parse('2012-10-01')
73
+ expect(Date.parse_spec('10', :to)).to eq Date.parse('2012-10-31')
75
74
  expect { Date.parse_spec('99') }.to raise_error
76
75
  expect { Date.parse_spec('011') }.to raise_error
77
76
  end
78
77
 
79
78
  it "should parse year-only specs such as YYYY" do
80
- Date.parse_spec('2010', :from).should eq Date.parse('2010-01-01')
81
- Date.parse_spec('2010', :to).should eq Date.parse('2010-12-31')
79
+ expect(Date.parse_spec('2010', :from)).to eq Date.parse('2010-01-01')
80
+ expect(Date.parse_spec('2010', :to)).to eq Date.parse('2010-12-31')
82
81
  expect { Date.parse_spec('99999') }.to raise_error
83
82
  end
84
83
 
85
84
  it "should parse relative day names: today, yesterday" do
86
- Date.parse_spec('today').should eq Date.current
87
- Date.parse_spec('this_day').should eq Date.current
88
- Date.parse_spec('yesterday').should eq Date.current - 1.day
89
- Date.parse_spec('last_day').should eq Date.current - 1.day
85
+ expect(Date.parse_spec('today')).to eq Date.current
86
+ expect(Date.parse_spec('this_day')).to eq Date.current
87
+ expect(Date.parse_spec('yesterday')).to eq Date.current - 1.day
88
+ expect(Date.parse_spec('last_day')).to eq Date.current - 1.day
90
89
  end
91
90
 
92
91
  it "should parse relative weeks: this_week, last_week" do
93
- Date.parse_spec('this_week').should eq Date.parse('2012-07-16')
94
- Date.parse_spec('this_week', :to).should eq Date.parse('2012-07-22')
95
- Date.parse_spec('last_week').should eq Date.parse('2012-07-09')
96
- Date.parse_spec('last_week', :to).should eq Date.parse('2012-07-15')
92
+ expect(Date.parse_spec('this_week')).to eq Date.parse('2012-07-16')
93
+ expect(Date.parse_spec('this_week', :to)).to eq Date.parse('2012-07-22')
94
+ expect(Date.parse_spec('last_week')).to eq Date.parse('2012-07-09')
95
+ expect(Date.parse_spec('last_week', :to)).to eq Date.parse('2012-07-15')
97
96
  end
98
97
 
99
98
  it "should parse relative biweeks: this_biweek, last_biweek" do
100
- Date.parse_spec('this_biweek').should eq Date.parse('2012-07-16')
101
- Date.parse_spec('this_biweek', :to).should eq Date.parse('2012-07-29')
102
- Date.parse_spec('last_biweek').should eq Date.parse('2012-07-02')
103
- Date.parse_spec('last_biweek', :to).should eq Date.parse('2012-07-15')
99
+ expect(Date.parse_spec('this_biweek')).to eq Date.parse('2012-07-16')
100
+ expect(Date.parse_spec('this_biweek', :to)).to eq Date.parse('2012-07-29')
101
+ expect(Date.parse_spec('last_biweek')).to eq Date.parse('2012-07-02')
102
+ expect(Date.parse_spec('last_biweek', :to)).to eq Date.parse('2012-07-15')
104
103
  end
105
104
 
106
105
  it "should parse relative months: this_semimonth, last_semimonth" do
107
- Date.parse_spec('this_semimonth').should eq Date.parse('2012-07-16')
108
- Date.parse_spec('this_semimonth', :to).should eq Date.parse('2012-07-31')
109
- Date.parse_spec('last_semimonth').should eq Date.parse('2012-07-01')
110
- Date.parse_spec('last_semimonth', :to).should eq Date.parse('2012-07-15')
106
+ expect(Date.parse_spec('this_semimonth')).to eq Date.parse('2012-07-16')
107
+ expect(Date.parse_spec('this_semimonth', :to)).to eq Date.parse('2012-07-31')
108
+ expect(Date.parse_spec('last_semimonth')).to eq Date.parse('2012-07-01')
109
+ expect(Date.parse_spec('last_semimonth', :to)).to eq Date.parse('2012-07-15')
111
110
  end
112
111
 
113
112
  it "should parse relative months: this_month, last_month" do
114
- Date.parse_spec('this_month').should eq Date.parse('2012-07-01')
115
- Date.parse_spec('this_month', :to).should eq Date.parse('2012-07-31')
116
- Date.parse_spec('last_month').should eq Date.parse('2012-06-01')
117
- Date.parse_spec('last_month', :to).should eq Date.parse('2012-06-30')
113
+ expect(Date.parse_spec('this_month')).to eq Date.parse('2012-07-01')
114
+ expect(Date.parse_spec('this_month', :to)).to eq Date.parse('2012-07-31')
115
+ expect(Date.parse_spec('last_month')).to eq Date.parse('2012-06-01')
116
+ expect(Date.parse_spec('last_month', :to)).to eq Date.parse('2012-06-30')
118
117
  end
119
118
 
120
119
  it "should parse relative bimonths: this_bimonth, last_bimonth" do
121
- Date.parse_spec('this_bimonth').should eq Date.parse('2012-07-01')
122
- Date.parse_spec('this_bimonth', :to).should eq Date.parse('2012-08-31')
123
- Date.parse_spec('last_bimonth').should eq Date.parse('2012-05-01')
124
- Date.parse_spec('last_bimonth', :to).should eq Date.parse('2012-06-30')
120
+ expect(Date.parse_spec('this_bimonth')).to eq Date.parse('2012-07-01')
121
+ expect(Date.parse_spec('this_bimonth', :to)).to eq Date.parse('2012-08-31')
122
+ expect(Date.parse_spec('last_bimonth')).to eq Date.parse('2012-05-01')
123
+ expect(Date.parse_spec('last_bimonth', :to)).to eq Date.parse('2012-06-30')
125
124
  end
126
125
 
127
126
  it "should parse relative quarters: this_quarter, last_quarter" do
128
- Date.parse_spec('this_quarter').should eq Date.parse('2012-07-01')
129
- Date.parse_spec('this_quarter', :to).should eq Date.parse('2012-09-30')
130
- Date.parse_spec('last_quarter').should eq Date.parse('2012-04-01')
131
- Date.parse_spec('last_quarter', :to).should eq Date.parse('2012-06-30')
127
+ expect(Date.parse_spec('this_quarter')).to eq Date.parse('2012-07-01')
128
+ expect(Date.parse_spec('this_quarter', :to)).to eq Date.parse('2012-09-30')
129
+ expect(Date.parse_spec('last_quarter')).to eq Date.parse('2012-04-01')
130
+ expect(Date.parse_spec('last_quarter', :to)).to eq Date.parse('2012-06-30')
132
131
  end
133
132
 
134
133
  it "should parse relative years: this_year, last_year" do
135
- Date.parse_spec('this_year').should eq Date.parse('2012-01-01')
136
- Date.parse_spec('this_year', :to).should eq Date.parse('2012-12-31')
137
- Date.parse_spec('last_year').should eq Date.parse('2011-01-01')
138
- Date.parse_spec('last_year', :to).should eq Date.parse('2011-12-31')
134
+ expect(Date.parse_spec('this_year')).to eq Date.parse('2012-01-01')
135
+ expect(Date.parse_spec('this_year', :to)).to eq Date.parse('2012-12-31')
136
+ expect(Date.parse_spec('last_year')).to eq Date.parse('2011-01-01')
137
+ expect(Date.parse_spec('last_year', :to)).to eq Date.parse('2011-12-31')
139
138
  end
140
139
 
141
140
  it "should parse forever and never" do
142
- Date.parse_spec('forever').should eq Date::BOT
143
- Date.parse_spec('forever', :to).should eq Date::EOT
144
- Date.parse_spec('never').should be_nil
141
+ expect(Date.parse_spec('forever')).to eq Date::BOT
142
+ expect(Date.parse_spec('forever', :to)).to eq Date::EOT
143
+ expect(Date.parse_spec('never')).to be_nil
145
144
  end
146
145
  end
147
146
 
148
147
  it "should be able to parse an American-style date" do
149
- Date.parse_american('2/12/2011').iso.should eq('2011-02-12')
150
- Date.parse_american('2 / 12/ 2011').iso.should eq('2011-02-12')
151
- Date.parse_american('2 / 1 / 2011').iso.should eq('2011-02-01')
152
- Date.parse_american(' 2 / 1 / 2011 ').iso.should eq('2011-02-01')
153
- Date.parse_american(' 2 / 1 / 15 ').iso.should eq('2015-02-01')
148
+ expect(Date.parse_american('2/12/2011').iso).to eq('2011-02-12')
149
+ expect(Date.parse_american('2 / 12/ 2011').iso).to eq('2011-02-12')
150
+ expect(Date.parse_american('2 / 1 / 2011').iso).to eq('2011-02-01')
151
+ expect(Date.parse_american(' 2 / 1 / 2011 ').iso).to eq('2011-02-01')
152
+ expect(Date.parse_american(' 2 / 1 / 15 ').iso).to eq('2015-02-01')
154
153
  end
155
154
  end
156
155
 
@@ -167,154 +166,146 @@ describe Date do
167
166
  end
168
167
 
169
168
  it "should know its pred and succ (for Range)" do
170
- Date.today.pred.should eq (Date.today - 1)
171
- Date.today.succ.should eq (Date.today + 1)
169
+ expect(Date.today.pred).to eq (Date.today - 1)
170
+ expect(Date.today.succ).to eq (Date.today + 1)
172
171
  end
173
172
 
174
173
  it "should be able to print itself as an American-style date" do
175
- Date.parse('2011-02-12').american.should eq('2/12/2011')
174
+ expect(Date.parse('2011-02-12').american).to eq('2/12/2011')
176
175
  end
177
176
 
178
177
  it "should be able to print itself in iso form" do
179
- Date.today.iso.should == '2012-07-18'
178
+ expect(Date.today.iso).to eq '2012-07-18'
180
179
  end
181
180
 
182
181
  it "should be able to print itself in org form" do
183
- Date.today.org.should eq('[2012-07-18 Wed]')
184
- (Date.today + 1.day).org.should eq('[2012-07-19 Thu]')
182
+ expect(Date.today.org).to eq('[2012-07-18 Wed]')
183
+ expect((Date.today + 1.day).org).to eq('[2012-07-19 Thu]')
185
184
  end
186
185
 
187
186
  it "should be able to print itself in eng form" do
188
- Date.today.eng.should eq('July 18, 2012')
189
- (Date.today + 1.day).eng.should eq('July 19, 2012')
187
+ expect(Date.today.eng).to eq('July 18, 2012')
188
+ expect((Date.today + 1.day).eng).to eq('July 19, 2012')
190
189
  end
191
190
 
192
191
  it "should be able to state its quarter" do
193
- Date.today.quarter.should eq(3)
194
- Date.parse('2012-02-29').quarter.should eq(1)
195
- Date.parse('2012-01-01').quarter.should eq(1)
196
- Date.parse('2012-03-31').quarter.should eq(1)
197
- Date.parse('2012-04-01').quarter.should eq(2)
198
- Date.parse('2012-05-15').quarter.should eq(2)
199
- Date.parse('2012-06-30').quarter.should eq(2)
200
- Date.parse('2012-07-01').quarter.should eq(3)
201
- Date.parse('2012-08-15').quarter.should eq(3)
202
- Date.parse('2012-09-30').quarter.should eq(3)
203
- Date.parse('2012-10-01').quarter.should eq(4)
204
- Date.parse('2012-11-15').quarter.should eq(4)
205
- Date.parse('2012-12-31').quarter.should eq(4)
192
+ expect(Date.today.quarter).to eq(3)
193
+ expect(Date.parse('2012-02-29').quarter).to eq(1)
194
+ expect(Date.parse('2012-01-01').quarter).to eq(1)
195
+ expect(Date.parse('2012-03-31').quarter).to eq(1)
196
+ expect(Date.parse('2012-04-01').quarter).to eq(2)
197
+ expect(Date.parse('2012-05-15').quarter).to eq(2)
198
+ expect(Date.parse('2012-06-30').quarter).to eq(2)
199
+ expect(Date.parse('2012-07-01').quarter).to eq(3)
200
+ expect(Date.parse('2012-08-15').quarter).to eq(3)
201
+ expect(Date.parse('2012-09-30').quarter).to eq(3)
202
+ expect(Date.parse('2012-10-01').quarter).to eq(4)
203
+ expect(Date.parse('2012-11-15').quarter).to eq(4)
204
+ expect(Date.parse('2012-12-31').quarter).to eq(4)
206
205
  end
207
206
 
208
207
  it "should know about years" do
209
- Date.parse('2013-01-01').should be_beginning_of_year
210
- Date.parse('2013-12-31').should be_end_of_year
211
- Date.parse('2013-04-01').should_not be_beginning_of_year
212
- Date.parse('2013-12-30').should_not be_end_of_year
208
+ expect(Date.parse('2013-01-01')).to be_beginning_of_year
209
+ expect(Date.parse('2013-12-31')).to be_end_of_year
210
+ expect(Date.parse('2013-04-01')).to_not be_beginning_of_year
211
+ expect(Date.parse('2013-12-30')).to_not be_end_of_year
213
212
  end
214
213
 
215
214
  it "should know about quarters" do
216
- Date.parse('2013-01-01').should be_beginning_of_quarter
217
- Date.parse('2013-12-31').should be_end_of_quarter
218
- Date.parse('2013-04-01').should be_beginning_of_quarter
219
- Date.parse('2013-06-30').should be_end_of_quarter
220
- Date.parse('2013-05-01').should_not be_beginning_of_quarter
221
- Date.parse('2013-07-31').should_not be_end_of_quarter
215
+ expect(Date.parse('2013-01-01')).to be_beginning_of_quarter
216
+ expect(Date.parse('2013-12-31')).to be_end_of_quarter
217
+ expect(Date.parse('2013-04-01')).to be_beginning_of_quarter
218
+ expect(Date.parse('2013-06-30')).to be_end_of_quarter
219
+ expect(Date.parse('2013-05-01')).to_not be_beginning_of_quarter
220
+ expect(Date.parse('2013-07-31')).to_not be_end_of_quarter
222
221
  end
223
222
 
224
223
  it "should know about bimonths" do
225
- Date.parse('2013-11-04').beginning_of_bimonth.should eq Date.parse('2013-11-01')
226
- Date.parse('2013-11-04').end_of_bimonth.should eq Date.parse('2013-12-31')
227
- Date.parse('2013-03-01').should be_beginning_of_bimonth
228
- Date.parse('2013-04-30').should be_end_of_bimonth
229
- Date.parse('2013-01-01').should be_beginning_of_bimonth
230
- Date.parse('2013-12-31').should be_end_of_bimonth
231
- Date.parse('2013-05-01').should be_beginning_of_bimonth
232
- Date.parse('2013-06-30').should be_end_of_bimonth
233
- Date.parse('2013-06-01').should_not be_beginning_of_bimonth
234
- Date.parse('2013-07-31').should_not be_end_of_bimonth
224
+ expect(Date.parse('2013-11-04').beginning_of_bimonth).to eq Date.parse('2013-11-01')
225
+ expect(Date.parse('2013-11-04').end_of_bimonth).to eq Date.parse('2013-12-31')
226
+ expect(Date.parse('2013-03-01')).to be_beginning_of_bimonth
227
+ expect(Date.parse('2013-04-30')).to be_end_of_bimonth
228
+ expect(Date.parse('2013-01-01')).to be_beginning_of_bimonth
229
+ expect(Date.parse('2013-12-31')).to be_end_of_bimonth
230
+ expect(Date.parse('2013-05-01')).to be_beginning_of_bimonth
231
+ expect(Date.parse('2013-06-30')).to be_end_of_bimonth
232
+ expect(Date.parse('2013-06-01')).to_not be_beginning_of_bimonth
233
+ expect(Date.parse('2013-07-31')).to_not be_end_of_bimonth
235
234
  end
236
235
 
237
236
  it "should know about months" do
238
- Date.parse('2013-01-01').should be_beginning_of_month
239
- Date.parse('2013-12-31').should be_end_of_month
240
- Date.parse('2013-05-01').should be_beginning_of_month
241
- Date.parse('2013-07-31').should be_end_of_month
242
- Date.parse('2013-05-02').should_not be_beginning_of_month
243
- Date.parse('2013-07-30').should_not be_end_of_month
237
+ expect(Date.parse('2013-01-01')).to be_beginning_of_month
238
+ expect(Date.parse('2013-12-31')).to be_end_of_month
239
+ expect(Date.parse('2013-05-01')).to be_beginning_of_month
240
+ expect(Date.parse('2013-07-31')).to be_end_of_month
241
+ expect(Date.parse('2013-05-02')).to_not be_beginning_of_month
242
+ expect(Date.parse('2013-07-30')).to_not be_end_of_month
244
243
  end
245
244
 
246
245
  it "should know about semimonths" do
247
- Date.parse('2013-11-24').beginning_of_semimonth.should eq Date.parse('2013-11-16')
248
- Date.parse('2013-11-04').beginning_of_semimonth.should eq Date.parse('2013-11-01')
249
- Date.parse('2013-11-04').end_of_semimonth.should eq Date.parse('2013-11-15')
250
- Date.parse('2013-11-24').end_of_semimonth.should eq Date.parse('2013-11-30')
251
- Date.parse('2013-03-01').should be_beginning_of_semimonth
252
- Date.parse('2013-03-16').should be_beginning_of_semimonth
253
- Date.parse('2013-04-15').should be_end_of_semimonth
254
- Date.parse('2013-04-30').should be_end_of_semimonth
246
+ expect(Date.parse('2013-11-24').beginning_of_semimonth).to eq Date.parse('2013-11-16')
247
+ expect(Date.parse('2013-11-04').beginning_of_semimonth).to eq Date.parse('2013-11-01')
248
+ expect(Date.parse('2013-11-04').end_of_semimonth).to eq Date.parse('2013-11-15')
249
+ expect(Date.parse('2013-11-24').end_of_semimonth).to eq Date.parse('2013-11-30')
250
+ expect(Date.parse('2013-03-01')).to be_beginning_of_semimonth
251
+ expect(Date.parse('2013-03-16')).to be_beginning_of_semimonth
252
+ expect(Date.parse('2013-04-15')).to be_end_of_semimonth
253
+ expect(Date.parse('2013-04-30')).to be_end_of_semimonth
255
254
  end
256
255
 
257
256
  it "should know about biweeks" do
258
- Date.parse('2013-11-07').beginning_of_biweek.should eq Date.parse('2013-11-04')
259
- Date.parse('2013-11-07').end_of_biweek.should eq Date.parse('2013-11-17')
260
- Date.parse('2013-03-11').should be_beginning_of_biweek
261
- Date.parse('2013-03-24').should be_end_of_biweek
257
+ expect(Date.parse('2013-11-07').beginning_of_biweek).to eq Date.parse('2013-11-04')
258
+ expect(Date.parse('2013-11-07').end_of_biweek).to eq Date.parse('2013-11-17')
259
+ expect(Date.parse('2013-03-11')).to be_beginning_of_biweek
260
+ expect(Date.parse('2013-03-24')).to be_end_of_biweek
262
261
  end
263
262
 
264
263
  it "should know about weeks" do
265
- Date.parse('2013-11-04').should be_beginning_of_week
266
- Date.parse('2013-11-10').should be_end_of_week
267
- Date.parse('2013-12-02').should be_beginning_of_week
268
- Date.parse('2013-12-08').should be_end_of_week
269
- Date.parse('2013-10-13').should_not be_beginning_of_week
270
- Date.parse('2013-10-19').should_not be_end_of_week
264
+ expect(Date.parse('2013-11-04')).to be_beginning_of_week
265
+ expect(Date.parse('2013-11-10')).to be_end_of_week
266
+ expect(Date.parse('2013-12-02')).to be_beginning_of_week
267
+ expect(Date.parse('2013-12-08')).to be_end_of_week
268
+ expect(Date.parse('2013-10-13')).to_not be_beginning_of_week
269
+ expect(Date.parse('2013-10-19')).to_not be_end_of_week
271
270
  end
272
271
 
273
272
  it "should know the beginning of chunks" do
274
- Date.parse('2013-11-04').beginning_of_chunk(:year).should eq Date.parse('2013-01-01')
275
- Date.parse('2013-11-04').beginning_of_chunk(:quarter).should eq Date.parse('2013-10-01')
276
- Date.parse('2013-12-04').beginning_of_chunk(:bimonth).should eq Date.parse('2013-11-01')
277
- Date.parse('2013-11-04').beginning_of_chunk(:month).should eq Date.parse('2013-11-01')
278
- Date.parse('2013-11-04').beginning_of_chunk(:semimonth).should eq Date.parse('2013-11-01')
279
- Date.parse('2013-11-24').beginning_of_chunk(:semimonth).should eq Date.parse('2013-11-16')
280
- Date.parse('2013-11-08').beginning_of_chunk(:biweek).should eq Date.parse('2013-11-04')
281
- Date.parse('2013-11-08').beginning_of_chunk(:week).should eq Date.parse('2013-11-04')
273
+ expect(Date.parse('2013-11-04').beginning_of_chunk(:year)).to eq Date.parse('2013-01-01')
274
+ expect(Date.parse('2013-11-04').beginning_of_chunk(:quarter)).to eq Date.parse('2013-10-01')
275
+ expect(Date.parse('2013-12-04').beginning_of_chunk(:bimonth)).to eq Date.parse('2013-11-01')
276
+ expect(Date.parse('2013-11-04').beginning_of_chunk(:month)).to eq Date.parse('2013-11-01')
277
+ expect(Date.parse('2013-11-04').beginning_of_chunk(:semimonth)).to eq Date.parse('2013-11-01')
278
+ expect(Date.parse('2013-11-24').beginning_of_chunk(:semimonth)).to eq Date.parse('2013-11-16')
279
+ expect(Date.parse('2013-11-08').beginning_of_chunk(:biweek)).to eq Date.parse('2013-11-04')
280
+ expect(Date.parse('2013-11-08').beginning_of_chunk(:week)).to eq Date.parse('2013-11-04')
282
281
  expect {
283
282
  Date.parse('2013-11-04').beginning_of_chunk(:wek)
284
283
  }.to raise_error
285
284
  end
286
285
 
287
286
  it "should know the end of chunks" do
288
- Date.parse('2013-07-04').end_of_chunk(:year).should eq Date.parse('2013-12-31')
289
- Date.parse('2013-07-04').end_of_chunk(:quarter).should eq Date.parse('2013-09-30')
290
- Date.parse('2013-12-04').end_of_chunk(:bimonth).should eq Date.parse('2013-12-31')
291
- Date.parse('2013-07-04').end_of_chunk(:month).should eq Date.parse('2013-07-31')
292
- Date.parse('2013-11-04').end_of_chunk(:semimonth).should eq Date.parse('2013-11-15')
293
- Date.parse('2013-11-24').end_of_chunk(:semimonth).should eq Date.parse('2013-11-30')
294
- Date.parse('2013-11-08').end_of_chunk(:biweek).should eq Date.parse('2013-11-17')
295
- Date.parse('2013-07-04').end_of_chunk(:week).should eq Date.parse('2013-07-07')
287
+ expect(Date.parse('2013-07-04').end_of_chunk(:year)).to eq Date.parse('2013-12-31')
288
+ expect(Date.parse('2013-07-04').end_of_chunk(:quarter)).to eq Date.parse('2013-09-30')
289
+ expect(Date.parse('2013-12-04').end_of_chunk(:bimonth)).to eq Date.parse('2013-12-31')
290
+ expect(Date.parse('2013-07-04').end_of_chunk(:month)).to eq Date.parse('2013-07-31')
291
+ expect(Date.parse('2013-11-04').end_of_chunk(:semimonth)).to eq Date.parse('2013-11-15')
292
+ expect(Date.parse('2013-11-24').end_of_chunk(:semimonth)).to eq Date.parse('2013-11-30')
293
+ expect(Date.parse('2013-11-08').end_of_chunk(:biweek)).to eq Date.parse('2013-11-17')
294
+ expect(Date.parse('2013-07-04').end_of_chunk(:week)).to eq Date.parse('2013-07-07')
296
295
  expect {
297
296
  Date.parse('2013-11-04').end_of_chunk(:wek)
298
297
  }.to raise_error
299
298
  end
300
299
 
301
300
  it "should know how to expand to chunk periods" do
302
- Date.parse('2013-07-04').expand_to_period(:year).
303
- should eq Period.new(Date.parse('2013-01-01'), Date.parse('2013-12-31'))
304
- Date.parse('2013-07-04').expand_to_period(:quarter).
305
- should eq Period.new(Date.parse('2013-07-01'), Date.parse('2013-09-30'))
306
- Date.parse('2013-07-04').expand_to_period(:bimonth).
307
- should eq Period.new(Date.parse('2013-07-01'), Date.parse('2013-08-31'))
308
- Date.parse('2013-07-04').expand_to_period(:month).
309
- should eq Period.new(Date.parse('2013-07-01'), Date.parse('2013-07-31'))
310
- Date.parse('2013-07-04').expand_to_period(:semimonth).
311
- should eq Period.new(Date.parse('2013-07-01'), Date.parse('2013-07-15'))
312
- Date.parse('2013-07-04').expand_to_period(:biweek).
313
- should eq Period.new(Date.parse('2013-07-01'), Date.parse('2013-07-14'))
314
- Date.parse('2013-07-04').expand_to_period(:week).
315
- should eq Period.new(Date.parse('2013-07-01'), Date.parse('2013-07-07'))
316
- Date.parse('2013-07-04').expand_to_period(:day).
317
- should eq Period.new(Date.parse('2013-07-04'), Date.parse('2013-07-04'))
301
+ expect(Date.parse('2013-07-04').expand_to_period(:year)).to eq Period.new('2013-01-01', '2013-12-31')
302
+ expect(Date.parse('2013-07-04').expand_to_period(:quarter)).to eq Period.new('2013-07-01', '2013-09-30')
303
+ expect(Date.parse('2013-07-04').expand_to_period(:bimonth)).to eq Period.new('2013-07-01', '2013-08-31')
304
+ expect(Date.parse('2013-07-04').expand_to_period(:month)).to eq Period.new('2013-07-01', '2013-07-31')
305
+ expect(Date.parse('2013-07-04').expand_to_period(:semimonth)).to eq Period.new('2013-07-01', '2013-07-15')
306
+ expect(Date.parse('2013-07-04').expand_to_period(:biweek)).to eq Period.new('2013-07-01', '2013-07-14')
307
+ expect(Date.parse('2013-07-04').expand_to_period(:week)).to eq Period.new('2013-07-01', '2013-07-07')
308
+ expect(Date.parse('2013-07-04').expand_to_period(:day)).to eq Period.new('2013-07-04', '2013-07-04')
318
309
  end
319
310
  end
320
311
  end