groupdate 2.5.1 → 2.5.2

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
  SHA1:
3
- metadata.gz: e50a64260e2d0aa3ce8675cce56a1b074c4e1bff
4
- data.tar.gz: 08366d6b98a953349a1dff0e1585de45d3f4ff05
3
+ metadata.gz: 034c6a221a1b829973a2144cc5cd08a8553b004e
4
+ data.tar.gz: bf9e8fcc113763a0362b1d14e027033f5abca1dc
5
5
  SHA512:
6
- metadata.gz: cc9ae556196bbb405d1524d55b770a67b4b68647fc54332636e01b65e325221158cbb90bfd4868d47e7a6c8d86f267e507da0bb9213aff7c0322d8943214096f
7
- data.tar.gz: 63b2478668b5f76a29b4c72beffa227402eedd5671a9b4da7ad88a748373847e6ae5c181b64c0ec692c637c3914313e2731919e8356f0b03e33e3733313a13a1
6
+ metadata.gz: b394b615b8f63f0c5666ea48fa45a4a6260b9c86c928c60d948d1f4b845a92e58fa6015189927a94eae945c3f2c24de43cff49a889b53b0583ab1b313c95753e
7
+ data.tar.gz: 77468a2939c378c27323a13115f5129d2ff38b35b6f5e34d9be8c67ff0e346981b835adc54ccb000a59b3d842b857bb6094dee2f34631608c83b2462f8f19024
@@ -1,3 +1,7 @@
1
+ ## 2.5.2
2
+
3
+ - Added `dates` option to return dates for day, week, month, quarter, and year
4
+
1
5
  ## 2.5.1
2
6
 
3
7
  - Added `group_by_quarter`
data/README.md CHANGED
@@ -136,7 +136,24 @@ or
136
136
  User.group_by_day(:created_at).order("day desc").count
137
137
  ```
138
138
 
139
- ### Format
139
+ ### Keys
140
+
141
+ To get keys as date objects instead of time objects, use:
142
+
143
+ ```ruby
144
+ User.group_by_day(:created_at, dates: true).count
145
+ # {
146
+ # 2013-03-10 => 70,
147
+ # 2013-03-17 => 54,
148
+ # 2013-03-24 => 80
149
+ # }
150
+ ```
151
+
152
+ or make this the default with:
153
+
154
+ ```ruby
155
+ Groupdate.dates = true
156
+ ```
140
157
 
141
158
  To get keys in a different format, use:
142
159
 
@@ -9,9 +9,10 @@ module Groupdate
9
9
  FIELDS = PERIODS
10
10
  METHODS = PERIODS.map { |v| :"group_by_#{v}" }
11
11
 
12
- mattr_accessor :week_start, :day_start, :time_zone
12
+ mattr_accessor :week_start, :day_start, :time_zone, :dates
13
13
  self.week_start = :sun
14
14
  self.day_start = 0
15
+ self.dates = false
15
16
  end
16
17
 
17
18
  require "groupdate/enumerable"
@@ -254,6 +254,8 @@ module Groupdate
254
254
  I18n.localize(key, format: options[:format], locale: locale)
255
255
  end
256
256
  end
257
+ elsif (options[:dates] || (Groupdate.dates && !options.key?(:dates))) && [:day, :week, :month, :quarter, :year].include?(field)
258
+ lambda { |k| k.to_date }
257
259
  else
258
260
  lambda { |k| k }
259
261
  end
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "2.5.1"
2
+ VERSION = "2.5.2"
3
3
  end
@@ -906,6 +906,13 @@ module TestGroupdate
906
906
  assert_equal 2, User.group_by_day(:created_at, carry_forward: true).count[utc.parse("2014-05-02 00:00:00 UTC")]
907
907
  end
908
908
 
909
+ # dates
910
+
911
+ def test_dates
912
+ create_user "2014-03-01 12:00:00 UTC"
913
+ assert_equal ({Date.parse("2014-03-01") => 1}), User.group_by_day(:created_at, dates: true).count
914
+ end
915
+
909
916
  # helpers
910
917
 
911
918
  def assert_format(method, expected, format, options = {})
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: 2.5.1
4
+ version: 2.5.2
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-02-04 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport