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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00f2a25fe5b1a02e4b8a6e2b483e407ed4d5d76e
4
- data.tar.gz: 5f6c81ee95f601a8ad189d706c53b5e57cf6d483
3
+ metadata.gz: 89762e723508e5431f4f03eccc43b9a1edb63847
4
+ data.tar.gz: e78b217c7424bb628b284a143f8004d0ef159d93
5
5
  SHA512:
6
- metadata.gz: e3f980694ad4a61ae5a3915720f8e90a4d01fd62e865aa5db751f06c3fb4bc87b3b91f0681cf0d49ba39287b08aeb1ba7bbfe78b86d1fe3d8554b3f4754e6113
7
- data.tar.gz: 6700771e7de2ad8e0153e58efaa417fcbc73e5fd8f55beaa5af5314fc54d46425ea2d9ecacbed8a28a71f49931fa64f717f657b51da26e9203c2ed2b3f99fae9
6
+ metadata.gz: 3de4b5d5d7d05a10c77ef8b098bca4abbf7495cadd91381088f92bb299131ffac9b3c1cf86ada1ab0e1f202ae404f56ba1cfaba18f1a91233c9f6c7b93dfbcf2
7
+ data.tar.gz: 917773b5b9c2a6c42ff061f11dc7fc31ad50313d53e5140b828c91dc8331abd3be2ee49ec3ba627e8f8d3749991d7535f94a953ff4459ad9c9a571667ead05a8
@@ -1,3 +1,7 @@
1
+ # 2.0.1
2
+
3
+ - Use time zone instead of UTC for results
4
+
1
5
  # 2.0.0
2
6
 
3
7
  - Returns entire series by default
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:
@@ -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 :start option"
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
- end
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, time_zone, range, week_start, day_start)
79
+ Series.new(group, field, column, time_zone_object, range, week_start, day_start)
79
80
  else
80
81
  group
81
82
  end
@@ -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).utc }
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.map{|s| s.to_time.utc }
79
+ series
80
80
  else
81
81
  []
82
82
  end
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -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 = {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groupdate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane