shifty_week 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -0
- data/Rakefile +10 -3
- data/VERSION +1 -1
- data/init.rb +1 -1
- data/lib/shifty_week.rb +10 -9
- data/lib/shifty_week/date.rb +3 -10
- data/test/date_test.rb +1 -0
- data/test/shifty_week_test.rb +97 -165
- data/test/test_helper.rb +1 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
Description in ShiftyWeek[link:classes/ShiftyWeek.html]
|
4
4
|
|
5
|
+
== Quick Intro
|
6
|
+
|
7
|
+
n = DateTime.now
|
8
|
+
n.week_day_start = 'Wednesday'
|
9
|
+
n.week_days # => [2009-11-04T00:16:27-08:00, 2009-11-05T00:16:27-08:00, 2009-11-06T00:16:27-08:00, 2009-11-07T00:16:27-08:00, 2009-11-08T00:16:27-08:00, 2009-11-09T00:16:27-08:00, 2009-11-10T00:16:27-08:00]
|
10
|
+
|
11
|
+
|
12
|
+
== Installation
|
13
|
+
|
14
|
+
1. Require the gem
|
15
|
+
2. Require the libs:
|
16
|
+
|
17
|
+
shifty_week
|
18
|
+
shifty_week/time
|
19
|
+
shifty_week/date
|
20
|
+
|
5
21
|
== Note on Patches/Pull Requests
|
6
22
|
|
7
23
|
* Fork the project.
|
data/Rakefile
CHANGED
@@ -6,15 +6,22 @@ begin
|
|
6
6
|
require 'jeweler'
|
7
7
|
Jeweler::Tasks.new do |gem|
|
8
8
|
gem.name = "shifty_week"
|
9
|
-
gem.summary =
|
10
|
-
gem.description =
|
9
|
+
gem.summary = %q{Calculate dates based on a configurable first day of the week.}
|
10
|
+
gem.description = %q{Calculate dates based on a configurable first day of the week. If you want
|
11
|
+
the first day of the week to be Wednesday and the current calendar Year-Month are 2009-10,
|
12
|
+
DateTime#week_days will return an array of DateTime objects which when formatted with "%Y-%m-%d %a" look like
|
13
|
+
["2009-10-14 Wed", "2009-10-15 Thu", "2009-10-16 Fri", "2009-10-17 Sat", "2009-10-18 Sun", "2009-10-19 Mon", "2009-10-20 Tue"] }
|
11
14
|
gem.email = "frogstarr78@gmail.com"
|
12
15
|
gem.homepage = "http://github.com/frogstarr78/shifty_week"
|
13
16
|
gem.authors = ["Scott Noel-Hemming"]
|
14
17
|
gem.rdoc_options << '--main' << 'ShiftyWeek' << '--line-numbers'
|
18
|
+
gem.rubyforge_project = "shifty-week"
|
15
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
20
|
end
|
17
21
|
Jeweler::GemcutterTasks.new
|
22
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
23
|
+
rubyforge.doc_task = "rdoc"
|
24
|
+
end
|
18
25
|
rescue LoadError
|
19
26
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
27
|
end
|
@@ -42,7 +49,7 @@ end
|
|
42
49
|
task :test => :check_dependencies
|
43
50
|
|
44
51
|
begin
|
45
|
-
require 'reek/rake_task'
|
52
|
+
require 'reek/adapters/rake_task'
|
46
53
|
Reek::RakeTask.new do |t|
|
47
54
|
t.fail_on_error = true
|
48
55
|
t.verbose = false
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/init.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'time'
|
4
4
|
require 'date'
|
5
5
|
|
6
|
-
root_dir = File.dirname(__FILE__)
|
6
|
+
root_dir = File.expand_path(File.dirname(__FILE__))
|
7
7
|
require File.join(root_dir, 'lib', 'shifty_week')
|
8
8
|
require File.join(root_dir, 'lib', 'shifty_week', 'time')
|
9
9
|
require File.join(root_dir, 'lib', 'shifty_week', 'date')
|
data/lib/shifty_week.rb
CHANGED
@@ -30,6 +30,7 @@
|
|
30
30
|
# 28 29 30 31
|
31
31
|
|
32
32
|
module ShiftyWeek
|
33
|
+
WORKER_FORMAT = "%Y-%m-%d %H:%M:%S"
|
33
34
|
class Constants # :nodoc:
|
34
35
|
SUMMARY = %q{Calculate dates based on a configurable first day of the week.}
|
35
36
|
DESCRIPTION = %q{Calculate dates based on a configurable first day of the week. If you want
|
@@ -58,9 +59,9 @@ module ShiftyWeek
|
|
58
59
|
Time.send("month_days", self.year, self.month)
|
59
60
|
end
|
60
61
|
|
61
|
-
#
|
62
|
+
# Calculate the number of weeks in a year taking into account "shifted" weeks
|
62
63
|
def weeks_in_year
|
63
|
-
return (self-(self.yday-1)).wday == 6 ? 54 : 53
|
64
|
+
return (self-(self.yday-1)).wday == 6 && self.leap? ? 54 : 53
|
64
65
|
end
|
65
66
|
|
66
67
|
# Get the offset of this object's date, to the first day of the week.
|
@@ -84,8 +85,8 @@ module ShiftyWeek
|
|
84
85
|
working_date.week_day_start = self.week_day_start
|
85
86
|
working_date = (working_date-working_date.send("wday_offset"))
|
86
87
|
week_num = 0
|
87
|
-
working_date.step(self) { |
|
88
|
-
if
|
88
|
+
working_date.step(self) { |a_day|
|
89
|
+
if a_day.wday == _week_day_numbers.first
|
89
90
|
week_num += 1
|
90
91
|
end
|
91
92
|
}
|
@@ -108,12 +109,12 @@ module ShiftyWeek
|
|
108
109
|
def week_days(options={}, &block)
|
109
110
|
start_date = self
|
110
111
|
result = []
|
111
|
-
(start_date-wday_offset).step 7 do |
|
112
|
-
|
112
|
+
(start_date-wday_offset).step 7 do |a_day|
|
113
|
+
a_day.week_day_start = self.week_day_start
|
113
114
|
if block_given?
|
114
|
-
yield
|
115
|
+
yield a_day
|
115
116
|
else
|
116
|
-
|
117
|
+
result.push(a_day)
|
117
118
|
end
|
118
119
|
end
|
119
120
|
result
|
@@ -135,7 +136,7 @@ module ShiftyWeek
|
|
135
136
|
# Hopefully the name explains what this method does
|
136
137
|
def step_to_month_end step = 1
|
137
138
|
days_in_month = self.days_in_month
|
138
|
-
days_in_month += self.wday_offset if
|
139
|
+
days_in_month += self.wday_offset if days_in_month%(7*4) >= 0
|
139
140
|
self.step(days_in_month, step) do |date|
|
140
141
|
date.week_day_start = self.week_day_start
|
141
142
|
yield date
|
data/lib/shifty_week/date.rb
CHANGED
@@ -2,13 +2,6 @@ class Date
|
|
2
2
|
include ShiftyWeek
|
3
3
|
attr_writer :week_day_start
|
4
4
|
|
5
|
-
alias_method :'weekless_>>', :'>>'
|
6
|
-
def >> int
|
7
|
-
new_day = send(:'weekless_>>', int)
|
8
|
-
new_day.week_day_start = self.week_day_start
|
9
|
-
new_day
|
10
|
-
end
|
11
|
-
|
12
5
|
alias_method :step_to_date, :step #:nodoc:
|
13
6
|
# Seemed to make more sense to me to have step accept an integer number
|
14
7
|
# see step_to_date for previous behavior. Although, you can still pass
|
@@ -19,9 +12,9 @@ class Date
|
|
19
12
|
limit = (self + limit)-1
|
20
13
|
method = 'step'
|
21
14
|
end
|
22
|
-
send(method, limit, step) {|
|
23
|
-
|
24
|
-
yield
|
15
|
+
send(method, limit, step) {|a_day|
|
16
|
+
a_day.week_day_start = self.week_day_start
|
17
|
+
yield a_day
|
25
18
|
}
|
26
19
|
end
|
27
20
|
end
|
data/test/date_test.rb
CHANGED
data/test/shifty_week_test.rb
CHANGED
@@ -1,63 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ShiftyWeekTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
month_starts = [
|
6
|
-
%w(Su Mo Tu We Th Fr Sa
|
7
|
-
\ \ 1 2 3 4 5
|
8
|
-
6 7 8 9 10 11 12
|
9
|
-
13 14 15 16 17 18 19
|
10
|
-
20 21 22 23 24 25 26
|
11
|
-
27 28 29 30 31),
|
12
|
-
|
13
|
-
%w(Mo Tu We Th Fr Sa Su
|
14
|
-
\ 1 2 3 4 5 6
|
15
|
-
7 8 9 10 11 12 13
|
16
|
-
14 15 16 17 18 19 20
|
17
|
-
21 22 23 24 25 26 27
|
18
|
-
28 29 30 31),
|
19
|
-
|
20
|
-
%w(Tu We Th Fr Sa Su Mo
|
21
|
-
1 2 3 4 5 6 7
|
22
|
-
8 9 10 11 12 13 14
|
23
|
-
15 16 17 18 19 20 21
|
24
|
-
22 23 24 25 26 27 28
|
25
|
-
29 30 31),
|
26
|
-
|
27
|
-
%w(We Th Fr Sa Su Mo Tu
|
28
|
-
\ \ \ \ \ \ 1
|
29
|
-
2 3 4 5 6 7 8
|
30
|
-
9 10 11 12 13 14 15
|
31
|
-
16 17 18 19 20 21 22
|
32
|
-
23 24 25 26 27 28 29
|
33
|
-
30 31),
|
34
|
-
|
35
|
-
%w(Th Fr Sa Su Mo Tu We
|
36
|
-
\ \ \ \ \ 1 2
|
37
|
-
3 4 5 6 7 8 9
|
38
|
-
10 11 12 13 14 15 16
|
39
|
-
17 18 19 20 21 22 23
|
40
|
-
24 25 26 27 28 29 30
|
41
|
-
31),
|
42
|
-
|
43
|
-
%w(Fr Sa Su Mo Tu We Th
|
44
|
-
\ \ \ \ 1 2 3
|
45
|
-
4 5 6 7 8 9 10
|
46
|
-
11 12 13 14 15 16 17
|
47
|
-
18 19 20 21 22 23 24
|
48
|
-
25 26 27 28 29 30 31),
|
49
|
-
|
50
|
-
%w(Sa Su Mo Tu We Th Fr
|
51
|
-
\ \ \ 1 2 3 4
|
52
|
-
5 6 7 8 9 10 11
|
53
|
-
12 13 14 15 16 17 18
|
54
|
-
19 20 21 22 23 24 25
|
55
|
-
26 27 28 29 30 31)
|
56
|
-
]
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_week
|
60
|
-
|
4
|
+
def test_week_control
|
61
5
|
date = DateTime.new(2008, 1, 6)
|
62
6
|
assert_equal(0, date.send("wday_offset"))
|
63
7
|
assert_equal(2, date.week, "week #{date.week} on date #{date.to_s} != 2")
|
@@ -65,7 +9,9 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
65
9
|
date = date-1
|
66
10
|
assert_equal(6, date.send("wday_offset"))
|
67
11
|
assert_equal(1, date.week, "week #{date.week} on date #{date.to_s} != 2")
|
12
|
+
end
|
68
13
|
|
14
|
+
def test_week_expected_for_a_few_years
|
69
15
|
years_days = {
|
70
16
|
2000 => 2,
|
71
17
|
2001 => 7,
|
@@ -81,7 +27,9 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
81
27
|
date = DateTime.new(year, 1, day)
|
82
28
|
assert_equal(2, date.week, "week #{date.week} on date #{date.to_s} != 1")
|
83
29
|
}
|
30
|
+
end
|
84
31
|
|
32
|
+
def test_week_changes_calculate_correctly
|
85
33
|
date = DateTime.new(2008, 1, 3)
|
86
34
|
date.week_day_start = 'Wed'
|
87
35
|
assert_equal(1, date.send("wday_offset"))
|
@@ -98,7 +46,9 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
98
46
|
assert_equal(6, date.send("wday_offset"))
|
99
47
|
assert_equal("2008-01-01", date.strftime("%Y-%m-%d"))
|
100
48
|
assert_equal(1, date.week, "week #{date.week} on date #{date.to_s} != 1 with wday_start #{date.week_day_start}")
|
49
|
+
end
|
101
50
|
|
51
|
+
def test_week
|
102
52
|
date = DateTime.new(2007)
|
103
53
|
date.week_day_start = 'Sunday'
|
104
54
|
assert_equal(1, date.week, "week #{date.week} on date #{date.to_s} != 1")
|
@@ -108,74 +58,21 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
108
58
|
date = (date+7)
|
109
59
|
# date = DateTime.new(2007, 9, 1)
|
110
60
|
assert_equal(35, date.week, "week #{date.week} on date #{date.to_s} != 35")
|
61
|
+
end
|
111
62
|
|
112
|
-
|
113
|
-
|
114
|
-
1999 => 53,
|
115
|
-
2000 => 54,
|
116
|
-
2001 => 53,
|
117
|
-
2002 => 53,
|
118
|
-
2003 => 53,
|
119
|
-
2004 => 53,
|
120
|
-
2005 => 53,
|
121
|
-
2006 => 53,
|
122
|
-
2007 => 53,
|
123
|
-
2008 => 53,
|
124
|
-
2009 => 53,
|
125
|
-
2010 => 53,
|
126
|
-
2011 => 53,
|
127
|
-
2012 => 53,
|
128
|
-
2013 => 53,
|
129
|
-
2014 => 53,
|
130
|
-
2015 => 53,
|
131
|
-
2016 => 53,
|
132
|
-
}.each { |year, weeks|
|
63
|
+
def test_week_gets_correct_last_week_number
|
64
|
+
years_days_to_test.each { |year, weeks|
|
133
65
|
date = DateTime.new(year, 12, 31)
|
134
|
-
assert_equal(
|
66
|
+
assert_equal(date.weeks_in_year, date.week, "week #{date.week} in year #{year} != 1")
|
135
67
|
}
|
68
|
+
end
|
136
69
|
|
137
|
-
|
70
|
+
def test_expected_week_one_regardless_of_year
|
71
|
+
(2000..2006).each do |year|
|
138
72
|
day = 1
|
139
|
-
|
140
|
-
|
141
|
-
# end
|
73
|
+
date = DateTime.new(year, 1, day)
|
74
|
+
assert_equal(1, date.week, "week #{date.week} on date #{date.to_s} != 1")
|
142
75
|
end
|
143
|
-
|
144
|
-
# date = DateTime.new(2003, 1, 1)
|
145
|
-
# week = date.week(4)
|
146
|
-
# assert_equal(week, 1, "week #{week} on date #{date.to_s} != 1")
|
147
|
-
# date = DateTime.new(2003, 1, 2)
|
148
|
-
# week = date.week(4)
|
149
|
-
# assert_equal(week, 2, "week #{week} on date #{date.to_s} != 2")
|
150
|
-
# week = date.week(10)
|
151
|
-
# assert_equal(week, 2, "week #{week} on date #{date.to_s} != 2")
|
152
|
-
# date = DateTime.new(2003, 1, 3)
|
153
|
-
# week = date.week(4)
|
154
|
-
# assert_equal(week, 2, "week #{week} on date #{date.to_s} != 2")
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_weeks_in_year
|
158
|
-
years_days = {
|
159
|
-
2000 => 54,
|
160
|
-
2001 => 53,
|
161
|
-
2002 => 53,
|
162
|
-
2003 => 53,
|
163
|
-
2004 => 53,
|
164
|
-
2005 => 54,
|
165
|
-
2006 => 53,
|
166
|
-
2007 => 53,
|
167
|
-
2008 => 53,
|
168
|
-
2009 => 53,
|
169
|
-
2010 => 53,
|
170
|
-
2011 => 54,
|
171
|
-
2012 => 53,
|
172
|
-
2013 => 53,
|
173
|
-
2014 => 53,
|
174
|
-
2015 => 53,
|
175
|
-
}.each { |year, weeks|
|
176
|
-
date = DateTime.new(year, 12, 31)
|
177
|
-
assert_equal weeks, date.weeks_in_year, "week #{date.week} on date #{date.to_s} != 1"
|
178
|
-
}
|
179
76
|
end
|
180
77
|
|
181
78
|
def test_wday_offset
|
@@ -187,7 +84,7 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
187
84
|
}
|
188
85
|
end
|
189
86
|
|
190
|
-
def
|
87
|
+
def test_week_days_control
|
191
88
|
date = DateTime.new(2007)
|
192
89
|
assert_equal([
|
193
90
|
DateTime.new(2006, 12, 31).to_s,
|
@@ -200,6 +97,9 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
200
97
|
],
|
201
98
|
date.week_days.collect {|date| date.to_s}
|
202
99
|
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_week_days_span_month_and_year_boundary_with_configured_week_day_start
|
203
103
|
date = DateTime.new(2007)
|
204
104
|
date.week_day_start = 'Saturday'
|
205
105
|
assert_equal([
|
@@ -212,7 +112,9 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
212
112
|
DateTime.new(2007, 1, 5).to_s,
|
213
113
|
], date.week_days.collect {|date| date.to_s}
|
214
114
|
)
|
115
|
+
end
|
215
116
|
|
117
|
+
def test_week_days_dont_span_month_and_year_boundary_and_leap_year_because_of_configured_week_day_start
|
216
118
|
date = DateTime.new(2008)
|
217
119
|
date.week_day_start = 'Tue'
|
218
120
|
assert_equal([
|
@@ -225,6 +127,9 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
225
127
|
DateTime.new(2008, 1, 7).to_s,
|
226
128
|
], date.week_days.collect {|date| date.to_s}
|
227
129
|
)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_week_days_span_month_and_year_boundary_and_leap_year_because_of_configured_week_day_start
|
228
133
|
date = DateTime.new(2008)
|
229
134
|
date.week_day_start = 'Wed'
|
230
135
|
assert_equal([
|
@@ -237,9 +142,10 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
237
142
|
DateTime.new(2008, 1, 1).to_s,
|
238
143
|
], date.week_days.collect {|date| date.to_s}
|
239
144
|
)
|
145
|
+
end
|
240
146
|
|
241
|
-
|
242
|
-
|
147
|
+
def test_week_days_span_month_and_year_boundary_non_leap_year_with_non_configured_week_day_start
|
148
|
+
date = DateTime.new(2003)
|
243
149
|
assert_equal([
|
244
150
|
DateTime.new(2002, 12, 29).to_s,
|
245
151
|
DateTime.new(2002, 12, 30).to_s,
|
@@ -251,57 +157,59 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
251
157
|
],
|
252
158
|
date.week_days.collect {|date| date.to_s}
|
253
159
|
)
|
160
|
+
end
|
161
|
+
|
162
|
+
def unshifted_week_spanning_month_and_year
|
163
|
+
[
|
164
|
+
DateTime.new(2007, 12, 30).to_s,
|
165
|
+
DateTime.new(2007, 12, 31).to_s,
|
166
|
+
DateTime.new(2008, 1, 1).to_s,
|
167
|
+
DateTime.new(2008, 1, 2).to_s,
|
168
|
+
DateTime.new(2008, 1, 3).to_s,
|
169
|
+
DateTime.new(2008, 1, 4).to_s,
|
170
|
+
DateTime.new(2008, 1, 5).to_s,
|
171
|
+
]
|
172
|
+
end
|
173
|
+
|
174
|
+
def shifted_week_after_spanning_month_and_year_unshifted
|
175
|
+
[
|
176
|
+
DateTime.new(2008, 1, 1).to_s,
|
177
|
+
DateTime.new(2008, 1, 2).to_s,
|
178
|
+
DateTime.new(2008, 1, 3).to_s,
|
179
|
+
DateTime.new(2008, 1, 4).to_s,
|
180
|
+
DateTime.new(2008, 1, 5).to_s,
|
181
|
+
DateTime.new(2008, 1, 6).to_s,
|
182
|
+
DateTime.new(2008, 1, 7).to_s,
|
183
|
+
]
|
184
|
+
end
|
185
|
+
|
186
|
+
def re_shifted_week_after_spanning_month_and_year_unshifted
|
187
|
+
[
|
188
|
+
DateTime.new(2008, 1, 2).to_s,
|
189
|
+
DateTime.new(2008, 1, 3).to_s,
|
190
|
+
DateTime.new(2008, 1, 4).to_s,
|
191
|
+
DateTime.new(2008, 1, 5).to_s,
|
192
|
+
DateTime.new(2008, 1, 6).to_s,
|
193
|
+
DateTime.new(2008, 1, 7).to_s,
|
194
|
+
DateTime.new(2008, 1, 8).to_s,
|
195
|
+
]
|
196
|
+
end
|
197
|
+
private :unshifted_week_spanning_month_and_year, :shifted_week_after_spanning_month_and_year_unshifted, :re_shifted_week_after_spanning_month_and_year_unshifted
|
198
|
+
|
199
|
+
def test_week_days_span_month_and_year_boundary_non_leap_year_changing_the_week_day_start
|
254
200
|
date = DateTime.new(2007, 12, 31)
|
255
|
-
assert_equal(
|
256
|
-
DateTime.new(2007, 12, 30).to_s,
|
257
|
-
DateTime.new(2007, 12, 31).to_s,
|
258
|
-
DateTime.new(2008, 1, 1).to_s,
|
259
|
-
DateTime.new(2008, 1, 2).to_s,
|
260
|
-
DateTime.new(2008, 1, 3).to_s,
|
261
|
-
DateTime.new(2008, 1, 4).to_s,
|
262
|
-
DateTime.new(2008, 1, 5).to_s,
|
263
|
-
],
|
264
|
-
date.week_days.collect {|date| date.to_s}
|
265
|
-
)
|
201
|
+
assert_equal(unshifted_week_spanning_month_and_year, date.week_days.collect {|date| date.to_s})
|
266
202
|
assert_equal('2008-01-05', date.strftime("%Y-%m-%d"))
|
267
|
-
date.week_day_start = 2
|
268
|
-
assert_equal([
|
269
|
-
DateTime.new(2008, 1, 1).to_s,
|
270
|
-
DateTime.new(2008, 1, 2).to_s,
|
271
|
-
DateTime.new(2008, 1, 3).to_s,
|
272
|
-
DateTime.new(2008, 1, 4).to_s,
|
273
|
-
DateTime.new(2008, 1, 5).to_s,
|
274
|
-
DateTime.new(2008, 1, 6).to_s,
|
275
|
-
DateTime.new(2008, 1, 7).to_s,
|
276
|
-
],
|
277
|
-
date.week_days.collect {|date| date.to_s }
|
278
|
-
)
|
279
203
|
|
204
|
+
date.week_day_start = 2
|
205
|
+
assert_equal(shifted_week_after_spanning_month_and_year_unshifted, date.week_days.collect {|date| date.to_s })
|
280
206
|
assert_equal('2008-01-07', date.strftime("%Y-%m-%d"))
|
207
|
+
|
281
208
|
date.week_day_start = 'We'
|
282
|
-
assert_equal(
|
283
|
-
DateTime.new(2008, 1, 2).to_s,
|
284
|
-
DateTime.new(2008, 1, 3).to_s,
|
285
|
-
DateTime.new(2008, 1, 4).to_s,
|
286
|
-
DateTime.new(2008, 1, 5).to_s,
|
287
|
-
DateTime.new(2008, 1, 6).to_s,
|
288
|
-
DateTime.new(2008, 1, 7).to_s,
|
289
|
-
DateTime.new(2008, 1, 8).to_s,
|
290
|
-
],
|
291
|
-
date.week_days.collect {|date| date.to_s }
|
292
|
-
)
|
209
|
+
assert_equal(re_shifted_week_after_spanning_month_and_year_unshifted, date.week_days.collect {|date| date.to_s })
|
293
210
|
end
|
294
211
|
|
295
212
|
def test_step_to_month_end
|
296
|
-
# expected_display = {
|
297
|
-
# %w(January 2009) =>
|
298
|
-
# %w(Su Mo Tu We Th Fr Sa
|
299
|
-
# 28 29 30 31 1 2 3
|
300
|
-
# 4 5 6 7 8 9 10
|
301
|
-
# 11 12 13 14 15 16 17
|
302
|
-
# 18 19 20 21 22 23 24
|
303
|
-
# 25 26 27 28 29 30 31)
|
304
|
-
# }
|
305
213
|
expected_display = {
|
306
214
|
%w(January 2009) =>
|
307
215
|
%w(
|
@@ -354,4 +262,28 @@ class ShiftyWeekTest < Test::Unit::TestCase
|
|
354
262
|
assert_equal(DateTime.new(2007, 11).last_week_day, 5);
|
355
263
|
assert_equal(DateTime.new(2007, 12).last_week_day, 1);
|
356
264
|
end
|
265
|
+
|
266
|
+
private
|
267
|
+
|
268
|
+
def years_days_to_test
|
269
|
+
{ 1998 => 53,
|
270
|
+
1999 => 53,
|
271
|
+
2000 => 54,
|
272
|
+
2001 => 53,
|
273
|
+
2002 => 53,
|
274
|
+
2003 => 53,
|
275
|
+
2004 => 53,
|
276
|
+
2005 => 53,
|
277
|
+
2006 => 53,
|
278
|
+
2007 => 53,
|
279
|
+
2008 => 53,
|
280
|
+
2009 => 53,
|
281
|
+
2010 => 53,
|
282
|
+
2011 => 53,
|
283
|
+
2012 => 53,
|
284
|
+
2013 => 53,
|
285
|
+
2014 => 53,
|
286
|
+
2015 => 53,
|
287
|
+
2016 => 53 }
|
288
|
+
end
|
357
289
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shifty_week
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Noel-Hemming
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-08 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version:
|
69
69
|
requirements: []
|
70
70
|
|
71
|
-
rubyforge_project:
|
71
|
+
rubyforge_project: shifty-week
|
72
72
|
rubygems_version: 1.3.5
|
73
73
|
signing_key:
|
74
74
|
specification_version: 3
|