groupdate 2.0.0 → 2.0.1
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 +8 -0
- data/lib/groupdate/scopes.rb +4 -3
- data/lib/groupdate/series.rb +2 -2
- data/lib/groupdate/version.rb +1 -1
- data/test/test_helper.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89762e723508e5431f4f03eccc43b9a1edb63847
|
4
|
+
data.tar.gz: e78b217c7424bb628b284a143f8004d0ef159d93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3de4b5d5d7d05a10c77ef8b098bca4abbf7495cadd91381088f92bb299131ffac9b3c1cf86ada1ab0e1f202ae404f56ba1cfaba18f1a91233c9f6c7b93dfbcf2
|
7
|
+
data.tar.gz: 917773b5b9c2a6c42ff061f11dc7fc31ad50313d53e5140b828c91dc8331abd3be2ee49ec3ba627e8f8d3749991d7535f94a953ff4459ad9c9a571667ead05a8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -97,6 +97,14 @@ or
|
|
97
97
|
User.group_by_day(:created_at, day_start: 2).count
|
98
98
|
```
|
99
99
|
|
100
|
+
### Time Range
|
101
|
+
|
102
|
+
To get a specific time range, use:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
User.group_by_day(:created_at, range: 2.weeks.ago.midnight..Time.now).count
|
106
|
+
```
|
107
|
+
|
100
108
|
## Installation
|
101
109
|
|
102
110
|
Add this line to your application’s Gemfile:
|
data/lib/groupdate/scopes.rb
CHANGED
@@ -13,6 +13,7 @@ module Groupdate
|
|
13
13
|
column = connection.quote_table_name(args[0])
|
14
14
|
time_zone = args[1] || options[:time_zone] || Groupdate.time_zone || Time.zone || "Etc/UTC"
|
15
15
|
if time_zone.is_a?(ActiveSupport::TimeZone) or time_zone = ActiveSupport::TimeZone[time_zone]
|
16
|
+
time_zone_object = time_zone
|
16
17
|
time_zone = time_zone.tzinfo.name
|
17
18
|
else
|
18
19
|
raise "Unrecognized time zone"
|
@@ -21,7 +22,7 @@ module Groupdate
|
|
21
22
|
# for week
|
22
23
|
week_start = [:mon, :tue, :wed, :thu, :fri, :sat, :sun].index((options[:week_start] || options[:start] || Groupdate.week_start).to_sym)
|
23
24
|
if field == "week" and !week_start
|
24
|
-
raise "Unrecognized :
|
25
|
+
raise "Unrecognized :week_start option"
|
25
26
|
end
|
26
27
|
|
27
28
|
# for day
|
@@ -53,7 +54,7 @@ module Groupdate
|
|
53
54
|
"%Y-%m-01 00:00:00"
|
54
55
|
else # year
|
55
56
|
"%Y-01-01 00:00:00"
|
56
|
-
|
57
|
+
end
|
57
58
|
|
58
59
|
["DATE_ADD(CONVERT_TZ(DATE_FORMAT(CONVERT_TZ(DATE_SUB(#{column}, INTERVAL #{day_start} HOUR), '+00:00', ?), '#{format}'), ?, '+00:00'), INTERVAL #{day_start} HOUR)", time_zone, time_zone]
|
59
60
|
end
|
@@ -75,7 +76,7 @@ module Groupdate
|
|
75
76
|
group = group(Groupdate::OrderHack.new(sanitize_sql_array(query), field, time_zone))
|
76
77
|
range = args[2] || options[:range] || true
|
77
78
|
unless options[:series] == false
|
78
|
-
Series.new(group, field, column,
|
79
|
+
Series.new(group, field, column, time_zone_object, range, week_start, day_start)
|
79
80
|
else
|
80
81
|
group
|
81
82
|
end
|
data/lib/groupdate/series.rb
CHANGED
@@ -23,7 +23,7 @@ module Groupdate
|
|
23
23
|
when "day_of_week", "hour_of_day"
|
24
24
|
lambda{|k| k.to_i }
|
25
25
|
else
|
26
|
-
lambda{|k| (k.is_a?(String) ? utc.parse(k) : k.to_time).
|
26
|
+
lambda{|k| (k.is_a?(String) ? utc.parse(k) : k.to_time).in_time_zone(@time_zone) }
|
27
27
|
end
|
28
28
|
|
29
29
|
count = Hash[ count.map{|k, v| [cast_method.call(k), v] } ]
|
@@ -76,7 +76,7 @@ module Groupdate
|
|
76
76
|
series << series.last + step
|
77
77
|
end
|
78
78
|
|
79
|
-
series
|
79
|
+
series
|
80
80
|
else
|
81
81
|
[]
|
82
82
|
end
|
data/lib/groupdate/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -474,6 +474,12 @@ module TestGroupdate
|
|
474
474
|
assert_empty User.where("id = 0").group_by_day(:created_at).count
|
475
475
|
end
|
476
476
|
|
477
|
+
def test_time_zone
|
478
|
+
create_user "2013-05-01 00:00:00 UTC"
|
479
|
+
time_zone = "Pacific Time (US & Canada)"
|
480
|
+
assert_equal time_zone, User.group_by_day(:created_at, time_zone: time_zone).count.keys.first.time_zone.name
|
481
|
+
end
|
482
|
+
|
477
483
|
# helpers
|
478
484
|
|
479
485
|
def assert_result_time(method, expected, time_str, time_zone = false, options = {})
|