groupdate 6.0.1 → 6.1.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 +4 -0
- data/README.md +6 -0
- data/lib/groupdate/magic.rb +1 -1
- data/lib/groupdate/series_builder.rb +33 -29
- data/lib/groupdate/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95d89de45bf1e6828b313f8181a5b68ba1ba7c32b173bc0a9c15290e7aec9cd6
|
4
|
+
data.tar.gz: e39b910219e23681dac05095ae0a6a81de70e846f7bc089bb45d0bd3a4849211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74a5a30dc46ad1f8087889dcd5ef19f995e60b691adaadf8a01576b14086085ee9dece80bc45e8b14bac0dd001f51ca6015e4b503c339cc2ae20c9f8b7dc10f9
|
7
|
+
data.tar.gz: 1067a26e0e5b99c36a93e501eda2f152056e46b8c96ae6cfd1468464cebf0113455fdcbad288730d31d9b527b05411a6c20fb71de6575501b183d07e3aed3d36
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -119,6 +119,12 @@ To get a specific time range, use:
|
|
119
119
|
User.group_by_day(:created_at, range: 2.weeks.ago.midnight..Time.now).count
|
120
120
|
```
|
121
121
|
|
122
|
+
To expand the range to the start and end of the time period, use:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
User.group_by_day(:created_at, range: 2.weeks.ago..Time.now, expand_range: true).count
|
126
|
+
```
|
127
|
+
|
122
128
|
To get the most recent time periods, use:
|
123
129
|
|
124
130
|
```ruby
|
data/lib/groupdate/magic.rb
CHANGED
@@ -22,7 +22,7 @@ module Groupdate
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def validate_keywords
|
25
|
-
known_keywords = [:time_zone, :series, :format, :locale, :range, :reverse]
|
25
|
+
known_keywords = [:time_zone, :series, :format, :locale, :range, :expand_range, :reverse]
|
26
26
|
|
27
27
|
if %i[week day_of_week].include?(period)
|
28
28
|
known_keywords << :week_start
|
@@ -123,32 +123,32 @@ module Groupdate
|
|
123
123
|
exclude_end = true
|
124
124
|
end
|
125
125
|
|
126
|
+
if options[:expand_range]
|
127
|
+
start = round_time(start) if start
|
128
|
+
if finish && !(finish == round_time(finish) && exclude_end)
|
129
|
+
finish = round_time(finish) + step
|
130
|
+
exclude_end = true
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
126
134
|
time_range = Range.new(start, finish, exclude_end)
|
127
135
|
elsif !time_range && options[:last]
|
128
|
-
|
129
|
-
|
130
|
-
elsif period == :custom
|
131
|
-
step = n_seconds
|
132
|
-
elsif 1.respond_to?(period)
|
133
|
-
step = 1.send(period)
|
134
|
-
else
|
135
|
-
raise ArgumentError, "Cannot use last option with #{period}"
|
136
|
-
end
|
137
|
-
if step
|
138
|
-
# loop instead of multiply to change start_at - see #151
|
139
|
-
start_at = now
|
140
|
-
(options[:last].to_i - 1).times do
|
141
|
-
start_at -= step
|
142
|
-
end
|
136
|
+
step = step()
|
137
|
+
raise ArgumentError, "Cannot use last option with #{period}" unless step
|
143
138
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
# extend to end of current period
|
149
|
-
round_time(start_at)...(round_time(now) + step)
|
150
|
-
end
|
139
|
+
# loop instead of multiply to change start_at - see #151
|
140
|
+
start_at = now
|
141
|
+
(options[:last].to_i - 1).times do
|
142
|
+
start_at -= step
|
151
143
|
end
|
144
|
+
|
145
|
+
time_range =
|
146
|
+
if options[:current] == false
|
147
|
+
round_time(start_at - step)...round_time(now)
|
148
|
+
else
|
149
|
+
# extend to end of current period
|
150
|
+
round_time(start_at)...(round_time(now) + step)
|
151
|
+
end
|
152
152
|
end
|
153
153
|
time_range
|
154
154
|
end
|
@@ -210,13 +210,7 @@ module Groupdate
|
|
210
210
|
if time_range.begin
|
211
211
|
series = [round_time(time_range.begin)]
|
212
212
|
|
213
|
-
|
214
|
-
step = 3.months
|
215
|
-
elsif period == :custom
|
216
|
-
step = n_seconds
|
217
|
-
else
|
218
|
-
step = 1.send(period)
|
219
|
-
end
|
213
|
+
step = step()
|
220
214
|
|
221
215
|
last_step = series.last
|
222
216
|
day_start_hour = day_start / 3600
|
@@ -273,6 +267,16 @@ module Groupdate
|
|
273
267
|
end
|
274
268
|
end
|
275
269
|
|
270
|
+
def step
|
271
|
+
if period == :quarter
|
272
|
+
3.months
|
273
|
+
elsif period == :custom
|
274
|
+
n_seconds
|
275
|
+
elsif 1.respond_to?(period)
|
276
|
+
1.send(period)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
276
280
|
def handle_multiple(data, series, multiple_groups, group_index)
|
277
281
|
reverse = options[:reverse]
|
278
282
|
|
data/lib/groupdate/version.rb
CHANGED
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: 6.0
|
4
|
+
version: 6.1.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: 2022-
|
11
|
+
date: 2022-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
68
|
+
rubygems_version: 3.3.7
|
69
69
|
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: The simplest way to group temporal data
|