groupdate 6.0.1 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12cfc48ae509ac20872022dd07429dd7bd8f24a5bfd81dcb16242f3519cb5385
4
- data.tar.gz: 3079f700f956f141184fbc5bc8244ad90380804cea9f15fef51300985380d13e
3
+ metadata.gz: ee8a614ef0b4d869d534df2d0bb972296d26edd2839e430547d54a8ffb22a2b0
4
+ data.tar.gz: f15a380692b7726895a3083a4bd5e013610f6583bce614ede9e2fefd06d30f60
5
5
  SHA512:
6
- metadata.gz: 64b4e317731bc0032a914e4f07ca751ee276e41b7a30a2113bff9d9f2437196916c68e5f1f699c2e107861d0022b712b32315132cd0f530bb7caad5f41955e45
7
- data.tar.gz: ea085f2e6985f4df40f591333935b88f8c59b2be87943f39241254dbbc8ac18cc1aaa2b54030880a804117ecdc0451a65463b07ea758d3fc93d99697a11a5711
6
+ metadata.gz: 6145ca25662c5df8cab197d570a1bf1b26e7492e0404faba390d4af793992fbb3405c4995136b6818ac0be6a6bc3ff4da2ee8288860fd5c2b9b4fadad036c9e6
7
+ data.tar.gz: aaccec08b13902b51c2eb8180bb5a0807e6d2905fdd5b658a3dfab74dd2b4f2fed96dffc2dc42edcf61fe0a4eb20e21efca6a86ef55402a1f9d594d7eecb77e1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 6.2.0 (2023-01-29)
2
+
3
+ - Added support for async methods with Active Record 7.1
4
+
5
+ ## 6.1.0 (2022-04-05)
6
+
7
+ - Added `expand_range` option
8
+
1
9
  ## 6.0.1 (2022-01-16)
2
10
 
3
11
  - 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
@@ -125,6 +125,10 @@ module Groupdate
125
125
  end
126
126
 
127
127
  def perform(relation, result, default_value:)
128
+ if defined?(ActiveRecord::Promise) && result.is_a?(ActiveRecord::Promise)
129
+ return result.then { |r| perform(relation, r, default_value: default_value) }
130
+ end
131
+
128
132
  multiple_groups = relation.group_values.size > 1
129
133
 
130
134
  check_nils(result, multiple_groups, relation)
@@ -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.2.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.2.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: 2023-01-30 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.4.1
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: The simplest way to group temporal data