groupdate 2.5.1 → 2.5.2
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 +18 -1
- data/lib/groupdate.rb +2 -1
- data/lib/groupdate/magic.rb +2 -0
- data/lib/groupdate/version.rb +1 -1
- data/test/test_helper.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 034c6a221a1b829973a2144cc5cd08a8553b004e
|
4
|
+
data.tar.gz: bf9e8fcc113763a0362b1d14e027033f5abca1dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b394b615b8f63f0c5666ea48fa45a4a6260b9c86c928c60d948d1f4b845a92e58fa6015189927a94eae945c3f2c24de43cff49a889b53b0583ab1b313c95753e
|
7
|
+
data.tar.gz: 77468a2939c378c27323a13115f5129d2ff38b35b6f5e34d9be8c67ff0e346981b835adc54ccb000a59b3d842b857bb6094dee2f34631608c83b2462f8f19024
|
data/CHANGELOG.md
CHANGED
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
|
-
###
|
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
|
|
data/lib/groupdate.rb
CHANGED
@@ -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"
|
data/lib/groupdate/magic.rb
CHANGED
@@ -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
|
data/lib/groupdate/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|