groupdate 2.5.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +22 -27
- data/groupdate.gemspec +1 -1
- data/lib/groupdate.rb +1 -1
- data/lib/groupdate/active_record.rb +1 -1
- data/lib/groupdate/magic.rb +19 -21
- data/lib/groupdate/version.rb +1 -1
- data/test/enumerable_test.rb +13 -3
- data/test/gemfiles/activerecord50.gemfile +1 -1
- data/test/test_helper.rb +182 -160
- 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: 1388ce20a1c1a41fdd0fe87d5cda7d28522ad2d2
|
4
|
+
data.tar.gz: 62660c4bb7aabbf6e619274038f2335c0dbed0dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 471f406dd29530940a51bd7b1547a3a19d8399098a6949d50a94e08be5fefb1e256cd3b996f0f964101541858b4744d85e6e85d1eb2c162e35ffc3fec2eb4df5
|
7
|
+
data.tar.gz: d199353fbccd7b4c1aa74609e4c28d187fc19036785c236cd23e4d0559a2c50a380fe3e273fd8a1f324d13b42e9e3b90b9ebc75bea7527a2661083bca1e2f43f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 3.0.0
|
2
|
+
|
3
|
+
Breaking changes
|
4
|
+
|
5
|
+
- `Date` objects are now returned for day, week, month, quarter, and year by default. Use `dates: false` for the previous behavior, or change this globally with `Groupdate.dates = false`.
|
6
|
+
- Array and hash methods no longer return the entire series by default. Use `series: true` for the previous behavior.
|
7
|
+
- The `series: false` option now returns the correct types and order, and plays nicely with other options.
|
8
|
+
|
1
9
|
## 2.5.3
|
2
10
|
|
3
11
|
- All tests green with `mysql` gem
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ The simplest way to group by:
|
|
7
7
|
- hour of the day
|
8
8
|
- and more (complete list below)
|
9
9
|
|
10
|
-
:tada: Time zones supported!! **the best part**
|
10
|
+
:tada: Time zones - including daylight saving time - supported!! **the best part**
|
11
11
|
|
12
12
|
:cake: Get the entire series - **the other best part**
|
13
13
|
|
@@ -19,14 +19,16 @@ Supports PostgreSQL and MySQL, plus arrays and hashes
|
|
19
19
|
|
20
20
|
:cupid: Goes hand in hand with [Chartkick](http://ankane.github.io/chartkick/)
|
21
21
|
|
22
|
+
**Groupdate 3.0 was just released!** See [instructions for upgrading](#30). If you use Chartkick with Groupdate, we recommend Chartkick 2.0 and above.
|
23
|
+
|
22
24
|
## Get Started
|
23
25
|
|
24
26
|
```ruby
|
25
27
|
User.group_by_day(:created_at).count
|
26
28
|
# {
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
29
|
+
# Sat, 28 May 2016 => 50,
|
30
|
+
# Sun, 29 May 2016 => 100,
|
31
|
+
# Mon, 30 May 2016 => 34
|
30
32
|
# }
|
31
33
|
```
|
32
34
|
|
@@ -65,9 +67,9 @@ or
|
|
65
67
|
```ruby
|
66
68
|
User.group_by_week(:created_at, time_zone: "Pacific Time (US & Canada)").count
|
67
69
|
# {
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
70
|
+
# Sun, 06 Mar 2016 => 70,
|
71
|
+
# Sun, 13 Mar 2016 => 54,
|
72
|
+
# Sun, 20 Mar 2016 => 80
|
71
73
|
# }
|
72
74
|
```
|
73
75
|
|
@@ -137,24 +139,7 @@ User.group_by_day(:created_at).order("day desc").count
|
|
137
139
|
|
138
140
|
### Keys
|
139
141
|
|
140
|
-
Keys are returned as time objects for the start of the period.
|
141
|
-
|
142
|
-
To get keys as date objects instead, use:
|
143
|
-
|
144
|
-
```ruby
|
145
|
-
User.group_by_day(:created_at, dates: true).count
|
146
|
-
# {
|
147
|
-
# 2013-03-10 => 70,
|
148
|
-
# 2013-03-17 => 54,
|
149
|
-
# 2013-03-24 => 80
|
150
|
-
# }
|
151
|
-
```
|
152
|
-
|
153
|
-
or make this the default with:
|
154
|
-
|
155
|
-
```ruby
|
156
|
-
Groupdate.dates = true
|
157
|
-
```
|
142
|
+
Keys are returned as date or time objects for the start of the period.
|
158
143
|
|
159
144
|
To get keys in a different format, use:
|
160
145
|
|
@@ -229,9 +214,19 @@ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
|
|
229
214
|
|
230
215
|
or copy and paste [these statements](https://gist.githubusercontent.com/ankane/1d6b0022173186accbf0/raw/time_zone_support.sql) into a SQL console.
|
231
216
|
|
232
|
-
## Upgrading
|
217
|
+
## Upgrading
|
218
|
+
|
219
|
+
### 3.0
|
220
|
+
|
221
|
+
Groupdate 3.0 brings a number of improvements. Here are a few to be aware of:
|
222
|
+
|
223
|
+
- `Date` objects are now returned for day, week, month, quarter, and year by default. Use `dates: false` for the previous behavior, or change this globally with `Groupdate.dates = false`.
|
224
|
+
- Array and hash methods no longer return the entire series by default. Use `series: true` for the previous behavior.
|
225
|
+
- The `series: false` option now returns the correct type and order, and plays nicely with other options.
|
226
|
+
|
227
|
+
### 2.0
|
233
228
|
|
234
|
-
Groupdate 2.0 brings a number
|
229
|
+
Groupdate 2.0 brings a number of improvements. Here are two things to be aware of:
|
235
230
|
|
236
231
|
- the entire series is returned by default
|
237
232
|
- `ActiveSupport::TimeWithZone` keys are now returned for every database adapter - adapters previously returned `Time` or `String` keys
|
data/groupdate.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/ankane/groupdate"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
data/lib/groupdate.rb
CHANGED
data/lib/groupdate/magic.rb
CHANGED
@@ -15,11 +15,7 @@ module Groupdate
|
|
15
15
|
|
16
16
|
def group_by(enum, &_block)
|
17
17
|
group = enum.group_by { |v| v = yield(v); v ? round_time(v) : nil }
|
18
|
-
|
19
|
-
group
|
20
|
-
else
|
21
|
-
series(group, [])
|
22
|
-
end
|
18
|
+
series(group, [], false, false, false)
|
23
19
|
end
|
24
20
|
|
25
21
|
def relation(column, relation)
|
@@ -90,22 +86,18 @@ module Groupdate
|
|
90
86
|
end
|
91
87
|
|
92
88
|
group = relation.group(Groupdate::OrderHack.new(relation.send(:sanitize_sql_array, query), field, time_zone))
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
else
|
101
|
-
group.where("#{column} IS NOT NULL")
|
102
|
-
end
|
89
|
+
relation =
|
90
|
+
if time_range.is_a?(Range)
|
91
|
+
# doesn't matter whether we include the end of a ... range - it will be excluded later
|
92
|
+
group.where("#{column} >= ? AND #{column} <= ?", time_range.first, time_range.last)
|
93
|
+
else
|
94
|
+
group.where("#{column} IS NOT NULL")
|
95
|
+
end
|
103
96
|
|
104
|
-
|
105
|
-
|
97
|
+
# TODO do not change object state
|
98
|
+
@group_index = group.group_values.size - 1
|
106
99
|
|
107
|
-
|
108
|
-
end
|
100
|
+
Groupdate::Series.new(self, relation)
|
109
101
|
end
|
110
102
|
|
111
103
|
def perform(relation, method, *args, &block)
|
@@ -175,7 +167,7 @@ module Groupdate
|
|
175
167
|
end
|
176
168
|
end
|
177
169
|
|
178
|
-
def series(count, default_value, multiple_groups = false, reverse = false)
|
170
|
+
def series(count, default_value, multiple_groups = false, reverse = false, series_default = true)
|
179
171
|
reverse = !reverse if options[:reverse]
|
180
172
|
|
181
173
|
series =
|
@@ -238,6 +230,7 @@ module Groupdate
|
|
238
230
|
series = series.to_a.reverse if !multiple_groups && reverse
|
239
231
|
|
240
232
|
locale = options[:locale] || I18n.locale
|
233
|
+
use_dates = options.key?(:dates) ? options[:dates] : Groupdate.dates
|
241
234
|
key_format =
|
242
235
|
if options[:format]
|
243
236
|
if options[:format].respond_to?(:call)
|
@@ -258,12 +251,17 @@ module Groupdate
|
|
258
251
|
I18n.localize(key, format: options[:format], locale: locale)
|
259
252
|
end
|
260
253
|
end
|
261
|
-
elsif
|
254
|
+
elsif [:day, :week, :month, :quarter, :year].include?(field) && use_dates
|
262
255
|
lambda { |k| k.to_date }
|
263
256
|
else
|
264
257
|
lambda { |k| k }
|
265
258
|
end
|
266
259
|
|
260
|
+
use_series = options.key?(:series) ? options[:series] : series_default
|
261
|
+
if use_series == false
|
262
|
+
series = series.select { |k| count[k] }
|
263
|
+
end
|
264
|
+
|
267
265
|
value = 0
|
268
266
|
Hash[series.map do |k|
|
269
267
|
value = count[k] || (@options[:carry_forward] && value) || default_value
|
data/lib/groupdate/version.rb
CHANGED
data/test/enumerable_test.rb
CHANGED
@@ -8,13 +8,23 @@ class TestEnumerable < Minitest::Test
|
|
8
8
|
user_a = create_user("2014-01-21")
|
9
9
|
user_b = create_user("2014-03-14")
|
10
10
|
expected = {
|
11
|
-
|
12
|
-
|
13
|
-
utc.parse("2014-03-01") => [user_b]
|
11
|
+
Date.parse("2014-01-01") => [user_a],
|
12
|
+
Date.parse("2014-03-01") => [user_b]
|
14
13
|
}
|
15
14
|
assert_equal expected, [user_a, user_b].group_by_month(&:created_at)
|
16
15
|
end
|
17
16
|
|
17
|
+
def test_enumerable_series
|
18
|
+
user_a = create_user("2014-01-21")
|
19
|
+
user_b = create_user("2014-03-14")
|
20
|
+
expected = {
|
21
|
+
Date.parse("2014-01-01") => [user_a],
|
22
|
+
Date.parse("2014-02-01") => [],
|
23
|
+
Date.parse("2014-03-01") => [user_b]
|
24
|
+
}
|
25
|
+
assert_equal expected, [user_a, user_b].group_by_month(series: true, &:created_at)
|
26
|
+
end
|
27
|
+
|
18
28
|
def test_no_block
|
19
29
|
assert_raises(ArgumentError) { [].group_by_day(:created_at) }
|
20
30
|
end
|
data/test/test_helper.rb
CHANGED
@@ -51,11 +51,11 @@ end
|
|
51
51
|
|
52
52
|
module TestDatabase
|
53
53
|
def test_zeros_previous_scope
|
54
|
-
create_user "2013-05-01
|
54
|
+
create_user "2013-05-01"
|
55
55
|
expected = {
|
56
|
-
|
56
|
+
Date.parse("2013-05-01") => 0
|
57
57
|
}
|
58
|
-
assert_equal expected, User.where("id = 0").group_by_day(:created_at, range:
|
58
|
+
assert_equal expected, User.where("id = 0").group_by_day(:created_at, range: Date.parse("2013-05-01")..Date.parse("2013-05-01 23:59:59 UTC")).count
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_order_hour_of_day
|
@@ -81,51 +81,51 @@ module TestDatabase
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_previous_scopes
|
84
|
-
create_user "2013-05-01
|
84
|
+
create_user "2013-05-01"
|
85
85
|
assert_empty User.where("id = 0").group_by_day(:created_at).count
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_where_after
|
89
|
-
create_user "2013-05-01
|
90
|
-
create_user "2013-05-02
|
91
|
-
expected = {
|
92
|
-
assert_equal expected, User.group_by_day(:created_at).where("created_at > ?", "2013-05-01
|
89
|
+
create_user "2013-05-01"
|
90
|
+
create_user "2013-05-02"
|
91
|
+
expected = {Date.parse("2013-05-02") => 1}
|
92
|
+
assert_equal expected, User.group_by_day(:created_at).where("created_at > ?", "2013-05-01").count
|
93
93
|
end
|
94
94
|
|
95
95
|
def test_group_before
|
96
|
-
create_user "2013-05-01
|
97
|
-
create_user "2013-05-02
|
98
|
-
create_user "2013-05-03
|
96
|
+
create_user "2013-05-01", 1
|
97
|
+
create_user "2013-05-02", 2
|
98
|
+
create_user "2013-05-03", 2
|
99
99
|
expected = {
|
100
|
-
[1,
|
101
|
-
[1,
|
102
|
-
[1,
|
103
|
-
[2,
|
104
|
-
[2,
|
105
|
-
[2,
|
100
|
+
[1, Date.parse("2013-05-01")] => 1,
|
101
|
+
[1, Date.parse("2013-05-02")] => 0,
|
102
|
+
[1, Date.parse("2013-05-03")] => 0,
|
103
|
+
[2, Date.parse("2013-05-01")] => 0,
|
104
|
+
[2, Date.parse("2013-05-02")] => 1,
|
105
|
+
[2, Date.parse("2013-05-03")] => 1
|
106
106
|
}
|
107
107
|
assert_equal expected, User.group(:score).group_by_day(:created_at).order(:score).count
|
108
108
|
end
|
109
109
|
|
110
110
|
def test_group_after
|
111
|
-
create_user "2013-05-01
|
112
|
-
create_user "2013-05-02
|
113
|
-
create_user "2013-05-03
|
111
|
+
create_user "2013-05-01", 1
|
112
|
+
create_user "2013-05-02", 2
|
113
|
+
create_user "2013-05-03", 2
|
114
114
|
expected = {
|
115
|
-
[
|
116
|
-
[
|
117
|
-
[
|
118
|
-
[
|
119
|
-
[
|
120
|
-
[
|
115
|
+
[Date.parse("2013-05-01"), 1] => 1,
|
116
|
+
[Date.parse("2013-05-02"), 1] => 0,
|
117
|
+
[Date.parse("2013-05-03"), 1] => 0,
|
118
|
+
[Date.parse("2013-05-01"), 2] => 0,
|
119
|
+
[Date.parse("2013-05-02"), 2] => 1,
|
120
|
+
[Date.parse("2013-05-03"), 2] => 1
|
121
121
|
}
|
122
122
|
assert_equal expected, User.group_by_day(:created_at).group(:score).order(:score).count
|
123
123
|
end
|
124
124
|
|
125
125
|
def test_group_day_of_week
|
126
|
-
create_user "2013-05-01
|
127
|
-
create_user "2013-05-02
|
128
|
-
create_user "2013-05-03
|
126
|
+
create_user "2013-05-01", 1
|
127
|
+
create_user "2013-05-02", 2
|
128
|
+
create_user "2013-05-03", 2
|
129
129
|
expected = {
|
130
130
|
[1, 0] => 0,
|
131
131
|
[1, 1] => 0,
|
@@ -146,9 +146,9 @@ module TestDatabase
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def test_groupdate_multiple
|
149
|
-
create_user "2013-05-01
|
149
|
+
create_user "2013-05-01", 1
|
150
150
|
expected = {
|
151
|
-
[
|
151
|
+
[Date.parse("2013-05-01"), Date.parse("2013-01-01")] => 1
|
152
152
|
}
|
153
153
|
assert_equal expected, User.group_by_day(:created_at).group_by_year(:created_at).count
|
154
154
|
end
|
@@ -165,10 +165,10 @@ module TestDatabase
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def test_not_modified
|
168
|
-
create_user "2013-05-01
|
169
|
-
expected = {
|
168
|
+
create_user "2013-05-01"
|
169
|
+
expected = {Date.parse("2013-05-01") => 1}
|
170
170
|
relation = User.group_by_day(:created_at)
|
171
|
-
relation.where("created_at > ?", "2013-05-01
|
171
|
+
relation.where("created_at > ?", "2013-05-01")
|
172
172
|
assert_equal expected, relation.count
|
173
173
|
end
|
174
174
|
|
@@ -185,38 +185,38 @@ module TestDatabase
|
|
185
185
|
end
|
186
186
|
|
187
187
|
def test_last
|
188
|
-
create_user "#{this_year - 3}-01-01
|
189
|
-
create_user "#{this_year - 1}-01-01
|
188
|
+
create_user "#{this_year - 3}-01-01"
|
189
|
+
create_user "#{this_year - 1}-01-01"
|
190
190
|
expected = {
|
191
|
-
|
192
|
-
|
193
|
-
|
191
|
+
Date.parse("#{this_year - 2}-01-01") => 0,
|
192
|
+
Date.parse("#{this_year - 1}-01-01") => 1,
|
193
|
+
Date.parse("#{this_year}-01-01") => 0
|
194
194
|
}
|
195
195
|
assert_equal expected, User.group_by_year(:created_at, last: 3).count
|
196
196
|
end
|
197
197
|
|
198
198
|
def test_current
|
199
|
-
create_user "#{this_year - 3}-01-01
|
200
|
-
create_user "#{this_year - 1}-01-01
|
199
|
+
create_user "#{this_year - 3}-01-01"
|
200
|
+
create_user "#{this_year - 1}-01-01"
|
201
201
|
expected = {
|
202
|
-
|
203
|
-
|
202
|
+
Date.parse("#{this_year - 2}-01-01") => 0,
|
203
|
+
Date.parse("#{this_year - 1}-01-01") => 1
|
204
204
|
}
|
205
205
|
assert_equal expected, User.group_by_year(:created_at, last: 2, current: false).count
|
206
206
|
end
|
207
207
|
|
208
208
|
def test_format_locale
|
209
|
-
create_user "2014-10-01
|
209
|
+
create_user "2014-10-01"
|
210
210
|
assert_equal ({"Okt" => 1}), User.group_by_day(:created_at, format: "%b", locale: :de).count
|
211
211
|
end
|
212
212
|
|
213
213
|
def test_format_locale_by_symbol
|
214
|
-
create_user "2014-10-01
|
214
|
+
create_user "2014-10-01"
|
215
215
|
assert_equal ({"Okt 1, 2014" => 1}), User.group_by_day(:created_at, format: :special, locale: :de).count
|
216
216
|
end
|
217
217
|
|
218
218
|
def test_format_locale_global
|
219
|
-
create_user "2014-10-01
|
219
|
+
create_user "2014-10-01"
|
220
220
|
I18n.locale = :de
|
221
221
|
assert_equal ({"Okt" => 1}), User.group_by_day(:created_at, format: "%b").count
|
222
222
|
ensure
|
@@ -224,7 +224,7 @@ module TestDatabase
|
|
224
224
|
end
|
225
225
|
|
226
226
|
def test_format_multiple_groups
|
227
|
-
create_user "2014-03-01
|
227
|
+
create_user "2014-03-01"
|
228
228
|
assert_equal ({["Sun", 1] => 1}), User.group_by_week(:created_at, format: "%a").group(:score).count
|
229
229
|
assert_equal ({[1, "Sun"] => 1}), User.group(:score).group_by_week(:created_at, format: "%a").count
|
230
230
|
end
|
@@ -258,10 +258,10 @@ module TestDatabase
|
|
258
258
|
# default value
|
259
259
|
|
260
260
|
def test_default_value
|
261
|
-
create_user "#{this_year}-01-01
|
261
|
+
create_user "#{this_year}-01-01"
|
262
262
|
expected = {
|
263
|
-
|
264
|
-
|
263
|
+
Date.parse("#{this_year - 1}-01-01") => nil,
|
264
|
+
Date.parse("#{this_year}-01-01") => 1
|
265
265
|
}
|
266
266
|
assert_equal expected, User.group_by_year(:created_at, last: 2, default_value: nil).count
|
267
267
|
end
|
@@ -269,10 +269,10 @@ module TestDatabase
|
|
269
269
|
# associations
|
270
270
|
|
271
271
|
def test_associations
|
272
|
-
user = create_user("2014-03-01
|
272
|
+
user = create_user("2014-03-01")
|
273
273
|
user.posts.create!(created_at: "2014-04-01 00:00:00 UTC")
|
274
274
|
expected = {
|
275
|
-
|
275
|
+
Date.parse("2014-04-01") => 1
|
276
276
|
}
|
277
277
|
assert_equal expected, user.posts.group_by_day(:created_at).count
|
278
278
|
end
|
@@ -293,8 +293,8 @@ module TestDatabase
|
|
293
293
|
create_user(brasilia.parse("2014-10-19 02:00:00").utc.to_s)
|
294
294
|
create_user(brasilia.parse("2014-10-20 02:00:00").utc.to_s)
|
295
295
|
expected = {
|
296
|
-
|
297
|
-
|
296
|
+
Date.parse("2014-10-19") => 1,
|
297
|
+
Date.parse("2014-10-20") => 1
|
298
298
|
}
|
299
299
|
assert_equal expected, User.group_by_day(:created_at, time_zone: "Brasilia").count
|
300
300
|
end
|
@@ -302,10 +302,10 @@ module TestDatabase
|
|
302
302
|
# carry_forward option
|
303
303
|
|
304
304
|
def test_carry_forward
|
305
|
-
create_user "2014-05-01
|
306
|
-
create_user "2014-05-01
|
307
|
-
create_user "2014-05-03
|
308
|
-
assert_equal 2, User.group_by_day(:created_at, carry_forward: true).count[
|
305
|
+
create_user "2014-05-01"
|
306
|
+
create_user "2014-05-01"
|
307
|
+
create_user "2014-05-03"
|
308
|
+
assert_equal 2, User.group_by_day(:created_at, carry_forward: true).count[Date.parse("2014-05-02")]
|
309
309
|
end
|
310
310
|
|
311
311
|
# dates
|
@@ -333,7 +333,7 @@ module TestDatabase
|
|
333
333
|
)
|
334
334
|
|
335
335
|
# hack for MySQL adapter
|
336
|
-
user.update_attributes(created_at: nil, created_on: nil) if created_at.nil?
|
336
|
+
# user.update_attributes(created_at: nil, created_on: nil) if created_at.nil?
|
337
337
|
|
338
338
|
user
|
339
339
|
end
|
@@ -389,217 +389,217 @@ module TestGroupdate
|
|
389
389
|
# day
|
390
390
|
|
391
391
|
def test_day_end_of_day
|
392
|
-
|
392
|
+
assert_result_date :day, "2013-05-03", "2013-05-03 23:59:59"
|
393
393
|
end
|
394
394
|
|
395
395
|
def test_day_start_of_day
|
396
|
-
|
396
|
+
assert_result_date :day, "2013-05-04", "2013-05-04 00:00:00"
|
397
397
|
end
|
398
398
|
|
399
399
|
def test_day_end_of_day_with_time_zone
|
400
|
-
|
400
|
+
assert_result_date :day, "2013-05-02", "2013-05-03 06:59:59", true
|
401
401
|
end
|
402
402
|
|
403
403
|
def test_day_start_of_day_with_time_zone
|
404
|
-
|
404
|
+
assert_result_date :day, "2013-05-03", "2013-05-03 07:00:00", true
|
405
405
|
end
|
406
406
|
|
407
407
|
# day hour starts at 2 am
|
408
408
|
|
409
409
|
def test_test_day_end_of_day_day_start_2am
|
410
|
-
|
410
|
+
assert_result_date :day, "2013-05-03", "2013-05-04 01:59:59", false, day_start: 2
|
411
411
|
end
|
412
412
|
|
413
413
|
def test_test_day_start_of_day_day_start_2am
|
414
|
-
|
414
|
+
assert_result_date :day, "2013-05-03", "2013-05-03 02:00:00", false, day_start: 2
|
415
415
|
end
|
416
416
|
|
417
417
|
def test_test_day_end_of_day_with_time_zone_day_start_2am
|
418
|
-
|
418
|
+
assert_result_date :day, "2013-05-03", "2013-05-04 07:59:59", true, day_start: 2
|
419
419
|
end
|
420
420
|
|
421
421
|
def test_test_day_start_of_day_with_time_zone_day_start_2am
|
422
|
-
|
422
|
+
assert_result_date :day, "2013-05-03", "2013-05-03 09:00:00", true, day_start: 2
|
423
423
|
end
|
424
424
|
|
425
425
|
# week
|
426
426
|
|
427
427
|
def test_week_end_of_week
|
428
|
-
|
428
|
+
assert_result_date :week, "2013-03-17", "2013-03-23 23:59:59"
|
429
429
|
end
|
430
430
|
|
431
431
|
def test_week_start_of_week
|
432
|
-
|
432
|
+
assert_result_date :week, "2013-03-24", "2013-03-24 00:00:00"
|
433
433
|
end
|
434
434
|
|
435
435
|
def test_week_end_of_week_with_time_zone
|
436
|
-
|
436
|
+
assert_result_date :week, "2013-03-10", "2013-03-17 06:59:59", true
|
437
437
|
end
|
438
438
|
|
439
439
|
def test_week_start_of_week_with_time_zone
|
440
|
-
|
440
|
+
assert_result_date :week, "2013-03-17", "2013-03-17 07:00:00", true
|
441
441
|
end
|
442
442
|
|
443
443
|
# week starting on monday
|
444
444
|
|
445
445
|
def test_week_end_of_week_mon
|
446
|
-
|
446
|
+
assert_result_date :week, "2013-03-18", "2013-03-24 23:59:59", false, week_start: :mon
|
447
447
|
end
|
448
448
|
|
449
449
|
def test_week_start_of_week_mon
|
450
|
-
|
450
|
+
assert_result_date :week, "2013-03-25", "2013-03-25 00:00:00", false, week_start: :mon
|
451
451
|
end
|
452
452
|
|
453
453
|
def test_week_end_of_week_with_time_zone_mon
|
454
|
-
|
454
|
+
assert_result_date :week, "2013-03-11", "2013-03-18 06:59:59", true, week_start: :mon
|
455
455
|
end
|
456
456
|
|
457
457
|
def test_week_start_of_week_with_time_zone_mon
|
458
|
-
|
458
|
+
assert_result_date :week, "2013-03-18", "2013-03-18 07:00:00", true, week_start: :mon
|
459
459
|
end
|
460
460
|
|
461
461
|
# week starting on saturday
|
462
462
|
|
463
463
|
def test_week_end_of_week_sat
|
464
|
-
|
464
|
+
assert_result_date :week, "2013-03-16", "2013-03-22 23:59:59", false, week_start: :sat
|
465
465
|
end
|
466
466
|
|
467
467
|
def test_week_start_of_week_sat
|
468
|
-
|
468
|
+
assert_result_date :week, "2013-03-23", "2013-03-23 00:00:00", false, week_start: :sat
|
469
469
|
end
|
470
470
|
|
471
471
|
def test_week_end_of_week_with_time_zone_sat
|
472
|
-
|
472
|
+
assert_result_date :week, "2013-03-09", "2013-03-16 06:59:59", true, week_start: :sat
|
473
473
|
end
|
474
474
|
|
475
475
|
def test_week_start_of_week_with_time_zone_sat
|
476
|
-
|
476
|
+
assert_result_date :week, "2013-03-16", "2013-03-16 07:00:00", true, week_start: :sat
|
477
477
|
end
|
478
478
|
|
479
479
|
# week starting at 2am
|
480
480
|
|
481
481
|
def test_week_end_of_week_day_start_2am
|
482
|
-
|
482
|
+
assert_result_date :week, "2013-03-17", "2013-03-24 01:59:59", false, day_start: 2
|
483
483
|
end
|
484
484
|
|
485
485
|
def test_week_start_of_week_day_start_2am
|
486
|
-
|
486
|
+
assert_result_date :week, "2013-03-17", "2013-03-17 02:00:00", false, day_start: 2
|
487
487
|
end
|
488
488
|
|
489
489
|
def test_week_end_of_week_day_with_time_zone_start_2am
|
490
|
-
|
490
|
+
assert_result_date :week, "2013-03-17", "2013-03-24 08:59:59", true, day_start: 2
|
491
491
|
end
|
492
492
|
|
493
493
|
def test_week_start_of_week_day_with_time_zone_start_2am
|
494
|
-
|
494
|
+
assert_result_date :week, "2013-03-17", "2013-03-17 09:00:00", true, day_start: 2
|
495
495
|
end
|
496
496
|
|
497
497
|
# month
|
498
498
|
|
499
499
|
def test_month_end_of_month
|
500
|
-
|
500
|
+
assert_result_date :month, "2013-05-01", "2013-05-31 23:59:59"
|
501
501
|
end
|
502
502
|
|
503
503
|
def test_month_start_of_month
|
504
|
-
|
504
|
+
assert_result_date :month, "2013-06-01", "2013-06-01 00:00:00"
|
505
505
|
end
|
506
506
|
|
507
507
|
def test_month_end_of_month_with_time_zone
|
508
|
-
|
508
|
+
assert_result_date :month, "2013-05-01", "2013-06-01 06:59:59", true
|
509
509
|
end
|
510
510
|
|
511
511
|
def test_month_start_of_month_with_time_zone
|
512
|
-
|
512
|
+
assert_result_date :month, "2013-06-01", "2013-06-01 07:00:00", true
|
513
513
|
end
|
514
514
|
|
515
515
|
# month starts at 2am
|
516
516
|
|
517
517
|
def test_month_end_of_month_day_start_2am
|
518
|
-
|
518
|
+
assert_result_date :month, "2013-03-01", "2013-04-01 01:59:59", false, day_start: 2
|
519
519
|
end
|
520
520
|
|
521
521
|
def test_month_start_of_month_day_start_2am
|
522
|
-
|
522
|
+
assert_result_date :month, "2013-03-01", "2013-03-01 02:00:00", false, day_start: 2
|
523
523
|
end
|
524
524
|
|
525
525
|
def test_month_end_of_month_with_time_zone_day_start_2am
|
526
|
-
|
526
|
+
assert_result_date :month, "2013-03-01", "2013-04-01 08:59:59", true, day_start: 2
|
527
527
|
end
|
528
528
|
|
529
529
|
def test_month_start_of_month_with_time_zone_day_start_2am
|
530
|
-
|
530
|
+
assert_result_date :month, "2013-03-01", "2013-03-01 10:00:00", true, day_start: 2
|
531
531
|
end
|
532
532
|
|
533
533
|
# quarter
|
534
534
|
|
535
535
|
def test_quarter_end_of_quarter
|
536
|
-
|
536
|
+
assert_result_date :quarter, "2013-04-01", "2013-06-30 23:59:59"
|
537
537
|
end
|
538
538
|
|
539
539
|
def test_quarter_start_of_quarter
|
540
|
-
|
540
|
+
assert_result_date :quarter, "2013-04-01", "2013-04-01 00:00:00"
|
541
541
|
end
|
542
542
|
|
543
543
|
def test_quarter_end_of_quarter_with_time_zone
|
544
|
-
|
544
|
+
assert_result_date :quarter, "2013-04-01", "2013-07-01 06:59:59", true
|
545
545
|
end
|
546
546
|
|
547
547
|
def test_quarter_start_of_quarter_with_time_zone
|
548
|
-
|
548
|
+
assert_result_date :quarter, "2013-04-01", "2013-04-01 07:00:00", true
|
549
549
|
end
|
550
550
|
|
551
551
|
# quarter starts at 2am
|
552
552
|
|
553
553
|
def test_quarter_end_of_quarter_day_start_2am
|
554
|
-
|
554
|
+
assert_result_date :quarter, "2013-04-01", "2013-07-01 01:59:59", false, day_start: 2
|
555
555
|
end
|
556
556
|
|
557
557
|
def test_quarter_start_of_quarter_day_start_2am
|
558
|
-
|
558
|
+
assert_result_date :quarter, "2013-04-01", "2013-04-01 02:00:00", false, day_start: 2
|
559
559
|
end
|
560
560
|
|
561
561
|
def test_quarter_end_of_quarter_with_time_zone_day_start_2am
|
562
|
-
|
562
|
+
assert_result_date :quarter, "2013-01-01", "2013-04-01 08:59:59", true, day_start: 2
|
563
563
|
end
|
564
564
|
|
565
565
|
def test_quarter_start_of_quarter_with_time_zone_day_start_2am
|
566
|
-
|
566
|
+
assert_result_date :quarter, "2013-01-01", "2013-01-01 10:00:00", true, day_start: 2
|
567
567
|
end
|
568
568
|
|
569
569
|
# year
|
570
570
|
|
571
571
|
def test_year_end_of_year
|
572
|
-
|
572
|
+
assert_result_date :year, "2013-01-01", "2013-12-31 23:59:59"
|
573
573
|
end
|
574
574
|
|
575
575
|
def test_year_start_of_year
|
576
|
-
|
576
|
+
assert_result_date :year, "2014-01-01", "2014-01-01 00:00:00"
|
577
577
|
end
|
578
578
|
|
579
579
|
def test_year_end_of_year_with_time_zone
|
580
|
-
|
580
|
+
assert_result_date :year, "2013-01-01", "2014-01-01 07:59:59", true
|
581
581
|
end
|
582
582
|
|
583
583
|
def test_year_start_of_year_with_time_zone
|
584
|
-
|
584
|
+
assert_result_date :year, "2014-01-01", "2014-01-01 08:00:00", true
|
585
585
|
end
|
586
586
|
|
587
587
|
# year starts at 2am
|
588
588
|
|
589
589
|
def test_year_end_of_year_day_start_2am
|
590
|
-
|
590
|
+
assert_result_date :year, "2013-01-01", "2014-01-01 01:59:59", false, day_start: 2
|
591
591
|
end
|
592
592
|
|
593
593
|
def test_year_start_of_year_day_start_2am
|
594
|
-
|
594
|
+
assert_result_date :year, "2013-01-01", "2013-01-01 02:00:00", false, day_start: 2
|
595
595
|
end
|
596
596
|
|
597
597
|
def test_year_end_of_year_with_time_zone_day_start_2am
|
598
|
-
|
598
|
+
assert_result_date :year, "2013-01-01", "2014-01-01 09:59:59", true, day_start: 2
|
599
599
|
end
|
600
600
|
|
601
601
|
def test_year_start_of_year_with_time_zone_day_start_2am
|
602
|
-
|
602
|
+
assert_result_date :year, "2013-01-01", "2013-01-01 10:00:00", true, day_start: 2
|
603
603
|
end
|
604
604
|
|
605
605
|
# hour of day
|
@@ -765,68 +765,68 @@ module TestGroupdate
|
|
765
765
|
end
|
766
766
|
|
767
767
|
def test_zeros_day
|
768
|
-
|
768
|
+
assert_zeros_date :day, "2013-05-01 20:00:00 UTC", ["2013-04-30", "2013-05-01", "2013-05-02"], "2013-04-30 00:00:00 UTC", "2013-05-02 23:59:59 UTC"
|
769
769
|
end
|
770
770
|
|
771
771
|
def test_zeros_day_time_zone
|
772
|
-
|
772
|
+
assert_zeros_date :day, "2013-05-01 20:00:00 PDT", ["2013-04-30", "2013-05-01", "2013-05-02"], "2013-04-30 00:00:00 PDT", "2013-05-02 23:59:59 PDT", true
|
773
773
|
end
|
774
774
|
|
775
775
|
def test_zeros_week
|
776
|
-
|
776
|
+
assert_zeros_date :week, "2013-05-01 20:00:00 UTC", ["2013-04-21", "2013-04-28", "2013-05-05"], "2013-04-27 23:59:59 UTC", "2013-05-11 23:59:59 UTC"
|
777
777
|
end
|
778
778
|
|
779
779
|
def test_zeros_week_time_zone
|
780
|
-
|
780
|
+
assert_zeros_date :week, "2013-05-01 20:00:00 PDT", ["2013-04-21", "2013-04-28", "2013-05-05"], "2013-04-27 23:59:59 PDT", "2013-05-11 23:59:59 PDT", true
|
781
781
|
end
|
782
782
|
|
783
783
|
def test_zeros_week_mon
|
784
|
-
|
784
|
+
assert_zeros_date :week, "2013-05-01 20:00:00 UTC", ["2013-04-22", "2013-04-29", "2013-05-06"], "2013-04-27 23:59:59 UTC", "2013-05-11 23:59:59 UTC", false, week_start: :mon
|
785
785
|
end
|
786
786
|
|
787
787
|
def test_zeros_week_time_zone_mon
|
788
|
-
|
788
|
+
assert_zeros_date :week, "2013-05-01 20:00:00 PDT", ["2013-04-22", "2013-04-29", "2013-05-06"], "2013-04-27 23:59:59 PDT", "2013-05-11 23:59:59 PDT", true, week_start: :mon
|
789
789
|
end
|
790
790
|
|
791
791
|
def test_zeros_week_sat
|
792
|
-
|
792
|
+
assert_zeros_date :week, "2013-05-01 20:00:00 UTC", ["2013-04-20", "2013-04-27", "2013-05-04"], "2013-04-26 23:59:59 UTC", "2013-05-10 23:59:59 UTC", false, week_start: :sat
|
793
793
|
end
|
794
794
|
|
795
795
|
def test_zeros_week_time_zone_sat
|
796
|
-
|
796
|
+
assert_zeros_date :week, "2013-05-01 20:00:00 PDT", ["2013-04-20", "2013-04-27", "2013-05-04"], "2013-04-26 23:59:59 PDT", "2013-05-10 23:59:59 PDT", true, week_start: :sat
|
797
797
|
end
|
798
798
|
|
799
799
|
def test_zeros_month
|
800
|
-
|
800
|
+
assert_zeros_date :month, "2013-04-16 20:00:00 UTC", ["2013-03-01", "2013-04-01", "2013-05-01"], "2013-03-01", "2013-05-31 23:59:59 UTC"
|
801
801
|
end
|
802
802
|
|
803
803
|
def test_zeros_month_time_zone
|
804
|
-
|
804
|
+
assert_zeros_date :month, "2013-04-16 20:00:00 PDT", ["2013-03-01", "2013-04-01", "2013-05-01"], "2013-03-01 00:00:00 PST", "2013-05-31 23:59:59 PDT", true
|
805
805
|
end
|
806
806
|
|
807
807
|
def test_zeros_quarter
|
808
|
-
|
808
|
+
assert_zeros_date :quarter, "2013-04-16 20:00:00 UTC", ["2013-01-01", "2013-04-01", "2013-07-01"], "2013-01-01", "2013-09-30 23:59:59 UTC"
|
809
809
|
end
|
810
810
|
|
811
811
|
def test_zeros_quarter_time_zone
|
812
|
-
|
812
|
+
assert_zeros_date :quarter, "2013-04-16 20:00:00 PDT", ["2013-01-01", "2013-04-01", "2013-07-01"], "2013-01-01 00:00:00 PST", "2013-09-30 23:59:59 PDT", true
|
813
813
|
end
|
814
814
|
|
815
815
|
def test_zeros_year
|
816
|
-
|
816
|
+
assert_zeros_date :year, "2013-04-16 20:00:00 UTC", ["2012-01-01", "2013-01-01", "2014-01-01"], "2012-01-01", "2014-12-31 23:59:59 UTC"
|
817
817
|
end
|
818
818
|
|
819
819
|
def test_zeros_year_time_zone
|
820
|
-
|
820
|
+
assert_zeros_date :year, "2013-04-16 20:00:00 PDT", ["2012-01-01 00:00:00 PST", "2013-01-01 00:00:00 PST", "2014-01-01 00:00:00 PST"], "2012-01-01 00:00:00 PST", "2014-12-31 23:59:59 PST", true
|
821
821
|
end
|
822
822
|
|
823
823
|
def test_zeros_day_of_week
|
824
|
-
create_user "2013-05-01
|
824
|
+
create_user "2013-05-01"
|
825
825
|
expected = {}
|
826
826
|
7.times do |n|
|
827
827
|
expected[n] = n == 3 ? 1 : 0
|
828
828
|
end
|
829
|
-
assert_equal expected, call_method(:day_of_week, :created_at, {})
|
829
|
+
assert_equal expected, call_method(:day_of_week, :created_at, {series: true})
|
830
830
|
end
|
831
831
|
|
832
832
|
def test_zeros_hour_of_day
|
@@ -835,130 +835,130 @@ module TestGroupdate
|
|
835
835
|
24.times do |n|
|
836
836
|
expected[n] = n == 20 ? 1 : 0
|
837
837
|
end
|
838
|
-
assert_equal expected, call_method(:hour_of_day, :created_at, {})
|
838
|
+
assert_equal expected, call_method(:hour_of_day, :created_at, {series: true})
|
839
839
|
end
|
840
840
|
|
841
841
|
def test_zeros_day_of_month
|
842
|
-
create_user "1978-12-18
|
842
|
+
create_user "1978-12-18"
|
843
843
|
expected = {}
|
844
844
|
(1..31).each do |n|
|
845
845
|
expected[n] = n == 18 ? 1 : 0
|
846
846
|
end
|
847
|
-
assert_equal expected, call_method(:day_of_month, :created_at, {})
|
847
|
+
assert_equal expected, call_method(:day_of_month, :created_at, {series: true})
|
848
848
|
end
|
849
849
|
|
850
850
|
def test_zeros_month_of_year
|
851
|
-
create_user "2013-05-01
|
851
|
+
create_user "2013-05-01"
|
852
852
|
expected = {}
|
853
853
|
(1..12).each do |n|
|
854
854
|
expected[n] = n == 5 ? 1 : 0
|
855
855
|
end
|
856
|
-
assert_equal expected, call_method(:month_of_year, :created_at, {})
|
856
|
+
assert_equal expected, call_method(:month_of_year, :created_at, {series: true})
|
857
857
|
end
|
858
858
|
|
859
859
|
def test_zeros_excludes_end
|
860
|
-
create_user "2013-05-02
|
860
|
+
create_user "2013-05-02"
|
861
861
|
expected = {
|
862
|
-
|
862
|
+
Date.parse("2013-05-01") => 0
|
863
863
|
}
|
864
|
-
assert_equal expected, call_method(:day, :created_at, range:
|
864
|
+
assert_equal expected, call_method(:day, :created_at, range: Date.parse("2013-05-01")...Date.parse("2013-05-02"), series: true)
|
865
865
|
end
|
866
866
|
|
867
867
|
def test_zeros_datetime
|
868
|
-
create_user "2013-05-01
|
868
|
+
create_user "2013-05-01"
|
869
869
|
expected = {
|
870
|
-
|
870
|
+
Date.parse("2013-05-01") => 1
|
871
871
|
}
|
872
|
-
assert_equal expected, call_method(:day, :created_at, range: DateTime.parse("2013-05-01
|
872
|
+
assert_equal expected, call_method(:day, :created_at, range: DateTime.parse("2013-05-01")..DateTime.parse("2013-05-01"), series: true)
|
873
873
|
end
|
874
874
|
|
875
875
|
def test_zeros_null_value
|
876
876
|
create_user nil
|
877
|
-
assert_equal 0, call_method(:hour_of_day, :created_at, range: true)[0]
|
877
|
+
assert_equal 0, call_method(:hour_of_day, :created_at, range: true, series: true)[0]
|
878
878
|
end
|
879
879
|
|
880
880
|
def test_zeroes_range_true
|
881
|
-
create_user "2013-05-01
|
882
|
-
create_user "2013-05-03
|
881
|
+
create_user "2013-05-01"
|
882
|
+
create_user "2013-05-03"
|
883
883
|
expected = {
|
884
|
-
|
885
|
-
|
886
|
-
|
884
|
+
Date.parse("2013-05-01") => 1,
|
885
|
+
Date.parse("2013-05-02") => 0,
|
886
|
+
Date.parse("2013-05-03") => 1
|
887
887
|
}
|
888
|
-
assert_equal expected, call_method(:day, :created_at, range: true)
|
888
|
+
assert_equal expected, call_method(:day, :created_at, range: true, series: true)
|
889
889
|
end
|
890
890
|
|
891
891
|
# week_start
|
892
892
|
|
893
893
|
def test_week_start
|
894
894
|
Groupdate.week_start = :mon
|
895
|
-
|
895
|
+
assert_result_date :week, "2013-03-18", "2013-03-24 23:59:59"
|
896
896
|
end
|
897
897
|
|
898
898
|
def test_week_start_and_start_option
|
899
899
|
Groupdate.week_start = :mon
|
900
|
-
|
900
|
+
assert_result_date :week, "2013-03-16", "2013-03-22 23:59:59", false, week_start: :sat
|
901
901
|
end
|
902
902
|
|
903
903
|
# misc
|
904
904
|
|
905
905
|
def test_order_hour_of_day_reverse_option
|
906
|
-
assert_equal 23, call_method(:hour_of_day, :created_at, reverse: true).keys.first
|
906
|
+
assert_equal 23, call_method(:hour_of_day, :created_at, reverse: true, series: true).keys.first
|
907
907
|
end
|
908
908
|
|
909
909
|
def test_time_zone
|
910
|
-
create_user "2013-05-01
|
910
|
+
create_user "2013-05-01"
|
911
911
|
time_zone = "Pacific Time (US & Canada)"
|
912
|
-
assert_equal time_zone, call_method(:
|
912
|
+
assert_equal time_zone, call_method(:hour, :created_at, time_zone: time_zone).keys.first.time_zone.name
|
913
913
|
end
|
914
914
|
|
915
915
|
def test_format_day
|
916
|
-
create_user "2014-03-01
|
916
|
+
create_user "2014-03-01"
|
917
917
|
assert_format :day, "March 1, 2014", "%B %-e, %Y"
|
918
918
|
end
|
919
919
|
|
920
920
|
def test_format_month
|
921
|
-
create_user "2014-03-01
|
921
|
+
create_user "2014-03-01"
|
922
922
|
assert_format :month, "March 2014", "%B %Y"
|
923
923
|
end
|
924
924
|
|
925
925
|
def test_format_quarter
|
926
|
-
create_user "2014-03-05
|
926
|
+
create_user "2014-03-05"
|
927
927
|
assert_format :quarter, "January 1, 2014", "%B %-e, %Y"
|
928
928
|
end
|
929
929
|
|
930
930
|
def test_format_year
|
931
|
-
create_user "2014-03-01
|
931
|
+
create_user "2014-03-01"
|
932
932
|
assert_format :year, "2014", "%Y"
|
933
933
|
end
|
934
934
|
|
935
935
|
def test_format_hour_of_day
|
936
|
-
create_user "2014-03-01
|
936
|
+
create_user "2014-03-01"
|
937
937
|
assert_format :hour_of_day, "12 am", "%-l %P"
|
938
938
|
end
|
939
939
|
|
940
940
|
def test_format_hour_of_day_day_start
|
941
|
-
create_user "2014-03-01
|
941
|
+
create_user "2014-03-01"
|
942
942
|
assert_format :hour_of_day, "2 am", "%-l %P", day_start: 2
|
943
943
|
end
|
944
944
|
|
945
945
|
def test_format_day_of_week
|
946
|
-
create_user "2014-03-01
|
946
|
+
create_user "2014-03-01"
|
947
947
|
assert_format :day_of_week, "Sun", "%a"
|
948
948
|
end
|
949
949
|
|
950
950
|
def test_format_day_of_week_week_start
|
951
|
-
create_user "2014-03-01
|
951
|
+
create_user "2014-03-01"
|
952
952
|
assert_format :day_of_week, "Sun", "%a", week_start: :sat
|
953
953
|
end
|
954
954
|
|
955
955
|
def test_format_day_of_month
|
956
|
-
create_user "2014-03-01
|
956
|
+
create_user "2014-03-01"
|
957
957
|
assert_format :day_of_month, " 1", "%e"
|
958
958
|
end
|
959
959
|
|
960
960
|
def test_format_month_of_year
|
961
|
-
create_user "2014-01-01
|
961
|
+
create_user "2014-01-01"
|
962
962
|
assert_format :month_of_year, "Jan", "%b"
|
963
963
|
end
|
964
964
|
|
@@ -983,17 +983,17 @@ module TestGroupdate
|
|
983
983
|
# day start
|
984
984
|
|
985
985
|
def test_day_start_decimal_end_of_day
|
986
|
-
|
986
|
+
assert_result_date :day, "2013-05-03", "2013-05-04 02:29:59", false, day_start: 2.5
|
987
987
|
end
|
988
988
|
|
989
989
|
def test_day_start_decimal_start_of_day
|
990
|
-
|
990
|
+
assert_result_date :day, "2013-05-03", "2013-05-03 02:30:00", false, day_start: 2.5
|
991
991
|
end
|
992
992
|
|
993
993
|
# helpers
|
994
994
|
|
995
995
|
def assert_format(method, expected, format, options = {})
|
996
|
-
assert_equal expected, call_method(method, :created_at, options.merge(format: format)).keys.first
|
996
|
+
assert_equal expected, call_method(method, :created_at, options.merge(format: format, series: true)).keys.first
|
997
997
|
end
|
998
998
|
|
999
999
|
def assert_result_time(method, expected, time_str, time_zone = false, options = {})
|
@@ -1001,6 +1001,15 @@ module TestGroupdate
|
|
1001
1001
|
assert_equal expected, result(method, time_str, time_zone, options)
|
1002
1002
|
end
|
1003
1003
|
|
1004
|
+
def assert_result_date(method, expected_str, time_str, time_zone = false, options = {})
|
1005
|
+
create_user time_str
|
1006
|
+
expected = {Date.parse(expected_str) => 1}
|
1007
|
+
assert_equal expected, call_method(method, :created_at, options.merge(time_zone: time_zone ? "Pacific Time (US & Canada)" : nil))
|
1008
|
+
expected = {(time_zone ? pt : utc).parse(expected_str) + options[:day_start].to_f.hours => 1}
|
1009
|
+
assert_equal expected, call_method(method, :created_at, options.merge(dates: false, time_zone: time_zone ? "Pacific Time (US & Canada)" : nil))
|
1010
|
+
# assert_equal expected, call_method(method, :created_on, options.merge(time_zone: time_zone ? "Pacific Time (US & Canada)" : nil))
|
1011
|
+
end
|
1012
|
+
|
1004
1013
|
def assert_result(method, expected, time_str, time_zone = false, options = {})
|
1005
1014
|
assert_equal 1, result(method, time_str, time_zone, options)[expected]
|
1006
1015
|
end
|
@@ -1016,7 +1025,16 @@ module TestGroupdate
|
|
1016
1025
|
keys.each_with_index do |key, i|
|
1017
1026
|
expected[utc.parse(key).in_time_zone(time_zone ? "Pacific Time (US & Canada)" : utc)] = i == 1 ? 1 : 0
|
1018
1027
|
end
|
1019
|
-
assert_equal expected, call_method(method, :created_at, options.merge(time_zone: time_zone ? "Pacific Time (US & Canada)" : nil, range: Time.parse(range_start)..Time.parse(range_end)))
|
1028
|
+
assert_equal expected, call_method(method, :created_at, options.merge(series: true, time_zone: time_zone ? "Pacific Time (US & Canada)" : nil, range: Time.parse(range_start)..Time.parse(range_end)))
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
def assert_zeros_date(method, created_at, keys, range_start, range_end, time_zone = nil, options = {})
|
1032
|
+
create_user created_at
|
1033
|
+
expected = {}
|
1034
|
+
keys.each_with_index do |key, i|
|
1035
|
+
expected[Date.parse(key)] = i == 1 ? 1 : 0
|
1036
|
+
end
|
1037
|
+
assert_equal expected, call_method(method, :created_at, options.merge(series: true, time_zone: time_zone ? "Pacific Time (US & Canada)" : nil, range: Time.parse(range_start)..Time.parse(range_end)))
|
1020
1038
|
end
|
1021
1039
|
|
1022
1040
|
def this_year
|
@@ -1027,6 +1045,10 @@ module TestGroupdate
|
|
1027
1045
|
ActiveSupport::TimeZone["UTC"]
|
1028
1046
|
end
|
1029
1047
|
|
1048
|
+
def pt
|
1049
|
+
ActiveSupport::TimeZone["Pacific Time (US & Canada)"]
|
1050
|
+
end
|
1051
|
+
|
1030
1052
|
def brasilia
|
1031
1053
|
ActiveSupport::TimeZone["Brasilia"]
|
1032
1054
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupdate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|