groupdate 6.0.1 → 6.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12cfc48ae509ac20872022dd07429dd7bd8f24a5bfd81dcb16242f3519cb5385
4
- data.tar.gz: 3079f700f956f141184fbc5bc8244ad90380804cea9f15fef51300985380d13e
3
+ metadata.gz: 95d89de45bf1e6828b313f8181a5b68ba1ba7c32b173bc0a9c15290e7aec9cd6
4
+ data.tar.gz: e39b910219e23681dac05095ae0a6a81de70e846f7bc089bb45d0bd3a4849211
5
5
  SHA512:
6
- metadata.gz: 64b4e317731bc0032a914e4f07ca751ee276e41b7a30a2113bff9d9f2437196916c68e5f1f699c2e107861d0022b712b32315132cd0f530bb7caad5f41955e45
7
- data.tar.gz: ea085f2e6985f4df40f591333935b88f8c59b2be87943f39241254dbbc8ac18cc1aaa2b54030880a804117ecdc0451a65463b07ea758d3fc93d99697a11a5711
6
+ metadata.gz: 74a5a30dc46ad1f8087889dcd5ef19f995e60b691adaadf8a01576b14086085ee9dece80bc45e8b14bac0dd001f51ca6015e4b503c339cc2ae20c9f8b7dc10f9
7
+ data.tar.gz: 1067a26e0e5b99c36a93e501eda2f152056e46b8c96ae6cfd1468464cebf0113455fdcbad288730d31d9b527b05411a6c20fb71de6575501b183d07e3aed3d36
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 6.1.0 (2022-04-05)
2
+
3
+ - Added `expand_range` option
4
+
1
5
  ## 6.0.1 (2022-01-16)
2
6
 
3
7
  - Fixed incorrect results (error before 6.0) with `includes` with Active Record 6.1+
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
@@ -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
- if period == :quarter
129
- step = 3.months
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
- time_range =
145
- if options[:current] == false
146
- round_time(start_at - step)...round_time(now)
147
- else
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
- if period == :quarter
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
 
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "6.0.1"
2
+ VERSION = "6.1.0"
3
3
  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: 6.0.1
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-01-16 00:00:00.000000000 Z
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.2.32
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