groupdate 4.1.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -33
- data/CONTRIBUTING.md +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +24 -11
- data/lib/groupdate/enumerable.rb +11 -10
- data/lib/groupdate/magic.rb +4 -2
- data/lib/groupdate/query_methods.rb +2 -0
- data/lib/groupdate/relation_builder.rb +8 -0
- data/lib/groupdate/series_builder.rb +7 -3
- data/lib/groupdate/version.rb +1 -1
- data/lib/groupdate.rb +1 -1
- metadata +14 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c661470fa1d3e85d4cff490be69845b175f5c095956ae674bda74e25e8713d1e
|
|
4
|
+
data.tar.gz: d2f4a2adb3dec4d73fdfc36302514c7c9c051766bb2703057b4074e3f480223c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7e3309e4f687cb88839c23d07f6ad9dce57ee3f8f18c335d695d79fe4c0d7fe4e236d1362071180ba07daf3eb6edd62ace05f4d15e0f4392c2dc48e81139c17
|
|
7
|
+
data.tar.gz: 2b1682b63429bb482b01cb8f50a5bd0ab03a0677b9a806244c7d26054579611b1678f056c713d23278cd5cd3e8616def5c77d0897caccda7c5a6d297e4eaa863
|
data/CHANGELOG.md
CHANGED
|
@@ -1,25 +1,42 @@
|
|
|
1
|
-
## 4.
|
|
1
|
+
## 4.3.0 (2019-12-26)
|
|
2
|
+
|
|
3
|
+
- Fixed error with empty results in Ruby 2.7
|
|
4
|
+
- Fixed deprecation warnings in Ruby 2.7
|
|
5
|
+
- Deprecated positional arguments for time zone and range
|
|
6
|
+
|
|
7
|
+
## 4.2.0 (2019-10-28)
|
|
8
|
+
|
|
9
|
+
- Added `day_of_year`
|
|
10
|
+
- Dropped support for Rails 4.2
|
|
11
|
+
|
|
12
|
+
## 4.1.2 (2019-05-26)
|
|
13
|
+
|
|
14
|
+
- Fixed error with empty data and `current: false`
|
|
15
|
+
- Fixed error in time zone check for Rails < 5.2
|
|
16
|
+
- Prevent infinite loop with endless ranges
|
|
17
|
+
|
|
18
|
+
## 4.1.1 (2018-12-11)
|
|
2
19
|
|
|
3
20
|
- Made column resolution consistent with `group`
|
|
4
21
|
- Added support for `alias_attribute`
|
|
5
22
|
|
|
6
|
-
## 4.1.0
|
|
23
|
+
## 4.1.0 (2018-11-04)
|
|
7
24
|
|
|
8
25
|
- Many performance improvements
|
|
9
26
|
- Added check for consistent time zone info
|
|
10
27
|
- Fixed error message for invalid queries with MySQL and SQLite
|
|
11
28
|
- Fixed issue with enumerable methods ignoring nils
|
|
12
29
|
|
|
13
|
-
## 4.0.2
|
|
30
|
+
## 4.0.2 (2018-10-15)
|
|
14
31
|
|
|
15
32
|
- Make `current` option work without `last`
|
|
16
33
|
- Fixed default value for `maximum`, `minimum`, and `average` (periods with no results now return `nil` instead of `0`, pass `default_value: 0` for previous behavior)
|
|
17
34
|
|
|
18
|
-
## 4.0.1
|
|
35
|
+
## 4.0.1 (2018-05-03)
|
|
19
36
|
|
|
20
37
|
- Fixed incorrect range with `last` option near time change
|
|
21
38
|
|
|
22
|
-
## 4.0.0
|
|
39
|
+
## 4.0.0 (2018-02-21)
|
|
23
40
|
|
|
24
41
|
- Custom calculation methods are supported by default - `groupdate_calculation_methods` is no longer needed
|
|
25
42
|
|
|
@@ -31,37 +48,37 @@ Breaking changes
|
|
|
31
48
|
- `week_start` now affects `day_of_week`
|
|
32
49
|
- Removed support for `reverse_order` (was never supported in Rails 5)
|
|
33
50
|
|
|
34
|
-
## 3.2.1
|
|
51
|
+
## 3.2.1 (2018-02-21)
|
|
35
52
|
|
|
36
53
|
- Added `minute_of_hour`
|
|
37
54
|
- Added support for `unscoped`
|
|
38
55
|
|
|
39
|
-
## 3.2.0
|
|
56
|
+
## 3.2.0 (2017-01-30)
|
|
40
57
|
|
|
41
58
|
- Added limited support for SQLite
|
|
42
59
|
|
|
43
|
-
## 3.1.1
|
|
60
|
+
## 3.1.1 (2016-10-25)
|
|
44
61
|
|
|
45
62
|
- Fixed `current: false`
|
|
46
63
|
- Fixed `last` with `group_by_quarter`
|
|
47
64
|
- Raise `ArgumentError` when `last` option is not supported
|
|
48
65
|
|
|
49
|
-
## 3.1.0
|
|
66
|
+
## 3.1.0 (2016-10-22)
|
|
50
67
|
|
|
51
68
|
- Better support for date columns with `time_zone: false`
|
|
52
69
|
- Better date range handling for `range` option
|
|
53
70
|
|
|
54
|
-
## 3.0.2
|
|
71
|
+
## 3.0.2 (2016-08-09)
|
|
55
72
|
|
|
56
73
|
- Fixed `group_by_period` with associations
|
|
57
74
|
- Fixed `week_start` option for enumerables
|
|
58
75
|
|
|
59
|
-
## 3.0.1
|
|
76
|
+
## 3.0.1 (2016-07-13)
|
|
60
77
|
|
|
61
78
|
- Added support for Redshift
|
|
62
79
|
- Fix for infinite loop in certain cases for Rails 5
|
|
63
80
|
|
|
64
|
-
## 3.0.0
|
|
81
|
+
## 3.0.0 (2016-05-30)
|
|
65
82
|
|
|
66
83
|
Breaking changes
|
|
67
84
|
|
|
@@ -69,16 +86,16 @@ Breaking changes
|
|
|
69
86
|
- Array and hash methods no longer return the entire series by default. Use `series: true` for the previous behavior.
|
|
70
87
|
- The `series: false` option now returns the correct types and order, and plays nicely with other options.
|
|
71
88
|
|
|
72
|
-
## 2.5.3
|
|
89
|
+
## 2.5.3 (2016-04-28)
|
|
73
90
|
|
|
74
91
|
- All tests green with `mysql` gem
|
|
75
92
|
- Added support for decimal day start
|
|
76
93
|
|
|
77
|
-
## 2.5.2
|
|
94
|
+
## 2.5.2 (2016-02-16)
|
|
78
95
|
|
|
79
96
|
- Added `dates` option to return dates for day, week, month, quarter, and year
|
|
80
97
|
|
|
81
|
-
## 2.5.1
|
|
98
|
+
## 2.5.1 (2016-02-03)
|
|
82
99
|
|
|
83
100
|
- Added `group_by_quarter`
|
|
84
101
|
- Added `default_value` option
|
|
@@ -86,13 +103,13 @@ Breaking changes
|
|
|
86
103
|
- Raise `ArgumentError` if no field specified
|
|
87
104
|
- Added support for ActiveRecord 5 beta
|
|
88
105
|
|
|
89
|
-
## 2.5.0
|
|
106
|
+
## 2.5.0 (2015-09-29)
|
|
90
107
|
|
|
91
108
|
- Added `group_by_period` method
|
|
92
109
|
- Added `current` option
|
|
93
110
|
- Raise `ArgumentError` if no block given to enumerable
|
|
94
111
|
|
|
95
|
-
## 2.4.0
|
|
112
|
+
## 2.4.0 (2014-12-28)
|
|
96
113
|
|
|
97
114
|
- Added localization
|
|
98
115
|
- Added `carry_forward` option
|
|
@@ -100,77 +117,77 @@ Breaking changes
|
|
|
100
117
|
- Fixed issue w/ Brasilia Summer Time
|
|
101
118
|
- Fixed issues w/ ActiveRecord 4.2
|
|
102
119
|
|
|
103
|
-
## 2.3.0
|
|
120
|
+
## 2.3.0 (2014-08-31)
|
|
104
121
|
|
|
105
122
|
- Raise error when ActiveRecord::Base.default_timezone is not `:utc`
|
|
106
123
|
- Added `day_of_month`
|
|
107
124
|
- Added `month_of_year`
|
|
108
125
|
- Do not quote column name
|
|
109
126
|
|
|
110
|
-
## 2.2.1
|
|
127
|
+
## 2.2.1 (2014-06-23)
|
|
111
128
|
|
|
112
129
|
- Fixed ActiveRecord 3 associations
|
|
113
130
|
|
|
114
|
-
## 2.2.0
|
|
131
|
+
## 2.2.0 (2014-06-22)
|
|
115
132
|
|
|
116
133
|
- Added support for arrays and hashes
|
|
117
134
|
|
|
118
|
-
## 2.1.1
|
|
135
|
+
## 2.1.1 (2014-05-17)
|
|
119
136
|
|
|
120
137
|
- Fixed format option with multiple groups
|
|
121
138
|
- Better error message if time zone support is missing for MySQL
|
|
122
139
|
|
|
123
|
-
## 2.1.0
|
|
140
|
+
## 2.1.0 (2014-03-16)
|
|
124
141
|
|
|
125
142
|
- Added last option
|
|
126
143
|
- Added format option
|
|
127
144
|
|
|
128
|
-
## 2.0.4
|
|
145
|
+
## 2.0.4 (2014-03-12)
|
|
129
146
|
|
|
130
147
|
- Added multiple groups
|
|
131
148
|
- Added order
|
|
132
149
|
- Subsequent methods no longer modify relation
|
|
133
150
|
|
|
134
|
-
## 2.0.3
|
|
151
|
+
## 2.0.3 (2014-03-11)
|
|
135
152
|
|
|
136
153
|
- Implemented respond_to?
|
|
137
154
|
|
|
138
|
-
## 2.0.2
|
|
155
|
+
## 2.0.2 (2014-03-11)
|
|
139
156
|
|
|
140
157
|
- where, joins, and includes no longer need to be before the group_by method
|
|
141
158
|
|
|
142
|
-
## 2.0.1
|
|
159
|
+
## 2.0.1 (2014-03-07)
|
|
143
160
|
|
|
144
161
|
- Use time zone instead of UTC for results
|
|
145
162
|
|
|
146
|
-
## 2.0.0
|
|
163
|
+
## 2.0.0 (2014-03-07)
|
|
147
164
|
|
|
148
165
|
- Returns entire series by default
|
|
149
166
|
- Added day_start option
|
|
150
167
|
- Better interface
|
|
151
168
|
|
|
152
|
-
## 1.0.5
|
|
169
|
+
## 1.0.5 (2014-03-06)
|
|
153
170
|
|
|
154
171
|
- Added global time_zone option
|
|
155
172
|
|
|
156
|
-
## 1.0.4
|
|
173
|
+
## 1.0.4 (2013-07-20)
|
|
157
174
|
|
|
158
175
|
- Added global week_start option
|
|
159
176
|
- Fixed bug with NULL values and series
|
|
160
177
|
|
|
161
|
-
## 1.0.3
|
|
178
|
+
## 1.0.3 (2013-07-05)
|
|
162
179
|
|
|
163
180
|
- Fixed deprecation warning when used with will_paginate
|
|
164
181
|
- Fixed bug with DateTime series
|
|
165
182
|
|
|
166
|
-
## 1.0.2
|
|
183
|
+
## 1.0.2 (2013-06-10)
|
|
167
184
|
|
|
168
185
|
- Added :start option for custom week start for group_by_week
|
|
169
186
|
|
|
170
|
-
## 1.0.1
|
|
187
|
+
## 1.0.1 (2013-06-03)
|
|
171
188
|
|
|
172
189
|
- Fixed series for Rails < 3.2 and MySQL
|
|
173
190
|
|
|
174
|
-
## 1.0.0
|
|
191
|
+
## 1.0.0 (2013-05-15)
|
|
175
192
|
|
|
176
193
|
- First major release
|
data/CONTRIBUTING.md
CHANGED
|
@@ -57,7 +57,7 @@ brew services start mysql
|
|
|
57
57
|
|
|
58
58
|
# create databases
|
|
59
59
|
createdb groupdate_test
|
|
60
|
-
|
|
60
|
+
mysqladmin create groupdate_test
|
|
61
61
|
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
|
|
62
62
|
|
|
63
63
|
# clone the repo and run the tests
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -17,7 +17,17 @@ Supports PostgreSQL, MySQL, and Redshift, plus arrays and hashes (and limited su
|
|
|
17
17
|
|
|
18
18
|
[](https://travis-ci.org/ankane/groupdate)
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Add this line to your application’s Gemfile:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
gem 'groupdate'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For MySQL and SQLite, also follow [these instructions](#additional-instructions).
|
|
29
|
+
|
|
30
|
+
## Getting Started
|
|
21
31
|
|
|
22
32
|
```ruby
|
|
23
33
|
User.group_by_day(:created_at).count
|
|
@@ -46,9 +56,10 @@ and
|
|
|
46
56
|
- hour_of_day
|
|
47
57
|
- day_of_week (Sunday = 0, Monday = 1, etc)
|
|
48
58
|
- day_of_month
|
|
59
|
+
- day_of_year
|
|
49
60
|
- month_of_year
|
|
50
61
|
|
|
51
|
-
Use it anywhere you can use `group`. Works with `count`, `sum`, `minimum`, `maximum`, and `average`. For `median`, check out [ActiveMedian](https://github.com/ankane/active_median).
|
|
62
|
+
Use it anywhere you can use `group`. Works with `count`, `sum`, `minimum`, `maximum`, and `average`. For `median`, check out [ActiveMedian](https://github.com/ankane/active_median).
|
|
52
63
|
|
|
53
64
|
### Time Zones
|
|
54
65
|
|
|
@@ -215,23 +226,23 @@ Supports the same options as above
|
|
|
215
226
|
users.group_by_day(time_zone: time_zone) { |u| u.created_at }
|
|
216
227
|
```
|
|
217
228
|
|
|
218
|
-
|
|
229
|
+
Get the entire series with:
|
|
219
230
|
|
|
220
231
|
```ruby
|
|
221
|
-
|
|
232
|
+
users.group_by_day(series: true) { |u| u.created_at }
|
|
222
233
|
```
|
|
223
234
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
Add this line to your application’s Gemfile:
|
|
235
|
+
Count
|
|
227
236
|
|
|
228
237
|
```ruby
|
|
229
|
-
|
|
238
|
+
users.group_by_day { |u| u.created_at }.map { |k, v| [k, v.count] }.to_h
|
|
230
239
|
```
|
|
231
240
|
|
|
232
|
-
|
|
241
|
+
## Additional Instructions
|
|
233
242
|
|
|
234
|
-
|
|
243
|
+
### For MySQL
|
|
244
|
+
|
|
245
|
+
[Time zone support](https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html) must be installed on the server.
|
|
235
246
|
|
|
236
247
|
```sh
|
|
237
248
|
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
|
|
@@ -247,7 +258,7 @@ SELECT CONVERT_TZ(NOW(), '+00:00', 'Pacific/Honolulu');
|
|
|
247
258
|
|
|
248
259
|
It should return the time instead of `NULL`.
|
|
249
260
|
|
|
250
|
-
|
|
261
|
+
### For SQLite
|
|
251
262
|
|
|
252
263
|
Groupdate has limited support for SQLite.
|
|
253
264
|
|
|
@@ -301,3 +312,5 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
|
301
312
|
- Fix bugs and [submit pull requests](https://github.com/ankane/groupdate/pulls)
|
|
302
313
|
- Write, clarify, or fix documentation
|
|
303
314
|
- Suggest or add new features
|
|
315
|
+
|
|
316
|
+
To get started with development and testing, check out the [Contributing Guide](CONTRIBUTING.md).
|
data/lib/groupdate/enumerable.rb
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
module Enumerable
|
|
2
2
|
Groupdate::PERIODS.each do |period|
|
|
3
|
-
define_method :"group_by_#{period}" do |*args, &block|
|
|
3
|
+
define_method :"group_by_#{period}" do |*args, **options, &block|
|
|
4
4
|
if block
|
|
5
|
-
|
|
5
|
+
# TODO throw error in Groupdate 5
|
|
6
|
+
warn "[groupdate] positional arguments are deprecated" if args.any?
|
|
7
|
+
Groupdate::Magic::Enumerable.group_by(self, period, (args[0] || {}).merge(options), &block)
|
|
6
8
|
elsif respond_to?(:scoping)
|
|
7
|
-
scoping { @klass.send(:"group_by_#{period}", *args, &block) }
|
|
9
|
+
scoping { @klass.send(:"group_by_#{period}", *args, **options, &block) }
|
|
8
10
|
else
|
|
9
11
|
raise ArgumentError, "no block given"
|
|
10
12
|
end
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
def group_by_period(*args, &block)
|
|
16
|
+
def group_by_period(period, *args, **options, &block)
|
|
15
17
|
if block || !respond_to?(:scoping)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
options = options.dup
|
|
18
|
+
# TODO throw error in Groupdate 5
|
|
19
|
+
warn "[groupdate] positional arguments are deprecated" if args.any?
|
|
20
|
+
options = (args[0] || {}).merge(options)
|
|
20
21
|
# to_sym is unsafe on user input, so convert to strings
|
|
21
22
|
permitted_periods = ((options.delete(:permit) || Groupdate::PERIODS).map(&:to_sym) & Groupdate::PERIODS).map(&:to_s)
|
|
22
23
|
if permitted_periods.include?(period.to_s)
|
|
23
|
-
send("group_by_#{period}", options, &block)
|
|
24
|
+
send("group_by_#{period}", **options, &block)
|
|
24
25
|
else
|
|
25
26
|
raise ArgumentError, "Unpermitted period"
|
|
26
27
|
end
|
|
27
28
|
else
|
|
28
|
-
scoping { @klass.send(:group_by_period, *args, &block) }
|
|
29
|
+
scoping { @klass.send(:group_by_period, period, *args, **options, &block) }
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
32
|
end
|
data/lib/groupdate/magic.rb
CHANGED
|
@@ -13,6 +13,7 @@ module Groupdate
|
|
|
13
13
|
|
|
14
14
|
raise Groupdate::Error, "Unrecognized time zone" unless time_zone
|
|
15
15
|
raise Groupdate::Error, "Unrecognized :week_start option" if period == :week && !week_start
|
|
16
|
+
raise Groupdate::Error, "Cannot use endless range for :range option" if options[:range].is_a?(Range) && !options[:range].end
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def time_zone
|
|
@@ -86,7 +87,7 @@ module Groupdate
|
|
|
86
87
|
case period
|
|
87
88
|
when :day_of_week
|
|
88
89
|
lambda { |k| (k.to_i - 1 - week_start) % 7 }
|
|
89
|
-
when :hour_of_day, :day_of_month, :month_of_year, :minute_of_hour
|
|
90
|
+
when :hour_of_day, :day_of_month, :day_of_year, :month_of_year, :minute_of_hour
|
|
90
91
|
lambda { |k| k.to_i }
|
|
91
92
|
else
|
|
92
93
|
utc = ActiveSupport::TimeZone["UTC"]
|
|
@@ -110,7 +111,8 @@ module Groupdate
|
|
|
110
111
|
|
|
111
112
|
def time_zone_support?(relation)
|
|
112
113
|
if relation.connection.adapter_name =~ /mysql/i
|
|
113
|
-
|
|
114
|
+
# need to call klass for Rails < 5.2
|
|
115
|
+
sql = relation.klass.send(:sanitize_sql_array, ["SELECT CONVERT_TZ(NOW(), '+00:00', ?)", time_zone.tzinfo.name])
|
|
114
116
|
!relation.connection.select_all(sql).first.values.first.nil?
|
|
115
117
|
else
|
|
116
118
|
true
|
|
@@ -2,6 +2,8 @@ module Groupdate
|
|
|
2
2
|
module QueryMethods
|
|
3
3
|
Groupdate::PERIODS.each do |period|
|
|
4
4
|
define_method :"group_by_#{period}" do |field, time_zone = nil, range = nil, **options|
|
|
5
|
+
warn "[groupdate] positional arguments for time zone and range are deprecated" if time_zone || range
|
|
6
|
+
|
|
5
7
|
Groupdate::Magic::Relation.generate_relation(self,
|
|
6
8
|
period: period,
|
|
7
9
|
field: field,
|
|
@@ -31,6 +31,8 @@ module Groupdate
|
|
|
31
31
|
case period
|
|
32
32
|
when :day_of_week
|
|
33
33
|
["DAYOFWEEK(CONVERT_TZ(DATE_SUB(#{column}, INTERVAL #{day_start} second), '+00:00', ?)) - 1", time_zone]
|
|
34
|
+
when :day_of_year
|
|
35
|
+
["DAYOFYEAR(CONVERT_TZ(DATE_SUB(#{column}, INTERVAL #{day_start} second), '+00:00', ?))", time_zone]
|
|
34
36
|
when :hour_of_day
|
|
35
37
|
["(EXTRACT(HOUR from CONVERT_TZ(#{column}, '+00:00', ?)) + 24 - #{day_start / 3600}) % 24", time_zone]
|
|
36
38
|
when :minute_of_hour
|
|
@@ -66,6 +68,8 @@ module Groupdate
|
|
|
66
68
|
case period
|
|
67
69
|
when :day_of_week
|
|
68
70
|
["EXTRACT(DOW from #{column}::timestamptz AT TIME ZONE ? - INTERVAL '#{day_start} second')::integer", time_zone]
|
|
71
|
+
when :day_of_year
|
|
72
|
+
["EXTRACT(DOY from #{column}::timestamptz AT TIME ZONE ? - INTERVAL '#{day_start} second')::integer", time_zone]
|
|
69
73
|
when :hour_of_day
|
|
70
74
|
["EXTRACT(HOUR from #{column}::timestamptz AT TIME ZONE ? - INTERVAL '#{day_start} second')::integer", time_zone]
|
|
71
75
|
when :minute_of_hour
|
|
@@ -99,6 +103,8 @@ module Groupdate
|
|
|
99
103
|
"%d"
|
|
100
104
|
when :month_of_year
|
|
101
105
|
"%m"
|
|
106
|
+
when :day_of_year
|
|
107
|
+
"%j"
|
|
102
108
|
when :second
|
|
103
109
|
"%Y-%m-%d %H:%M:%S UTC"
|
|
104
110
|
when :minute
|
|
@@ -127,6 +133,8 @@ module Groupdate
|
|
|
127
133
|
["EXTRACT(MINUTE from CONVERT_TIMEZONE(?, #{column}::timestamp) - INTERVAL '#{day_start} second')::integer", time_zone]
|
|
128
134
|
when :day_of_month
|
|
129
135
|
["EXTRACT(DAY from CONVERT_TIMEZONE(?, #{column}::timestamp) - INTERVAL '#{day_start} second')::integer", time_zone]
|
|
136
|
+
when :day_of_year
|
|
137
|
+
["EXTRACT(DOY from CONVERT_TIMEZONE(?, #{column}::timestamp) - INTERVAL '#{day_start} second')::integer", time_zone]
|
|
130
138
|
when :month_of_year
|
|
131
139
|
["EXTRACT(MONTH from CONVERT_TIMEZONE(?, #{column}::timestamp) - INTERVAL '#{day_start} second')::integer", time_zone]
|
|
132
140
|
when :week # start on Sunday, not Redshift default Monday
|
|
@@ -79,6 +79,8 @@ module Groupdate
|
|
|
79
79
|
time.day
|
|
80
80
|
when :month_of_year
|
|
81
81
|
time.month
|
|
82
|
+
when :day_of_year
|
|
83
|
+
time.yday
|
|
82
84
|
else
|
|
83
85
|
raise Groupdate::Error, "Invalid period"
|
|
84
86
|
end
|
|
@@ -141,6 +143,8 @@ module Groupdate
|
|
|
141
143
|
0..59
|
|
142
144
|
when :day_of_month
|
|
143
145
|
1..31
|
|
146
|
+
when :day_of_year
|
|
147
|
+
1..366
|
|
144
148
|
when :month_of_year
|
|
145
149
|
1..12
|
|
146
150
|
else
|
|
@@ -158,14 +162,14 @@ module Groupdate
|
|
|
158
162
|
end
|
|
159
163
|
|
|
160
164
|
tr = sorted_keys.first..sorted_keys.last
|
|
161
|
-
if options[:current] == false && round_time(now) >= tr.last
|
|
165
|
+
if options[:current] == false && sorted_keys.any? && round_time(now) >= tr.last
|
|
162
166
|
tr = tr.first...round_time(now)
|
|
163
167
|
end
|
|
164
168
|
tr
|
|
165
169
|
end
|
|
166
170
|
|
|
167
|
-
if time_range.
|
|
168
|
-
series = [round_time(time_range.
|
|
171
|
+
if time_range.begin
|
|
172
|
+
series = [round_time(time_range.begin)]
|
|
169
173
|
|
|
170
174
|
if period == :quarter
|
|
171
175
|
step = 3.months
|
data/lib/groupdate/version.rb
CHANGED
data/lib/groupdate.rb
CHANGED
|
@@ -8,7 +8,7 @@ require "groupdate/magic"
|
|
|
8
8
|
module Groupdate
|
|
9
9
|
class Error < RuntimeError; end
|
|
10
10
|
|
|
11
|
-
PERIODS = [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :minute_of_hour, :day_of_month, :month_of_year]
|
|
11
|
+
PERIODS = [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :minute_of_hour, :day_of_month, :day_of_year, :month_of_year]
|
|
12
12
|
METHODS = PERIODS.map { |v| :"group_by_#{v}" } + [:group_by_period]
|
|
13
13
|
|
|
14
14
|
mattr_accessor :week_start, :day_start, :time_zone, :dates
|
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.
|
|
4
|
+
version: 4.3.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:
|
|
11
|
+
date: 2019-12-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '5'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '5'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: bundler
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -84,30 +84,30 @@ dependencies:
|
|
|
84
84
|
name: pg
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- - "
|
|
87
|
+
- - ">="
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
89
|
+
version: '0'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
|
-
- - "
|
|
94
|
+
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
96
|
+
version: '0'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: mysql2
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
|
101
|
-
- - "
|
|
101
|
+
- - ">="
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0
|
|
103
|
+
version: '0'
|
|
104
104
|
type: :development
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
|
-
- - "
|
|
108
|
+
- - ">="
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0
|
|
110
|
+
version: '0'
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
112
|
name: sqlite3
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -153,15 +153,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
153
153
|
requirements:
|
|
154
154
|
- - ">="
|
|
155
155
|
- !ruby/object:Gem::Version
|
|
156
|
-
version: '2.
|
|
156
|
+
version: '2.4'
|
|
157
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
requirements:
|
|
159
159
|
- - ">="
|
|
160
160
|
- !ruby/object:Gem::Version
|
|
161
161
|
version: '0'
|
|
162
162
|
requirements: []
|
|
163
|
-
|
|
164
|
-
rubygems_version: 2.7.6
|
|
163
|
+
rubygems_version: 3.1.2
|
|
165
164
|
signing_key:
|
|
166
165
|
specification_version: 4
|
|
167
166
|
summary: The simplest way to group temporal data
|