fat_core 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fat_core/period.rb +9 -0
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/date_spec.rb +158 -167
- data/spec/lib/numeric_spec.rb +9 -9
- data/spec/lib/period_spec.rb +139 -137
- data/spec/lib/range_spec.rb +53 -53
- data/spec/lib/string_spec.rb +27 -27
- data/spec/spec_helper.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ca41250c3f9b03257b33633c7bdadea6f0e1d8b
|
4
|
+
data.tar.gz: 4af0065da337d9a77211fe4ee27802842b08f0b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a031a05bae6490638d336b9552fcbac2e7537ef4593016e9ac0bdbf158e35c9226e749799310c2569574dc68bb71cffb4c037ee0d36e6f8a8fccde60ee0c5492
|
7
|
+
data.tar.gz: a63755c81cf3bae6175810301584f2f18e2afe34bb0df1667a3c3a01eb4ffd641146f15d4994f807203a6bcce31457cb6ea1bfede45a165d0652e53fd368b247
|
data/lib/fat_core/period.rb
CHANGED
@@ -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
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/date_spec.rb
CHANGED
@@ -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.
|
8
|
-
Date.
|
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').
|
24
|
-
Date.parse_spec('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').
|
29
|
-
Date.parse_spec('W23').
|
30
|
-
Date.parse_spec('W23', :to).
|
31
|
-
Date.parse_spec('23W').
|
32
|
-
Date.parse_spec('23W', :to).
|
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').
|
40
|
-
Date.parse_spec('2003-W1', :to).
|
41
|
-
Date.parse_spec('2003-W23').
|
42
|
-
Date.parse_spec('2003-W23', :to).
|
43
|
-
Date.parse_spec('2003-23W').
|
44
|
-
Date.parse_spec('2003-23W', :to).
|
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).
|
52
|
-
Date.parse_spec('2011-4Q', :to).
|
53
|
-
Date.parse_spec('2011-Q4', :from).
|
54
|
-
Date.parse_spec('2011-Q4', :to).
|
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).
|
60
|
-
Date.parse_spec('4Q', :to).
|
61
|
-
Date.parse_spec('Q4', :from).
|
62
|
-
Date.parse_spec('Q4', :to).
|
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).
|
68
|
-
Date.parse_spec('2010-5', :to).
|
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).
|
74
|
-
Date.parse_spec('10', :to).
|
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).
|
81
|
-
Date.parse_spec('2010', :to).
|
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').
|
87
|
-
Date.parse_spec('this_day').
|
88
|
-
Date.parse_spec('yesterday').
|
89
|
-
Date.parse_spec('last_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').
|
94
|
-
Date.parse_spec('this_week', :to).
|
95
|
-
Date.parse_spec('last_week').
|
96
|
-
Date.parse_spec('last_week', :to).
|
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').
|
101
|
-
Date.parse_spec('this_biweek', :to).
|
102
|
-
Date.parse_spec('last_biweek').
|
103
|
-
Date.parse_spec('last_biweek', :to).
|
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').
|
108
|
-
Date.parse_spec('this_semimonth', :to).
|
109
|
-
Date.parse_spec('last_semimonth').
|
110
|
-
Date.parse_spec('last_semimonth', :to).
|
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').
|
115
|
-
Date.parse_spec('this_month', :to).
|
116
|
-
Date.parse_spec('last_month').
|
117
|
-
Date.parse_spec('last_month', :to).
|
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').
|
122
|
-
Date.parse_spec('this_bimonth', :to).
|
123
|
-
Date.parse_spec('last_bimonth').
|
124
|
-
Date.parse_spec('last_bimonth', :to).
|
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').
|
129
|
-
Date.parse_spec('this_quarter', :to).
|
130
|
-
Date.parse_spec('last_quarter').
|
131
|
-
Date.parse_spec('last_quarter', :to).
|
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').
|
136
|
-
Date.parse_spec('this_year', :to).
|
137
|
-
Date.parse_spec('last_year').
|
138
|
-
Date.parse_spec('last_year', :to).
|
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').
|
143
|
-
Date.parse_spec('forever', :to).
|
144
|
-
Date.parse_spec('never').
|
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.
|
150
|
-
Date.parse_american('2 / 12/ 2011').iso.
|
151
|
-
Date.parse_american('2 / 1 / 2011').iso.
|
152
|
-
Date.parse_american(' 2 / 1 / 2011 ').iso.
|
153
|
-
Date.parse_american(' 2 / 1 / 15 ').iso.
|
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.
|
171
|
-
Date.today.succ.
|
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.
|
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.
|
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.
|
184
|
-
(Date.today + 1.day).org.
|
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.
|
189
|
-
(Date.today + 1.day).eng.
|
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.
|
194
|
-
Date.parse('2012-02-29').quarter.
|
195
|
-
Date.parse('2012-01-01').quarter.
|
196
|
-
Date.parse('2012-03-31').quarter.
|
197
|
-
Date.parse('2012-04-01').quarter.
|
198
|
-
Date.parse('2012-05-15').quarter.
|
199
|
-
Date.parse('2012-06-30').quarter.
|
200
|
-
Date.parse('2012-07-01').quarter.
|
201
|
-
Date.parse('2012-08-15').quarter.
|
202
|
-
Date.parse('2012-09-30').quarter.
|
203
|
-
Date.parse('2012-10-01').quarter.
|
204
|
-
Date.parse('2012-11-15').quarter.
|
205
|
-
Date.parse('2012-12-31').quarter.
|
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').
|
210
|
-
Date.parse('2013-12-31').
|
211
|
-
Date.parse('2013-04-01').
|
212
|
-
Date.parse('2013-12-30').
|
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').
|
217
|
-
Date.parse('2013-12-31').
|
218
|
-
Date.parse('2013-04-01').
|
219
|
-
Date.parse('2013-06-30').
|
220
|
-
Date.parse('2013-05-01').
|
221
|
-
Date.parse('2013-07-31').
|
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.
|
226
|
-
Date.parse('2013-11-04').end_of_bimonth.
|
227
|
-
Date.parse('2013-03-01').
|
228
|
-
Date.parse('2013-04-30').
|
229
|
-
Date.parse('2013-01-01').
|
230
|
-
Date.parse('2013-12-31').
|
231
|
-
Date.parse('2013-05-01').
|
232
|
-
Date.parse('2013-06-30').
|
233
|
-
Date.parse('2013-06-01').
|
234
|
-
Date.parse('2013-07-31').
|
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').
|
239
|
-
Date.parse('2013-12-31').
|
240
|
-
Date.parse('2013-05-01').
|
241
|
-
Date.parse('2013-07-31').
|
242
|
-
Date.parse('2013-05-02').
|
243
|
-
Date.parse('2013-07-30').
|
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.
|
248
|
-
Date.parse('2013-11-04').beginning_of_semimonth.
|
249
|
-
Date.parse('2013-11-04').end_of_semimonth.
|
250
|
-
Date.parse('2013-11-24').end_of_semimonth.
|
251
|
-
Date.parse('2013-03-01').
|
252
|
-
Date.parse('2013-03-16').
|
253
|
-
Date.parse('2013-04-15').
|
254
|
-
Date.parse('2013-04-30').
|
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.
|
259
|
-
Date.parse('2013-11-07').end_of_biweek.
|
260
|
-
Date.parse('2013-03-11').
|
261
|
-
Date.parse('2013-03-24').
|
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').
|
266
|
-
Date.parse('2013-11-10').
|
267
|
-
Date.parse('2013-12-02').
|
268
|
-
Date.parse('2013-12-08').
|
269
|
-
Date.parse('2013-10-13').
|
270
|
-
Date.parse('2013-10-19').
|
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).
|
275
|
-
Date.parse('2013-11-04').beginning_of_chunk(:quarter).
|
276
|
-
Date.parse('2013-12-04').beginning_of_chunk(:bimonth).
|
277
|
-
Date.parse('2013-11-04').beginning_of_chunk(:month).
|
278
|
-
Date.parse('2013-11-04').beginning_of_chunk(:semimonth).
|
279
|
-
Date.parse('2013-11-24').beginning_of_chunk(:semimonth).
|
280
|
-
Date.parse('2013-11-08').beginning_of_chunk(:biweek).
|
281
|
-
Date.parse('2013-11-08').beginning_of_chunk(:week).
|
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).
|
289
|
-
Date.parse('2013-07-04').end_of_chunk(:quarter).
|
290
|
-
Date.parse('2013-12-04').end_of_chunk(:bimonth).
|
291
|
-
Date.parse('2013-07-04').end_of_chunk(:month).
|
292
|
-
Date.parse('2013-11-04').end_of_chunk(:semimonth).
|
293
|
-
Date.parse('2013-11-24').end_of_chunk(:semimonth).
|
294
|
-
Date.parse('2013-11-08').end_of_chunk(:biweek).
|
295
|
-
Date.parse('2013-07-04').end_of_chunk(:week).
|
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
|
-
|
304
|
-
Date.parse('2013-07-04').expand_to_period(:
|
305
|
-
|
306
|
-
Date.parse('2013-07-04').expand_to_period(:
|
307
|
-
|
308
|
-
Date.parse('2013-07-04').expand_to_period(:
|
309
|
-
|
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
|