week_of_month 1.2.1 → 1.2.2
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.
- data/.gitignore +24 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +8 -0
- data/README.rdoc +111 -0
- data/Rakefile +10 -0
- data/lib/modules/constant.rb +41 -0
- data/lib/modules/day.rb +64 -0
- data/lib/modules/month.rb +68 -0
- data/lib/modules/week.rb +179 -0
- data/lib/modules/year.rb +24 -0
- data/lib/test/modules/test_constant.rb +63 -0
- data/lib/test/modules/test_day.rb +129 -0
- data/lib/test/modules/test_month.rb +187 -0
- data/lib/test/modules/test_week.rb +196 -0
- data/lib/test/modules/test_year.rb +17 -0
- data/lib/week_of_month.rb +12 -3
- data/week_of_month.gemspec +13 -0
- metadata +20 -7
- data/lib/test/test_week_of_month_for_date_object.rb +0 -350
- data/lib/test/test_week_of_month_for_time_object.rb +0 -350
- data/lib/week_helper.rb +0 -120
@@ -1,350 +0,0 @@
|
|
1
|
-
#!/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require_relative '../week_of_month'
|
6
|
-
|
7
|
-
class TestWeekOfMonthForTimeObject < Test::Unit::TestCase
|
8
|
-
|
9
|
-
def test_constants_present?
|
10
|
-
assert Time::WEEK_IN_ENG
|
11
|
-
|
12
|
-
assert Time::WEEK_IN_GER
|
13
|
-
|
14
|
-
assert Time::WEEK_IN_FR
|
15
|
-
|
16
|
-
assert Time::WEEK_IN_JAP
|
17
|
-
|
18
|
-
assert Time::MONTH_WITH_DAY
|
19
|
-
|
20
|
-
assert Time::MONTH_WITH_SEQUENCE
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_constants_value
|
24
|
-
assert_equal({ 1 => 'First', 2 => 'Second',
|
25
|
-
3 => 'Third', 4 => 'Fourth',
|
26
|
-
5 => 'Fifth', 6 => 'Sixth' }, Time::WEEK_IN_ENG)
|
27
|
-
|
28
|
-
assert_equal({ 1 => 'First', 2 => 'Second',
|
29
|
-
3 => 'Third', 4 => 'Quatrième',
|
30
|
-
5 => 'Cinquième', 6 => 'sixième'}, Time::WEEK_IN_FR)
|
31
|
-
|
32
|
-
assert_equal({ 1 => 'First', 2 => 'Second',
|
33
|
-
3 => 'Dritten', 4 => 'Vierte',
|
34
|
-
5 => 'Fünfte', 6 => 'Sechste'}, Time::WEEK_IN_GER)
|
35
|
-
|
36
|
-
assert_equal({ 1=>'最初', 2 =>'秒',
|
37
|
-
3 =>'サード', 4=> '第4回',
|
38
|
-
5 =>'第五',6=> 'シックス' } , Time::WEEK_IN_JAP)
|
39
|
-
|
40
|
-
assert_equal({ :january => 1, :february => 2, :march => 3,
|
41
|
-
:april => 4, :may => 5, :june => 6, :july => 7,
|
42
|
-
:august => 8, :september => 9, :october => 10,
|
43
|
-
:november => 11, :december => 12 }, Time::MONTH_WITH_SEQUENCE)
|
44
|
-
|
45
|
-
assert_equal({ :january => 31, :february => 28, :march => 31,
|
46
|
-
:april => 30, :may => 31, :june => 30, :july => 31,
|
47
|
-
:august => 31, :september => 30, :october => 31,
|
48
|
-
:november => 30, :december => 31 }, Time::MONTH_WITH_DAY)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_month?
|
52
|
-
assert Time.new(2012,1,1).january?
|
53
|
-
|
54
|
-
assert Time.new(2012,2,1).february?
|
55
|
-
|
56
|
-
assert Time.new(2012,3,1).march?
|
57
|
-
|
58
|
-
assert Time.new(2012,4,1).april?
|
59
|
-
|
60
|
-
assert Time.new(2012,5,1).may?
|
61
|
-
|
62
|
-
assert Time.new(2012,6,1).june?
|
63
|
-
|
64
|
-
assert Time.new(2012,7,1).july?
|
65
|
-
|
66
|
-
assert Time.new(2012,8,1).august?
|
67
|
-
|
68
|
-
assert Time.new(2012,9,1).september?
|
69
|
-
|
70
|
-
assert Time.new(2012,10,1).october?
|
71
|
-
|
72
|
-
assert Time.new(2012,11,1).november?
|
73
|
-
|
74
|
-
assert Time.new(2012,12,1).december?
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_week_of_month
|
78
|
-
assert_equal 5, Time.new(2012,1,31).week_of_month
|
79
|
-
|
80
|
-
assert_equal 5, Time.new(2012,2,29).week_of_month
|
81
|
-
|
82
|
-
assert_equal 5, Time.new(2012,3,31).week_of_month
|
83
|
-
|
84
|
-
assert_equal 5, Time.new(2012,4,30).week_of_month
|
85
|
-
|
86
|
-
assert_equal 5, Time.new(2012,5,31).week_of_month
|
87
|
-
|
88
|
-
assert_equal 5, Time.new(2012,6,30).week_of_month
|
89
|
-
|
90
|
-
assert_equal 5, Time.new(2012,7,31).week_of_month
|
91
|
-
|
92
|
-
assert_equal 5, Time.new(2012,8,31).week_of_month
|
93
|
-
|
94
|
-
assert_equal 6, Time.new(2012,9,30).week_of_month
|
95
|
-
|
96
|
-
assert_equal 5, Time.new(2012,10,31).week_of_month
|
97
|
-
|
98
|
-
assert_equal 5, Time.new(2012,11,30).week_of_month
|
99
|
-
|
100
|
-
assert_equal 6, Time.new(2012,12,31).week_of_month
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_last_day_of_month
|
104
|
-
assert_equal 31, Time.new(2012,1,31).last_day_of_month
|
105
|
-
|
106
|
-
assert_equal 29, Time.new(2012,2,29).last_day_of_month
|
107
|
-
|
108
|
-
assert_equal 31, Time.new(2012,3,31).last_day_of_month
|
109
|
-
|
110
|
-
assert_equal 30, Time.new(2012,4,30).last_day_of_month
|
111
|
-
|
112
|
-
assert_equal 31, Time.new(2012,5,31).last_day_of_month
|
113
|
-
|
114
|
-
assert_equal 30, Time.new(2012,6,30).last_day_of_month
|
115
|
-
|
116
|
-
assert_equal 31, Time.new(2012,7,31).last_day_of_month
|
117
|
-
|
118
|
-
assert_equal 31, Time.new(2012,8,31).last_day_of_month
|
119
|
-
|
120
|
-
assert_equal 30, Time.new(2012,9,30).last_day_of_month
|
121
|
-
|
122
|
-
assert_equal 31, Time.new(2012,10,31).last_day_of_month
|
123
|
-
|
124
|
-
assert_equal 30, Time.new(2012,11,30).last_day_of_month
|
125
|
-
|
126
|
-
assert_equal 31, Time.new(2012,12,31).last_day_of_month
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_end_of_month
|
130
|
-
assert_equal Time.new(2012,1,31), Time.new(2012,1,1).end_of_month
|
131
|
-
|
132
|
-
assert_equal Time.new(2012,2,29), Time.new(2012,2,2).end_of_month
|
133
|
-
|
134
|
-
assert_equal Time.new(2012,3,31), Time.new(2012,3,1).end_of_month
|
135
|
-
|
136
|
-
assert_equal Time.new(2012,4,30), Time.new(2012,4,3).end_of_month
|
137
|
-
|
138
|
-
assert_equal Time.new(2012,5,31), Time.new(2012,5,1).end_of_month
|
139
|
-
|
140
|
-
assert_equal Time.new(2012,6,30), Time.new(2012,6,30).end_of_month
|
141
|
-
|
142
|
-
assert_equal Time.new(2012,7,31), Time.new(2012,7,1).end_of_month
|
143
|
-
|
144
|
-
assert_equal Time.new(2012,8,31), Time.new(2012,8,5).end_of_month
|
145
|
-
|
146
|
-
assert_equal Time.new(2012,9,30), Time.new(2012,9,2).end_of_month
|
147
|
-
|
148
|
-
assert_equal Time.new(2012,10,31), Time.new(2012,10,22).end_of_month
|
149
|
-
|
150
|
-
assert_equal Time.new(2012,11,30), Time.new(2012,11,10).end_of_month
|
151
|
-
|
152
|
-
assert_equal Time.new(2012,12,31), Time.new(2012,12,15).end_of_month
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_beginning_of_month
|
156
|
-
assert_equal Time.new(2012,1,1), Time.new(2012,1,31).beginning_of_month
|
157
|
-
|
158
|
-
assert_equal Time.new(2012,2,1), Time.new(2012,2,29).beginning_of_month
|
159
|
-
|
160
|
-
assert_equal Time.new(2012,3,1), Time.new(2012,3,31).beginning_of_month
|
161
|
-
|
162
|
-
assert_equal Time.new(2012,4,1), Time.new(2012,4,30).beginning_of_month
|
163
|
-
|
164
|
-
assert_equal Time.new(2012,5,1), Time.new(2012,5,31).beginning_of_month
|
165
|
-
|
166
|
-
assert_equal Time.new(2012,6,1), Time.new(2012,6,30).beginning_of_month
|
167
|
-
|
168
|
-
assert_equal Time.new(2012,7,1), Time.new(2012,7,31).beginning_of_month
|
169
|
-
|
170
|
-
assert_equal Time.new(2012,8,1), Time.new(2012,8,31).beginning_of_month
|
171
|
-
|
172
|
-
assert_equal Time.new(2012,9,1), Time.new(2012,9,30).beginning_of_month
|
173
|
-
|
174
|
-
assert_equal Time.new(2012,10,1), Time.new(2012,10,31).beginning_of_month
|
175
|
-
|
176
|
-
assert_equal Time.new(2012,11,1), Time.new(2012,11,30).beginning_of_month
|
177
|
-
|
178
|
-
assert_equal Time.new(2012,12,1), Time.new(2012,12,31).beginning_of_month
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_days_array
|
182
|
-
time = Time.new(2012,2,8)
|
183
|
-
days_array_for_february = [nil, nil, nil, 1, 2, 3, 4, 5,
|
184
|
-
6, 7, 8, 9, 10, 11, 12, 13, 14,
|
185
|
-
15, 16, 17, 18, 19, 20, 21, 22,
|
186
|
-
23, 24, 25, 26, 27, 28, 29]
|
187
|
-
assert_kind_of Array,time.days_array
|
188
|
-
assert_equal days_array_for_february, time.days_array
|
189
|
-
|
190
|
-
time = Time.new(2012,7,1)
|
191
|
-
days_array_for_july = [1, 2, 3, 4, 5, 6, 7,
|
192
|
-
8, 9, 10, 11, 12, 13,
|
193
|
-
14, 15, 16, 17, 18, 19,
|
194
|
-
20, 21, 22, 23, 24, 25,
|
195
|
-
26, 27, 28, 29, 30, 31]
|
196
|
-
assert_kind_of Array,time.days_array
|
197
|
-
assert_equal days_array_for_july, time.days_array
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_week_split
|
201
|
-
time = Time.new(2012,1,10)
|
202
|
-
split_for_january = [[1, 2, 3, 4, 5, 6, 7],
|
203
|
-
[8, 9, 10, 11, 12, 13, 14],
|
204
|
-
[15, 16, 17, 18, 19, 20, 21],
|
205
|
-
[22, 23, 24, 25, 26, 27, 28],
|
206
|
-
[29, 30, 31]]
|
207
|
-
assert_kind_of Array, time.week_split
|
208
|
-
assert_equal split_for_january, time.week_split
|
209
|
-
|
210
|
-
time = Time.new(2012,10,15)
|
211
|
-
split_for_october = [[nil, 1, 2, 3, 4, 5, 6],
|
212
|
-
[7, 8, 9, 10, 11, 12, 13],
|
213
|
-
[14, 15, 16, 17, 18, 19, 20],
|
214
|
-
[21, 22, 23, 24, 25, 26, 27],
|
215
|
-
[28, 29, 30, 31]]
|
216
|
-
assert_kind_of Array, time.week_split
|
217
|
-
assert_equal split_for_october, time.week_split
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_first_week?
|
221
|
-
assert Time.new(2012,1,1).first_week?
|
222
|
-
assert !Time.new(2012,1,31).first_week?
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_second_week?
|
226
|
-
assert Time.new(2012,10,9).second_week?
|
227
|
-
assert !Time.new(2012,10,20).second_week?
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_last_week?
|
231
|
-
assert Time.new(2012,10,31).last_week?
|
232
|
-
assert !Time.new(2012,10,20).last_week?
|
233
|
-
end
|
234
|
-
|
235
|
-
def test_total_weeks
|
236
|
-
assert_equal 5, Time.new(2012,10,31).total_weeks
|
237
|
-
assert_equal 6, Time.new(2012,12,20).total_weeks
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_week_of_month_in_eng
|
241
|
-
assert_equal 'First', Time.new(2012,12,1).week_of_month_in_eng
|
242
|
-
assert_equal 'Second', Time.new(2012,12,4).week_of_month_in_eng
|
243
|
-
assert_equal 'Third', Time.new(2012,12,9).week_of_month_in_eng
|
244
|
-
assert_equal 'Fourth', Time.new(2012,12,16).week_of_month_in_eng
|
245
|
-
assert_equal 'Fifth', Time.new(2012,12,24).week_of_month_in_eng
|
246
|
-
assert_equal 'Sixth', Time.new(2012,12,31).week_of_month_in_eng
|
247
|
-
end
|
248
|
-
|
249
|
-
def test_week_of_month_in_fr
|
250
|
-
assert_equal 'First', Time.new(2012,12,1).week_of_month_in_fr
|
251
|
-
assert_equal 'Second', Time.new(2012,12,4).week_of_month_in_fr
|
252
|
-
assert_equal 'Third', Time.new(2012,12,9).week_of_month_in_fr
|
253
|
-
assert_equal 'Quatrième', Time.new(2012,12,16).week_of_month_in_fr
|
254
|
-
assert_equal 'Cinquième', Time.new(2012,12,24).week_of_month_in_fr
|
255
|
-
assert_equal 'sixième', Time.new(2012,12,31).week_of_month_in_fr
|
256
|
-
end
|
257
|
-
|
258
|
-
def test_week_of_month_in_ger
|
259
|
-
assert_equal 'First', Time.new(2012,12,1).week_of_month_in_ger
|
260
|
-
assert_equal 'Second', Time.new(2012,12,4).week_of_month_in_ger
|
261
|
-
assert_equal 'Dritten', Time.new(2012,12,9).week_of_month_in_ger
|
262
|
-
assert_equal 'Vierte', Time.new(2012,12,16).week_of_month_in_ger
|
263
|
-
assert_equal 'Fünfte', Time.new(2012,12,24).week_of_month_in_ger
|
264
|
-
assert_equal 'Sechste', Time.new(2012,12,31).week_of_month_in_ger
|
265
|
-
end
|
266
|
-
|
267
|
-
def test_week_of_month_in_jap
|
268
|
-
assert_equal '最初', Time.new(2012,12,1).week_of_month_in_jap
|
269
|
-
assert_equal '秒', Time.new(2012,12,4).week_of_month_in_jap
|
270
|
-
assert_equal 'サード', Time.new(2012,12,9).week_of_month_in_jap
|
271
|
-
assert_equal '第4回', Time.new(2012,12,16).week_of_month_in_jap
|
272
|
-
assert_equal '第五', Time.new(2012,12,24).week_of_month_in_jap
|
273
|
-
assert_equal 'シックス', Time.new(2012,12,31).week_of_month_in_jap
|
274
|
-
end
|
275
|
-
|
276
|
-
def test_name_of_week_day
|
277
|
-
assert_equal "Saturday", Time.new(2012,12,1).name_of_week_day
|
278
|
-
assert_equal "Sunday", Time.new(2012,12,2).name_of_week_day
|
279
|
-
assert_equal "Monday", Time.new(2012,12,3).name_of_week_day
|
280
|
-
assert_equal "Tuesday", Time.new(2012,12,4).name_of_week_day
|
281
|
-
assert_equal "Wednesday", Time.new(2012,12,5).name_of_week_day
|
282
|
-
assert_equal "Thursday", Time.new(2012,12,6).name_of_week_day
|
283
|
-
assert_equal "Friday", Time.new(2012,12,7).name_of_week_day
|
284
|
-
end
|
285
|
-
|
286
|
-
def test_name_of_month
|
287
|
-
assert_equal "January", Time.new(2012,1,1).name_of_month
|
288
|
-
assert_equal "February", Time.new(2012,2,1).name_of_month
|
289
|
-
assert_equal "March", Time.new(2012,3,1).name_of_month
|
290
|
-
assert_equal "April", Time.new(2012,4,1).name_of_month
|
291
|
-
assert_equal "May", Time.new(2012,5,1).name_of_month
|
292
|
-
assert_equal "June", Time.new(2012,6,1).name_of_month
|
293
|
-
assert_equal "July", Time.new(2012,7,1).name_of_month
|
294
|
-
assert_equal "August", Time.new(2012,8,1).name_of_month
|
295
|
-
assert_equal "September", Time.new(2012,9,1).name_of_month
|
296
|
-
assert_equal "October", Time.new(2012,10,1).name_of_month
|
297
|
-
assert_equal "November", Time.new(2012,11,1).name_of_month
|
298
|
-
assert_equal "December", Time.new(2012,12,1).name_of_month
|
299
|
-
end
|
300
|
-
|
301
|
-
def test_week_end?
|
302
|
-
assert !Time.new(2012,10,1).week_end?
|
303
|
-
assert !Time.new(2012,10,31).week_end?
|
304
|
-
assert Time.new(2012,10,6).week_end?
|
305
|
-
assert Time.new(2012,10,7).week_end?
|
306
|
-
end
|
307
|
-
|
308
|
-
def test_working_day?
|
309
|
-
assert Time.new(2012,10,1).working_day?
|
310
|
-
assert Time.new(2012,10,31).working_day?
|
311
|
-
assert !Time.new(2012,10,6).working_day?
|
312
|
-
assert !Time.new(2012,10,7).working_day?
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_all_sundays_in_month
|
316
|
-
assert_equal [2, 9, 16, 23, 30], Time.new(2012,12,1).all_sundays_in_month
|
317
|
-
assert_equal [7, 14, 21, 28], Time.new(2012,10,1).all_sundays_in_month
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_all_mondays_in_month
|
321
|
-
assert_equal [3, 10, 17, 24, 31], Time.new(2012,12,1).all_mondays_in_month
|
322
|
-
assert_equal [1, 8, 15, 22, 29], Time.new(2012,10,1).all_mondays_in_month
|
323
|
-
end
|
324
|
-
|
325
|
-
def test_all_tuesdays_in_month
|
326
|
-
assert_equal [4, 11, 18, 25], Time.new(2012,12,1).all_tuesdays_in_month
|
327
|
-
assert_equal [2, 9, 16, 23, 30], Time.new(2012,10,1).all_tuesdays_in_month
|
328
|
-
end
|
329
|
-
|
330
|
-
def test_all_wednesdays_in_month
|
331
|
-
assert_equal [5, 12, 19, 26], Time.new(2012,12,1).all_wednesdays_in_month
|
332
|
-
assert_equal [3, 10, 17, 24, 31], Time.new(2012,10,1).all_wednesdays_in_month
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_all_thursdays_in_month
|
336
|
-
assert_equal [6, 13, 20, 27], Time.new(2012,12,1).all_thursdays_in_month
|
337
|
-
assert_equal [4, 11, 18, 25], Time.new(2012,10,1).all_thursdays_in_month
|
338
|
-
end
|
339
|
-
|
340
|
-
def test_all_fridays_in_month
|
341
|
-
assert_equal [7, 14, 21, 28], Time.new(2012,12,1).all_fridays_in_month
|
342
|
-
assert_equal [5, 12, 19, 26], Time.new(2012,10,1).all_fridays_in_month
|
343
|
-
end
|
344
|
-
|
345
|
-
def test_all_saturdays_in_month
|
346
|
-
assert_equal [1, 8, 15, 22, 29], Time.new(2012,12,1).all_saturdays_in_month
|
347
|
-
assert_equal [6, 13, 20, 27], Time.new(2012,10,1).all_saturdays_in_month
|
348
|
-
end
|
349
|
-
|
350
|
-
end
|
data/lib/week_helper.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
#!/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
module WeekHelper
|
5
|
-
|
6
|
-
WEEK_IN_ENG = { 1 => 'First', 2 => 'Second',
|
7
|
-
3 => 'Third', 4 => 'Fourth',
|
8
|
-
5 => 'Fifth', 6 => 'Sixth' }
|
9
|
-
|
10
|
-
WEEK_IN_FR = { 1 => 'First', 2 => 'Second',
|
11
|
-
3 => 'Third', 4 => 'Quatrième',
|
12
|
-
5 => 'Cinquième', 6 => 'sixième'}
|
13
|
-
|
14
|
-
WEEK_IN_GER = { 1 => 'First', 2 => 'Second',
|
15
|
-
3 => 'Dritten', 4 => 'Vierte',
|
16
|
-
5 => 'Fünfte', 6 => 'Sechste'}
|
17
|
-
|
18
|
-
WEEK_IN_JAP = { 1=>'最初', 2 =>'秒',
|
19
|
-
3 =>'サード', 4=> '第4回',
|
20
|
-
5 =>'第五',6=> 'シックス' }
|
21
|
-
|
22
|
-
MONTH_WITH_DAY = { :january => 31, :february => 28, :march => 31,
|
23
|
-
:april => 30, :may => 31, :june => 30, :july => 31,
|
24
|
-
:august => 31, :september => 30, :october => 31,
|
25
|
-
:november => 30, :december => 31 }
|
26
|
-
|
27
|
-
MONTH_WITH_SEQUENCE = { :january => 1, :february => 2, :march => 3,
|
28
|
-
:april => 4, :may => 5, :june => 6, :july => 7,
|
29
|
-
:august => 8, :september => 9, :october => 10,
|
30
|
-
:november => 11, :december => 12 }
|
31
|
-
|
32
|
-
|
33
|
-
MONTH_WITH_DAY.keys.each do |month_name|
|
34
|
-
define_method((month_name.to_s + '?').to_sym) do
|
35
|
-
MONTH_WITH_SEQUENCE[month_name] == month
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def last_day_of_month
|
40
|
-
if leap? && february?
|
41
|
-
29
|
42
|
-
else
|
43
|
-
MONTH_WITH_DAY[MONTH_WITH_SEQUENCE.key(month)]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def end_of_month
|
48
|
-
self.class.new(year,month,last_day_of_month)
|
49
|
-
end
|
50
|
-
|
51
|
-
def beginning_of_month
|
52
|
-
self.class.new(year,month,1)
|
53
|
-
end
|
54
|
-
|
55
|
-
def days_array
|
56
|
-
day = self.beginning_of_month.wday
|
57
|
-
array = []
|
58
|
-
array[day] = 1
|
59
|
-
(2..self.end_of_month.mday).each {|i| array << i }
|
60
|
-
array
|
61
|
-
end
|
62
|
-
|
63
|
-
def week_split
|
64
|
-
days_array.each_slice(7).to_a
|
65
|
-
end
|
66
|
-
|
67
|
-
def week_of_month
|
68
|
-
week_split.each_with_index do |o,i|
|
69
|
-
return (i + 1) if o.include?(self.day)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def first_week?
|
74
|
-
week_split[0].include?((self.day))
|
75
|
-
end
|
76
|
-
|
77
|
-
def second_week?
|
78
|
-
week_split[1].include?((self.day))
|
79
|
-
end
|
80
|
-
|
81
|
-
def last_week?
|
82
|
-
week_split.last.include?((self.day))
|
83
|
-
end
|
84
|
-
|
85
|
-
def total_weeks
|
86
|
-
week_split.size
|
87
|
-
end
|
88
|
-
|
89
|
-
['eng', 'fr', 'ger', 'jap'].each do |lang|
|
90
|
-
method_name = "week_of_month_in_#{lang}"
|
91
|
-
define_method(method_name) do
|
92
|
-
eval "WEEK_IN_#{lang.upcase}[week_of_month]"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def name_of_week_day
|
97
|
-
self.class.new(year,month,day).strftime('%A')
|
98
|
-
end
|
99
|
-
|
100
|
-
def name_of_month
|
101
|
-
self.class.new(year,month,day).strftime('%B')
|
102
|
-
end
|
103
|
-
|
104
|
-
def week_end?
|
105
|
-
saturday? || sunday?
|
106
|
-
end
|
107
|
-
|
108
|
-
def working_day?
|
109
|
-
!week_end?
|
110
|
-
end
|
111
|
-
|
112
|
-
Date::DAYNAMES.each_with_index do |day_name, i|
|
113
|
-
method_name = "all_#{day_name.downcase}s_in_month".to_sym
|
114
|
-
define_method(method_name) do
|
115
|
-
week_split.map{|d| d[i] }.compact
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|