Commit c48050f2b2027b8e11831bf9d5b71a6d7fd74bcc
1 parent
359b596e
Exists in
master
and in
6 other branches
Merged 3.0 updates
Showing
6 changed files
with
244 additions
and
211 deletions
Show diff stats
CHANGELOG.md
1 | +## 3.0.0 [unreleased] | ||
2 | + | ||
3 | +Breaking changes | ||
4 | + | ||
5 | +- `Date` objects are now returned for day, week, month, quarter, and year by default. Use `dates: false` for the previous behavior, or change this globally with `Groupdate.dates = false`. | ||
6 | +- Array and hash methods no longer return the entire series by default. Use `series: true` for the previous behavior. | ||
7 | +- The `series: false` option now returns the correct types and order, and plays nicely with other options. | ||
8 | + | ||
1 | ## 2.5.3 | 9 | ## 2.5.3 |
2 | 10 | ||
3 | - All tests green with `mysql` gem | 11 | - All tests green with `mysql` gem |
README.md
@@ -7,7 +7,7 @@ The simplest way to group by: | @@ -7,7 +7,7 @@ The simplest way to group by: | ||
7 | - hour of the day | 7 | - hour of the day |
8 | - and more (complete list below) | 8 | - and more (complete list below) |
9 | 9 | ||
10 | -:tada: Time zones supported!! **the best part** | 10 | +:tada: Time zones - including daylight saving time - supported!! **the best part** |
11 | 11 | ||
12 | :cake: Get the entire series - **the other best part** | 12 | :cake: Get the entire series - **the other best part** |
13 | 13 | ||
@@ -19,14 +19,16 @@ Supports PostgreSQL and MySQL, plus arrays and hashes | @@ -19,14 +19,16 @@ Supports PostgreSQL and MySQL, plus arrays and hashes | ||
19 | 19 | ||
20 | :cupid: Goes hand in hand with [Chartkick](http://ankane.github.io/chartkick/) | 20 | :cupid: Goes hand in hand with [Chartkick](http://ankane.github.io/chartkick/) |
21 | 21 | ||
22 | +**Groupdate 3.0 was just released!** See [instructions for upgrading](#30). If you use Chartkick with Groupdate, we recommend Chartkick 2.0 and above. | ||
23 | + | ||
22 | ## Get Started | 24 | ## Get Started |
23 | 25 | ||
24 | ```ruby | 26 | ```ruby |
25 | User.group_by_day(:created_at).count | 27 | User.group_by_day(:created_at).count |
26 | # { | 28 | # { |
27 | -# 2013-04-16 00:00:00 UTC => 50, | ||
28 | -# 2013-04-17 00:00:00 UTC => 100, | ||
29 | -# 2013-04-18 00:00:00 UTC => 34 | 29 | +# Sat, 28 May 2016 => 50, |
30 | +# Sun, 29 May 2016 => 100, | ||
31 | +# Mon, 30 May 2016 => 34 | ||
30 | # } | 32 | # } |
31 | ``` | 33 | ``` |
32 | 34 | ||
@@ -65,9 +67,9 @@ or | @@ -65,9 +67,9 @@ or | ||
65 | ```ruby | 67 | ```ruby |
66 | User.group_by_week(:created_at, time_zone: "Pacific Time (US & Canada)").count | 68 | User.group_by_week(:created_at, time_zone: "Pacific Time (US & Canada)").count |
67 | # { | 69 | # { |
68 | -# 2013-03-10 00:00:00 PST => 70, | ||
69 | -# 2013-03-17 00:00:00 PDT => 54, | ||
70 | -# 2013-03-24 00:00:00 PDT => 80 | 70 | +# Sun, 06 Mar 2016 => 70, |
71 | +# Sun, 13 Mar 2016 => 54, | ||
72 | +# Sun, 20 Mar 2016 => 80 | ||
71 | # } | 73 | # } |
72 | ``` | 74 | ``` |
73 | 75 | ||
@@ -137,24 +139,7 @@ User.group_by_day(:created_at).order("day desc").count | @@ -137,24 +139,7 @@ User.group_by_day(:created_at).order("day desc").count | ||
137 | 139 | ||
138 | ### Keys | 140 | ### Keys |
139 | 141 | ||
140 | -Keys are returned as time objects for the start of the period. | ||
141 | - | ||
142 | -To get keys as date objects instead, use: | ||
143 | - | ||
144 | -```ruby | ||
145 | -User.group_by_day(:created_at, dates: true).count | ||
146 | -# { | ||
147 | -# 2013-03-10 => 70, | ||
148 | -# 2013-03-17 => 54, | ||
149 | -# 2013-03-24 => 80 | ||
150 | -# } | ||
151 | -``` | ||
152 | - | ||
153 | -or make this the default with: | ||
154 | - | ||
155 | -```ruby | ||
156 | -Groupdate.dates = true | ||
157 | -``` | 142 | +Keys are returned as date or time objects for the start of the period. |
158 | 143 | ||
159 | To get keys in a different format, use: | 144 | To get keys in a different format, use: |
160 | 145 | ||
@@ -229,9 +214,19 @@ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql | @@ -229,9 +214,19 @@ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql | ||
229 | 214 | ||
230 | or copy and paste [these statements](https://gist.githubusercontent.com/ankane/1d6b0022173186accbf0/raw/time_zone_support.sql) into a SQL console. | 215 | or copy and paste [these statements](https://gist.githubusercontent.com/ankane/1d6b0022173186accbf0/raw/time_zone_support.sql) into a SQL console. |
231 | 216 | ||
232 | -## Upgrading to 2.0 | 217 | +## Upgrading |
218 | + | ||
219 | +### 3.0 | ||
220 | + | ||
221 | +Groupdate 3.0 brings a number of improvements. Here are a few to be aware of: | ||
222 | + | ||
223 | +- `Date` objects are now returned for day, week, month, quarter, and year by default. Use `dates: false` for the previous behavior, or change this globally with `Groupdate.dates = false`. | ||
224 | +- Array and hash methods no longer return the entire series by default. Use `series: true` for the previous behavior. | ||
225 | +- The `series: false` option now returns the correct type and order, and plays nicely with other options. | ||
226 | + | ||
227 | +### 2.0 | ||
233 | 228 | ||
234 | -Groupdate 2.0 brings a number a great improvements. Here are two things to be aware of: | 229 | +Groupdate 2.0 brings a number of improvements. Here are two things to be aware of: |
235 | 230 | ||
236 | - the entire series is returned by default | 231 | - the entire series is returned by default |
237 | - `ActiveSupport::TimeWithZone` keys are now returned for every database adapter - adapters previously returned `Time` or `String` keys | 232 | - `ActiveSupport::TimeWithZone` keys are now returned for every database adapter - adapters previously returned `Time` or `String` keys |
lib/groupdate.rb
@@ -12,7 +12,7 @@ module Groupdate | @@ -12,7 +12,7 @@ module Groupdate | ||
12 | mattr_accessor :week_start, :day_start, :time_zone, :dates | 12 | mattr_accessor :week_start, :day_start, :time_zone, :dates |
13 | self.week_start = :sun | 13 | self.week_start = :sun |
14 | self.day_start = 0 | 14 | self.day_start = 0 |
15 | - self.dates = false | 15 | + self.dates = true |
16 | end | 16 | end |
17 | 17 | ||
18 | require "groupdate/enumerable" | 18 | require "groupdate/enumerable" |
lib/groupdate/magic.rb
@@ -15,11 +15,7 @@ module Groupdate | @@ -15,11 +15,7 @@ module Groupdate | ||
15 | 15 | ||
16 | def group_by(enum, &_block) | 16 | def group_by(enum, &_block) |
17 | group = enum.group_by { |v| v = yield(v); v ? round_time(v) : nil } | 17 | group = enum.group_by { |v| v = yield(v); v ? round_time(v) : nil } |
18 | - if options[:series] == false | ||
19 | - group | ||
20 | - else | ||
21 | - series(group, []) | ||
22 | - end | 18 | + series(group, [], false, false, false) |
23 | end | 19 | end |
24 | 20 | ||
25 | def relation(column, relation) | 21 | def relation(column, relation) |
@@ -90,22 +86,18 @@ module Groupdate | @@ -90,22 +86,18 @@ module Groupdate | ||
90 | end | 86 | end |
91 | 87 | ||
92 | group = relation.group(Groupdate::OrderHack.new(relation.send(:sanitize_sql_array, query), field, time_zone)) | 88 | group = relation.group(Groupdate::OrderHack.new(relation.send(:sanitize_sql_array, query), field, time_zone)) |
93 | - if options[:series] == false | ||
94 | - group | ||
95 | - else | ||
96 | - relation = | ||
97 | - if time_range.is_a?(Range) | ||
98 | - # doesn't matter whether we include the end of a ... range - it will be excluded later | ||
99 | - group.where("#{column} >= ? AND #{column} <= ?", time_range.first, time_range.last) | ||
100 | - else | ||
101 | - group.where("#{column} IS NOT NULL") | ||
102 | - end | 89 | + relation = |
90 | + if time_range.is_a?(Range) | ||
91 | + # doesn't matter whether we include the end of a ... range - it will be excluded later | ||
92 | + group.where("#{column} >= ? AND #{column} <= ?", time_range.first, time_range.last) | ||
93 | + else | ||
94 | + group.where("#{column} IS NOT NULL") | ||
95 | + end | ||
103 | 96 | ||
104 | - # TODO do not change object state | ||
105 | - @group_index = group.group_values.size - 1 | 97 | + # TODO do not change object state |
98 | + @group_index = group.group_values.size - 1 | ||
106 | 99 | ||
107 | - Groupdate::Series.new(self, relation) | ||
108 | - end | 100 | + Groupdate::Series.new(self, relation) |
109 | end | 101 | end |
110 | 102 | ||
111 | def perform(relation, method, *args, &block) | 103 | def perform(relation, method, *args, &block) |
@@ -175,7 +167,7 @@ module Groupdate | @@ -175,7 +167,7 @@ module Groupdate | ||
175 | end | 167 | end |
176 | end | 168 | end |
177 | 169 | ||
178 | - def series(count, default_value, multiple_groups = false, reverse = false) | 170 | + def series(count, default_value, multiple_groups = false, reverse = false, series_default = true) |
179 | reverse = !reverse if options[:reverse] | 171 | reverse = !reverse if options[:reverse] |
180 | 172 | ||
181 | series = | 173 | series = |
@@ -238,6 +230,7 @@ module Groupdate | @@ -238,6 +230,7 @@ module Groupdate | ||
238 | series = series.to_a.reverse if !multiple_groups && reverse | 230 | series = series.to_a.reverse if !multiple_groups && reverse |
239 | 231 | ||
240 | locale = options[:locale] || I18n.locale | 232 | locale = options[:locale] || I18n.locale |
233 | + use_dates = options.key?(:dates) ? options[:dates] : Groupdate.dates | ||
241 | key_format = | 234 | key_format = |
242 | if options[:format] | 235 | if options[:format] |
243 | if options[:format].respond_to?(:call) | 236 | if options[:format].respond_to?(:call) |
@@ -258,12 +251,17 @@ module Groupdate | @@ -258,12 +251,17 @@ module Groupdate | ||
258 | I18n.localize(key, format: options[:format], locale: locale) | 251 | I18n.localize(key, format: options[:format], locale: locale) |
259 | end | 252 | end |
260 | end | 253 | end |
261 | - elsif (options[:dates] || (Groupdate.dates && !options.key?(:dates))) && [:day, :week, :month, :quarter, :year].include?(field) | 254 | + elsif [:day, :week, :month, :quarter, :year].include?(field) && use_dates |
262 | lambda { |k| k.to_date } | 255 | lambda { |k| k.to_date } |
263 | else | 256 | else |
264 | lambda { |k| k } | 257 | lambda { |k| k } |
265 | end | 258 | end |
266 | 259 | ||
260 | + use_series = options.key?(:series) ? options[:series] : series_default | ||
261 | + if use_series == false | ||
262 | + series = series.select { |k| count[k] } | ||
263 | + end | ||
264 | + | ||
267 | value = 0 | 265 | value = 0 |
268 | Hash[series.map do |k| | 266 | Hash[series.map do |k| |
269 | value = count[k] || (@options[:carry_forward] && value) || default_value | 267 | value = count[k] || (@options[:carry_forward] && value) || default_value |
test/enumerable_test.rb
@@ -8,13 +8,23 @@ class TestEnumerable < Minitest::Test | @@ -8,13 +8,23 @@ class TestEnumerable < Minitest::Test | ||
8 | user_a = create_user("2014-01-21") | 8 | user_a = create_user("2014-01-21") |
9 | user_b = create_user("2014-03-14") | 9 | user_b = create_user("2014-03-14") |
10 | expected = { | 10 | expected = { |
11 | - utc.parse("2014-01-01") => [user_a], | ||
12 | - utc.parse("2014-02-01") => [], | ||
13 | - utc.parse("2014-03-01") => [user_b] | 11 | + Date.parse("2014-01-01") => [user_a], |
12 | + Date.parse("2014-03-01") => [user_b] | ||
14 | } | 13 | } |
15 | assert_equal expected, [user_a, user_b].group_by_month(&:created_at) | 14 | assert_equal expected, [user_a, user_b].group_by_month(&:created_at) |
16 | end | 15 | end |
17 | 16 | ||
17 | + def test_enumerable_series | ||
18 | + user_a = create_user("2014-01-21") | ||
19 | + user_b = create_user("2014-03-14") | ||
20 | + expected = { | ||
21 | + Date.parse("2014-01-01") => [user_a], | ||
22 | + Date.parse("2014-02-01") => [], | ||
23 | + Date.parse("2014-03-01") => [user_b] | ||
24 | + } | ||
25 | + assert_equal expected, [user_a, user_b].group_by_month(series: true, &:created_at) | ||
26 | + end | ||
27 | + | ||
18 | def test_no_block | 28 | def test_no_block |
19 | assert_raises(ArgumentError) { [].group_by_day(:created_at) } | 29 | assert_raises(ArgumentError) { [].group_by_day(:created_at) } |
20 | end | 30 | end |
test/test_helper.rb
@@ -51,11 +51,11 @@ end | @@ -51,11 +51,11 @@ end | ||
51 | 51 | ||
52 | module TestDatabase | 52 | module TestDatabase |
53 | def test_zeros_previous_scope | 53 | def test_zeros_previous_scope |
54 | - create_user "2013-05-01 00:00:00 UTC" | 54 | + create_user "2013-05-01" |
55 | expected = { | 55 | expected = { |
56 | - utc.parse("2013-05-01 00:00:00 UTC") => 0 | 56 | + Date.parse("2013-05-01") => 0 |
57 | } | 57 | } |
58 | - assert_equal expected, User.where("id = 0").group_by_day(:created_at, range: Time.parse("2013-05-01 00:00:00 UTC")..Time.parse("2013-05-01 23:59:59 UTC")).count | 58 | + assert_equal expected, User.where("id = 0").group_by_day(:created_at, range: Date.parse("2013-05-01")..Date.parse("2013-05-01 23:59:59 UTC")).count |
59 | end | 59 | end |
60 | 60 | ||
61 | def test_order_hour_of_day | 61 | def test_order_hour_of_day |
@@ -81,51 +81,51 @@ module TestDatabase | @@ -81,51 +81,51 @@ module TestDatabase | ||
81 | end | 81 | end |
82 | 82 | ||
83 | def test_previous_scopes | 83 | def test_previous_scopes |
84 | - create_user "2013-05-01 00:00:00 UTC" | 84 | + create_user "2013-05-01" |
85 | assert_empty User.where("id = 0").group_by_day(:created_at).count | 85 | assert_empty User.where("id = 0").group_by_day(:created_at).count |
86 | end | 86 | end |
87 | 87 | ||
88 | def test_where_after | 88 | def test_where_after |
89 | - create_user "2013-05-01 00:00:00 UTC" | ||
90 | - create_user "2013-05-02 00:00:00 UTC" | ||
91 | - expected = {utc.parse("2013-05-02 00:00:00 UTC") => 1} | ||
92 | - assert_equal expected, User.group_by_day(:created_at).where("created_at > ?", "2013-05-01 00:00:00 UTC").count | 89 | + create_user "2013-05-01" |
90 | + create_user "2013-05-02" | ||
91 | + expected = {Date.parse("2013-05-02") => 1} | ||
92 | + assert_equal expected, User.group_by_day(:created_at).where("created_at > ?", "2013-05-01").count | ||
93 | end | 93 | end |
94 | 94 | ||
95 | def test_group_before | 95 | def test_group_before |
96 | - create_user "2013-05-01 00:00:00 UTC", 1 | ||
97 | - create_user "2013-05-02 00:00:00 UTC", 2 | ||
98 | - create_user "2013-05-03 00:00:00 UTC", 2 | 96 | + create_user "2013-05-01", 1 |
97 | + create_user "2013-05-02", 2 | ||
98 | + create_user "2013-05-03", 2 | ||
99 | expected = { | 99 | expected = { |
100 | - [1, utc.parse("2013-05-01 00:00:00 UTC")] => 1, | ||
101 | - [1, utc.parse("2013-05-02 00:00:00 UTC")] => 0, | ||
102 | - [1, utc.parse("2013-05-03 00:00:00 UTC")] => 0, | ||
103 | - [2, utc.parse("2013-05-01 00:00:00 UTC")] => 0, | ||
104 | - [2, utc.parse("2013-05-02 00:00:00 UTC")] => 1, | ||
105 | - [2, utc.parse("2013-05-03 00:00:00 UTC")] => 1 | 100 | + [1, Date.parse("2013-05-01")] => 1, |
101 | + [1, Date.parse("2013-05-02")] => 0, | ||
102 | + [1, Date.parse("2013-05-03")] => 0, | ||
103 | + [2, Date.parse("2013-05-01")] => 0, | ||
104 | + [2, Date.parse("2013-05-02")] => 1, | ||
105 | + [2, Date.parse("2013-05-03")] => 1 | ||
106 | } | 106 | } |
107 | assert_equal expected, User.group(:score).group_by_day(:created_at).order(:score).count | 107 | assert_equal expected, User.group(:score).group_by_day(:created_at).order(:score).count |
108 | end | 108 | end |
109 | 109 | ||
110 | def test_group_after | 110 | def test_group_after |
111 | - create_user "2013-05-01 00:00:00 UTC", 1 | ||
112 | - create_user "2013-05-02 00:00:00 UTC", 2 | ||
113 | - create_user "2013-05-03 00:00:00 UTC", 2 | 111 | + create_user "2013-05-01", 1 |
112 | + create_user "2013-05-02", 2 | ||
113 | + create_user "2013-05-03", 2 | ||
114 | expected = { | 114 | expected = { |
115 | - [utc.parse("2013-05-01 00:00:00 UTC"), 1] => 1, | ||
116 | - [utc.parse("2013-05-02 00:00:00 UTC"), 1] => 0, | ||
117 | - [utc.parse("2013-05-03 00:00:00 UTC"), 1] => 0, | ||
118 | - [utc.parse("2013-05-01 00:00:00 UTC"), 2] => 0, | ||
119 | - [utc.parse("2013-05-02 00:00:00 UTC"), 2] => 1, | ||
120 | - [utc.parse("2013-05-03 00:00:00 UTC"), 2] => 1 | 115 | + [Date.parse("2013-05-01"), 1] => 1, |
116 | + [Date.parse("2013-05-02"), 1] => 0, | ||
117 | + [Date.parse("2013-05-03"), 1] => 0, | ||
118 | + [Date.parse("2013-05-01"), 2] => 0, | ||
119 | + [Date.parse("2013-05-02"), 2] => 1, | ||
120 | + [Date.parse("2013-05-03"), 2] => 1 | ||
121 | } | 121 | } |
122 | assert_equal expected, User.group_by_day(:created_at).group(:score).order(:score).count | 122 | assert_equal expected, User.group_by_day(:created_at).group(:score).order(:score).count |
123 | end | 123 | end |
124 | 124 | ||
125 | def test_group_day_of_week | 125 | def test_group_day_of_week |
126 | - create_user "2013-05-01 00:00:00 UTC", 1 | ||
127 | - create_user "2013-05-02 00:00:00 UTC", 2 | ||
128 | - create_user "2013-05-03 00:00:00 UTC", 2 | 126 | + create_user "2013-05-01", 1 |
127 | + create_user "2013-05-02", 2 | ||
128 | + create_user "2013-05-03", 2 | ||
129 | expected = { | 129 | expected = { |
130 | [1, 0] => 0, | 130 | [1, 0] => 0, |
131 | [1, 1] => 0, | 131 | [1, 1] => 0, |
@@ -146,9 +146,9 @@ module TestDatabase | @@ -146,9 +146,9 @@ module TestDatabase | ||
146 | end | 146 | end |
147 | 147 | ||
148 | def test_groupdate_multiple | 148 | def test_groupdate_multiple |
149 | - create_user "2013-05-01 00:00:00 UTC", 1 | 149 | + create_user "2013-05-01", 1 |
150 | expected = { | 150 | expected = { |
151 | - [utc.parse("2013-05-01 00:00:00 UTC"), utc.parse("2013-01-01 00:00:00 UTC")] => 1 | 151 | + [Date.parse("2013-05-01"), Date.parse("2013-01-01")] => 1 |
152 | } | 152 | } |
153 | assert_equal expected, User.group_by_day(:created_at).group_by_year(:created_at).count | 153 | assert_equal expected, User.group_by_day(:created_at).group_by_year(:created_at).count |
154 | end | 154 | end |
@@ -165,10 +165,10 @@ module TestDatabase | @@ -165,10 +165,10 @@ module TestDatabase | ||
165 | end | 165 | end |
166 | 166 | ||
167 | def test_not_modified | 167 | def test_not_modified |
168 | - create_user "2013-05-01 00:00:00 UTC" | ||
169 | - expected = {utc.parse("2013-05-01 00:00:00 UTC") => 1} | 168 | + create_user "2013-05-01" |
169 | + expected = {Date.parse("2013-05-01") => 1} | ||
170 | relation = User.group_by_day(:created_at) | 170 | relation = User.group_by_day(:created_at) |
171 | - relation.where("created_at > ?", "2013-05-01 00:00:00 UTC") | 171 | + relation.where("created_at > ?", "2013-05-01") |
172 | assert_equal expected, relation.count | 172 | assert_equal expected, relation.count |
173 | end | 173 | end |
174 | 174 | ||
@@ -185,38 +185,38 @@ module TestDatabase | @@ -185,38 +185,38 @@ module TestDatabase | ||
185 | end | 185 | end |
186 | 186 | ||
187 | def test_last | 187 | def test_last |
188 | - create_user "#{this_year - 3}-01-01 00:00:00 UTC" | ||
189 | - create_user "#{this_year - 1}-01-01 00:00:00 UTC" | 188 | + create_user "#{this_year - 3}-01-01" |
189 | + create_user "#{this_year - 1}-01-01" | ||
190 | expected = { | 190 | expected = { |
191 | - utc.parse("#{this_year - 2}-01-01 00:00:00 UTC") => 0, | ||
192 | - utc.parse("#{this_year - 1}-01-01 00:00:00 UTC") => 1, | ||
193 | - utc.parse("#{this_year}-01-01 00:00:00 UTC") => 0 | 191 | + Date.parse("#{this_year - 2}-01-01") => 0, |
192 | + Date.parse("#{this_year - 1}-01-01") => 1, | ||
193 | + Date.parse("#{this_year}-01-01") => 0 | ||
194 | } | 194 | } |
195 | assert_equal expected, User.group_by_year(:created_at, last: 3).count | 195 | assert_equal expected, User.group_by_year(:created_at, last: 3).count |
196 | end | 196 | end |
197 | 197 | ||
198 | def test_current | 198 | def test_current |
199 | - create_user "#{this_year - 3}-01-01 00:00:00 UTC" | ||
200 | - create_user "#{this_year - 1}-01-01 00:00:00 UTC" | 199 | + create_user "#{this_year - 3}-01-01" |
200 | + create_user "#{this_year - 1}-01-01" | ||
201 | expected = { | 201 | expected = { |
202 | - utc.parse("#{this_year - 2}-01-01 00:00:00 UTC") => 0, | ||
203 | - utc.parse("#{this_year - 1}-01-01 00:00:00 UTC") => 1 | 202 | + Date.parse("#{this_year - 2}-01-01") => 0, |
203 | + Date.parse("#{this_year - 1}-01-01") => 1 | ||
204 | } | 204 | } |
205 | assert_equal expected, User.group_by_year(:created_at, last: 2, current: false).count | 205 | assert_equal expected, User.group_by_year(:created_at, last: 2, current: false).count |
206 | end | 206 | end |
207 | 207 | ||
208 | def test_format_locale | 208 | def test_format_locale |
209 | - create_user "2014-10-01 00:00:00 UTC" | 209 | + create_user "2014-10-01" |
210 | assert_equal ({"Okt" => 1}), User.group_by_day(:created_at, format: "%b", locale: :de).count | 210 | assert_equal ({"Okt" => 1}), User.group_by_day(:created_at, format: "%b", locale: :de).count |
211 | end | 211 | end |
212 | 212 | ||
213 | def test_format_locale_by_symbol | 213 | def test_format_locale_by_symbol |
214 | - create_user "2014-10-01 00:00:00 UTC" | 214 | + create_user "2014-10-01" |
215 | assert_equal ({"Okt 1, 2014" => 1}), User.group_by_day(:created_at, format: :special, locale: :de).count | 215 | assert_equal ({"Okt 1, 2014" => 1}), User.group_by_day(:created_at, format: :special, locale: :de).count |
216 | end | 216 | end |
217 | 217 | ||
218 | def test_format_locale_global | 218 | def test_format_locale_global |
219 | - create_user "2014-10-01 00:00:00 UTC" | 219 | + create_user "2014-10-01" |
220 | I18n.locale = :de | 220 | I18n.locale = :de |
221 | assert_equal ({"Okt" => 1}), User.group_by_day(:created_at, format: "%b").count | 221 | assert_equal ({"Okt" => 1}), User.group_by_day(:created_at, format: "%b").count |
222 | ensure | 222 | ensure |
@@ -224,7 +224,7 @@ module TestDatabase | @@ -224,7 +224,7 @@ module TestDatabase | ||
224 | end | 224 | end |
225 | 225 | ||
226 | def test_format_multiple_groups | 226 | def test_format_multiple_groups |
227 | - create_user "2014-03-01 00:00:00 UTC" | 227 | + create_user "2014-03-01" |
228 | assert_equal ({["Sun", 1] => 1}), User.group_by_week(:created_at, format: "%a").group(:score).count | 228 | assert_equal ({["Sun", 1] => 1}), User.group_by_week(:created_at, format: "%a").group(:score).count |
229 | assert_equal ({[1, "Sun"] => 1}), User.group(:score).group_by_week(:created_at, format: "%a").count | 229 | assert_equal ({[1, "Sun"] => 1}), User.group(:score).group_by_week(:created_at, format: "%a").count |
230 | end | 230 | end |
@@ -258,10 +258,10 @@ module TestDatabase | @@ -258,10 +258,10 @@ module TestDatabase | ||
258 | # default value | 258 | # default value |
259 | 259 | ||
260 | def test_default_value | 260 | def test_default_value |
261 | - create_user "#{this_year}-01-01 00:00:00 UTC" | 261 | + create_user "#{this_year}-01-01" |
262 | expected = { | 262 | expected = { |
263 | - utc.parse("#{this_year - 1}-01-01 00:00:00 UTC") => nil, | ||
264 | - utc.parse("#{this_year}-01-01 00:00:00 UTC") => 1 | 263 | + Date.parse("#{this_year - 1}-01-01") => nil, |
264 | + Date.parse("#{this_year}-01-01") => 1 | ||
265 | } | 265 | } |
266 | assert_equal expected, User.group_by_year(:created_at, last: 2, default_value: nil).count | 266 | assert_equal expected, User.group_by_year(:created_at, last: 2, default_value: nil).count |
267 | end | 267 | end |
@@ -269,10 +269,10 @@ module TestDatabase | @@ -269,10 +269,10 @@ module TestDatabase | ||
269 | # associations | 269 | # associations |
270 | 270 | ||
271 | def test_associations | 271 | def test_associations |
272 | - user = create_user("2014-03-01 00:00:00 UTC") | 272 | + user = create_user("2014-03-01") |
273 | user.posts.create!(created_at: "2014-04-01 00:00:00 UTC") | 273 | user.posts.create!(created_at: "2014-04-01 00:00:00 UTC") |
274 | expected = { | 274 | expected = { |
275 | - utc.parse("2014-04-01 00:00:00 UTC") => 1 | 275 | + Date.parse("2014-04-01") => 1 |
276 | } | 276 | } |
277 | assert_equal expected, user.posts.group_by_day(:created_at).count | 277 | assert_equal expected, user.posts.group_by_day(:created_at).count |
278 | end | 278 | end |
@@ -293,8 +293,8 @@ module TestDatabase | @@ -293,8 +293,8 @@ module TestDatabase | ||
293 | create_user(brasilia.parse("2014-10-19 02:00:00").utc.to_s) | 293 | create_user(brasilia.parse("2014-10-19 02:00:00").utc.to_s) |
294 | create_user(brasilia.parse("2014-10-20 02:00:00").utc.to_s) | 294 | create_user(brasilia.parse("2014-10-20 02:00:00").utc.to_s) |
295 | expected = { | 295 | expected = { |
296 | - brasilia.parse("2014-10-19 01:00:00") => 1, | ||
297 | - brasilia.parse("2014-10-20 00:00:00") => 1 | 296 | + Date.parse("2014-10-19") => 1, |
297 | + Date.parse("2014-10-20") => 1 | ||
298 | } | 298 | } |
299 | assert_equal expected, User.group_by_day(:created_at, time_zone: "Brasilia").count | 299 | assert_equal expected, User.group_by_day(:created_at, time_zone: "Brasilia").count |
300 | end | 300 | end |
@@ -302,10 +302,10 @@ module TestDatabase | @@ -302,10 +302,10 @@ module TestDatabase | ||
302 | # carry_forward option | 302 | # carry_forward option |
303 | 303 | ||
304 | def test_carry_forward | 304 | def test_carry_forward |
305 | - create_user "2014-05-01 00:00:00 UTC" | ||
306 | - create_user "2014-05-01 00:00:00 UTC" | ||
307 | - create_user "2014-05-03 00:00:00 UTC" | ||
308 | - assert_equal 2, User.group_by_day(:created_at, carry_forward: true).count[utc.parse("2014-05-02 00:00:00 UTC")] | 305 | + create_user "2014-05-01" |
306 | + create_user "2014-05-01" | ||
307 | + create_user "2014-05-03" | ||
308 | + assert_equal 2, User.group_by_day(:created_at, carry_forward: true).count[Date.parse("2014-05-02")] | ||
309 | end | 309 | end |
310 | 310 | ||
311 | # dates | 311 | # dates |
@@ -389,217 +389,217 @@ module TestGroupdate | @@ -389,217 +389,217 @@ module TestGroupdate | ||
389 | # day | 389 | # day |
390 | 390 | ||
391 | def test_day_end_of_day | 391 | def test_day_end_of_day |
392 | - assert_result_time :day, "2013-05-03 00:00:00 UTC", "2013-05-03 23:59:59" | 392 | + assert_result_date :day, "2013-05-03", "2013-05-03 23:59:59" |
393 | end | 393 | end |
394 | 394 | ||
395 | def test_day_start_of_day | 395 | def test_day_start_of_day |
396 | - assert_result_time :day, "2013-05-04 00:00:00 UTC", "2013-05-04 00:00:00" | 396 | + assert_result_date :day, "2013-05-04", "2013-05-04 00:00:00" |
397 | end | 397 | end |
398 | 398 | ||
399 | def test_day_end_of_day_with_time_zone | 399 | def test_day_end_of_day_with_time_zone |
400 | - assert_result_time :day, "2013-05-02 00:00:00 PDT", "2013-05-03 06:59:59", true | 400 | + assert_result_date :day, "2013-05-02", "2013-05-03 06:59:59", true |
401 | end | 401 | end |
402 | 402 | ||
403 | def test_day_start_of_day_with_time_zone | 403 | def test_day_start_of_day_with_time_zone |
404 | - assert_result_time :day, "2013-05-03 00:00:00 PDT", "2013-05-03 07:00:00", true | 404 | + assert_result_date :day, "2013-05-03", "2013-05-03 07:00:00", true |
405 | end | 405 | end |
406 | 406 | ||
407 | # day hour starts at 2 am | 407 | # day hour starts at 2 am |
408 | 408 | ||
409 | def test_test_day_end_of_day_day_start_2am | 409 | def test_test_day_end_of_day_day_start_2am |
410 | - assert_result_time :day, "2013-05-03 02:00:00 UTC", "2013-05-04 01:59:59", false, day_start: 2 | 410 | + assert_result_date :day, "2013-05-03", "2013-05-04 01:59:59", false, day_start: 2 |
411 | end | 411 | end |
412 | 412 | ||
413 | def test_test_day_start_of_day_day_start_2am | 413 | def test_test_day_start_of_day_day_start_2am |
414 | - assert_result_time :day, "2013-05-03 02:00:00 UTC", "2013-05-03 02:00:00", false, day_start: 2 | 414 | + assert_result_date :day, "2013-05-03", "2013-05-03 02:00:00", false, day_start: 2 |
415 | end | 415 | end |
416 | 416 | ||
417 | def test_test_day_end_of_day_with_time_zone_day_start_2am | 417 | def test_test_day_end_of_day_with_time_zone_day_start_2am |
418 | - assert_result_time :day, "2013-05-03 02:00:00 PDT", "2013-05-04 07:59:59", true, day_start: 2 | 418 | + assert_result_date :day, "2013-05-03", "2013-05-04 07:59:59", true, day_start: 2 |
419 | end | 419 | end |
420 | 420 | ||
421 | def test_test_day_start_of_day_with_time_zone_day_start_2am | 421 | def test_test_day_start_of_day_with_time_zone_day_start_2am |
422 | - assert_result_time :day, "2013-05-03 02:00:00 PDT", "2013-05-03 09:00:00", true, day_start: 2 | 422 | + assert_result_date :day, "2013-05-03", "2013-05-03 09:00:00", true, day_start: 2 |
423 | end | 423 | end |
424 | 424 | ||
425 | # week | 425 | # week |
426 | 426 | ||
427 | def test_week_end_of_week | 427 | def test_week_end_of_week |
428 | - assert_result_time :week, "2013-03-17 00:00:00 UTC", "2013-03-23 23:59:59" | 428 | + assert_result_date :week, "2013-03-17", "2013-03-23 23:59:59" |
429 | end | 429 | end |
430 | 430 | ||
431 | def test_week_start_of_week | 431 | def test_week_start_of_week |
432 | - assert_result_time :week, "2013-03-24 00:00:00 UTC", "2013-03-24 00:00:00" | 432 | + assert_result_date :week, "2013-03-24", "2013-03-24 00:00:00" |
433 | end | 433 | end |
434 | 434 | ||
435 | def test_week_end_of_week_with_time_zone | 435 | def test_week_end_of_week_with_time_zone |
436 | - assert_result_time :week, "2013-03-10 00:00:00 PST", "2013-03-17 06:59:59", true | 436 | + assert_result_date :week, "2013-03-10", "2013-03-17 06:59:59", true |
437 | end | 437 | end |
438 | 438 | ||
439 | def test_week_start_of_week_with_time_zone | 439 | def test_week_start_of_week_with_time_zone |
440 | - assert_result_time :week, "2013-03-17 00:00:00 PDT", "2013-03-17 07:00:00", true | 440 | + assert_result_date :week, "2013-03-17", "2013-03-17 07:00:00", true |
441 | end | 441 | end |
442 | 442 | ||
443 | # week starting on monday | 443 | # week starting on monday |
444 | 444 | ||
445 | def test_week_end_of_week_mon | 445 | def test_week_end_of_week_mon |
446 | - assert_result_time :week, "2013-03-18 00:00:00 UTC", "2013-03-24 23:59:59", false, week_start: :mon | 446 | + assert_result_date :week, "2013-03-18", "2013-03-24 23:59:59", false, week_start: :mon |
447 | end | 447 | end |
448 | 448 | ||
449 | def test_week_start_of_week_mon | 449 | def test_week_start_of_week_mon |
450 | - assert_result_time :week, "2013-03-25 00:00:00 UTC", "2013-03-25 00:00:00", false, week_start: :mon | 450 | + assert_result_date :week, "2013-03-25", "2013-03-25 00:00:00", false, week_start: :mon |
451 | end | 451 | end |
452 | 452 | ||
453 | def test_week_end_of_week_with_time_zone_mon | 453 | def test_week_end_of_week_with_time_zone_mon |
454 | - assert_result_time :week, "2013-03-11 00:00:00 PDT", "2013-03-18 06:59:59", true, week_start: :mon | 454 | + assert_result_date :week, "2013-03-11", "2013-03-18 06:59:59", true, week_start: :mon |
455 | end | 455 | end |
456 | 456 | ||
457 | def test_week_start_of_week_with_time_zone_mon | 457 | def test_week_start_of_week_with_time_zone_mon |
458 | - assert_result_time :week, "2013-03-18 00:00:00 PDT", "2013-03-18 07:00:00", true, week_start: :mon | 458 | + assert_result_date :week, "2013-03-18", "2013-03-18 07:00:00", true, week_start: :mon |
459 | end | 459 | end |
460 | 460 | ||
461 | # week starting on saturday | 461 | # week starting on saturday |
462 | 462 | ||
463 | def test_week_end_of_week_sat | 463 | def test_week_end_of_week_sat |
464 | - assert_result_time :week, "2013-03-16 00:00:00 UTC", "2013-03-22 23:59:59", false, week_start: :sat | 464 | + assert_result_date :week, "2013-03-16", "2013-03-22 23:59:59", false, week_start: :sat |
465 | end | 465 | end |
466 | 466 | ||
467 | def test_week_start_of_week_sat | 467 | def test_week_start_of_week_sat |
468 | - assert_result_time :week, "2013-03-23 00:00:00 UTC", "2013-03-23 00:00:00", false, week_start: :sat | 468 | + assert_result_date :week, "2013-03-23", "2013-03-23 00:00:00", false, week_start: :sat |
469 | end | 469 | end |
470 | 470 | ||
471 | def test_week_end_of_week_with_time_zone_sat | 471 | def test_week_end_of_week_with_time_zone_sat |
472 | - assert_result_time :week, "2013-03-09 00:00:00 PST", "2013-03-16 06:59:59", true, week_start: :sat | 472 | + assert_result_date :week, "2013-03-09", "2013-03-16 06:59:59", true, week_start: :sat |
473 | end | 473 | end |
474 | 474 | ||
475 | def test_week_start_of_week_with_time_zone_sat | 475 | def test_week_start_of_week_with_time_zone_sat |
476 | - assert_result_time :week, "2013-03-16 00:00:00 PDT", "2013-03-16 07:00:00", true, week_start: :sat | 476 | + assert_result_date :week, "2013-03-16", "2013-03-16 07:00:00", true, week_start: :sat |
477 | end | 477 | end |
478 | 478 | ||
479 | # week starting at 2am | 479 | # week starting at 2am |
480 | 480 | ||
481 | def test_week_end_of_week_day_start_2am | 481 | def test_week_end_of_week_day_start_2am |
482 | - assert_result_time :week, "2013-03-17 02:00:00 UTC", "2013-03-24 01:59:59", false, day_start: 2 | 482 | + assert_result_date :week, "2013-03-17", "2013-03-24 01:59:59", false, day_start: 2 |
483 | end | 483 | end |
484 | 484 | ||
485 | def test_week_start_of_week_day_start_2am | 485 | def test_week_start_of_week_day_start_2am |
486 | - assert_result_time :week, "2013-03-17 02:00:00 UTC", "2013-03-17 02:00:00", false, day_start: 2 | 486 | + assert_result_date :week, "2013-03-17", "2013-03-17 02:00:00", false, day_start: 2 |
487 | end | 487 | end |
488 | 488 | ||
489 | def test_week_end_of_week_day_with_time_zone_start_2am | 489 | def test_week_end_of_week_day_with_time_zone_start_2am |
490 | - assert_result_time :week, "2013-03-17 02:00:00 PDT", "2013-03-24 08:59:59", true, day_start: 2 | 490 | + assert_result_date :week, "2013-03-17", "2013-03-24 08:59:59", true, day_start: 2 |
491 | end | 491 | end |
492 | 492 | ||
493 | def test_week_start_of_week_day_with_time_zone_start_2am | 493 | def test_week_start_of_week_day_with_time_zone_start_2am |
494 | - assert_result_time :week, "2013-03-17 02:00:00 PDT", "2013-03-17 09:00:00", true, day_start: 2 | 494 | + assert_result_date :week, "2013-03-17", "2013-03-17 09:00:00", true, day_start: 2 |
495 | end | 495 | end |
496 | 496 | ||
497 | # month | 497 | # month |
498 | 498 | ||
499 | def test_month_end_of_month | 499 | def test_month_end_of_month |
500 | - assert_result_time :month, "2013-05-01 00:00:00 UTC", "2013-05-31 23:59:59" | 500 | + assert_result_date :month, "2013-05-01", "2013-05-31 23:59:59" |
501 | end | 501 | end |
502 | 502 | ||
503 | def test_month_start_of_month | 503 | def test_month_start_of_month |
504 | - assert_result_time :month, "2013-06-01 00:00:00 UTC", "2013-06-01 00:00:00" | 504 | + assert_result_date :month, "2013-06-01", "2013-06-01 00:00:00" |
505 | end | 505 | end |
506 | 506 | ||
507 | def test_month_end_of_month_with_time_zone | 507 | def test_month_end_of_month_with_time_zone |
508 | - assert_result_time :month, "2013-05-01 00:00:00 PDT", "2013-06-01 06:59:59", true | 508 | + assert_result_date :month, "2013-05-01", "2013-06-01 06:59:59", true |
509 | end | 509 | end |
510 | 510 | ||
511 | def test_month_start_of_month_with_time_zone | 511 | def test_month_start_of_month_with_time_zone |
512 | - assert_result_time :month, "2013-06-01 00:00:00 PDT", "2013-06-01 07:00:00", true | 512 | + assert_result_date :month, "2013-06-01", "2013-06-01 07:00:00", true |
513 | end | 513 | end |
514 | 514 | ||
515 | # month starts at 2am | 515 | # month starts at 2am |
516 | 516 | ||
517 | def test_month_end_of_month_day_start_2am | 517 | def test_month_end_of_month_day_start_2am |
518 | - assert_result_time :month, "2013-03-01 02:00:00 UTC", "2013-04-01 01:59:59", false, day_start: 2 | 518 | + assert_result_date :month, "2013-03-01", "2013-04-01 01:59:59", false, day_start: 2 |
519 | end | 519 | end |
520 | 520 | ||
521 | def test_month_start_of_month_day_start_2am | 521 | def test_month_start_of_month_day_start_2am |
522 | - assert_result_time :month, "2013-03-01 02:00:00 UTC", "2013-03-01 02:00:00", false, day_start: 2 | 522 | + assert_result_date :month, "2013-03-01", "2013-03-01 02:00:00", false, day_start: 2 |
523 | end | 523 | end |
524 | 524 | ||
525 | def test_month_end_of_month_with_time_zone_day_start_2am | 525 | def test_month_end_of_month_with_time_zone_day_start_2am |
526 | - assert_result_time :month, "2013-03-01 02:00:00 PST", "2013-04-01 08:59:59", true, day_start: 2 | 526 | + assert_result_date :month, "2013-03-01", "2013-04-01 08:59:59", true, day_start: 2 |
527 | end | 527 | end |
528 | 528 | ||
529 | def test_month_start_of_month_with_time_zone_day_start_2am | 529 | def test_month_start_of_month_with_time_zone_day_start_2am |
530 | - assert_result_time :month, "2013-03-01 02:00:00 PST", "2013-03-01 10:00:00", true, day_start: 2 | 530 | + assert_result_date :month, "2013-03-01", "2013-03-01 10:00:00", true, day_start: 2 |
531 | end | 531 | end |
532 | 532 | ||
533 | # quarter | 533 | # quarter |
534 | 534 | ||
535 | def test_quarter_end_of_quarter | 535 | def test_quarter_end_of_quarter |
536 | - assert_result_time :quarter, "2013-04-01 00:00:00 UTC", "2013-06-30 23:59:59" | 536 | + assert_result_date :quarter, "2013-04-01", "2013-06-30 23:59:59" |
537 | end | 537 | end |
538 | 538 | ||
539 | def test_quarter_start_of_quarter | 539 | def test_quarter_start_of_quarter |
540 | - assert_result_time :quarter, "2013-04-01 00:00:00 UTC", "2013-04-01 00:00:00" | 540 | + assert_result_date :quarter, "2013-04-01", "2013-04-01 00:00:00" |
541 | end | 541 | end |
542 | 542 | ||
543 | def test_quarter_end_of_quarter_with_time_zone | 543 | def test_quarter_end_of_quarter_with_time_zone |
544 | - assert_result_time :quarter, "2013-04-01 00:00:00 PDT", "2013-07-01 06:59:59", true | 544 | + assert_result_date :quarter, "2013-04-01", "2013-07-01 06:59:59", true |
545 | end | 545 | end |
546 | 546 | ||
547 | def test_quarter_start_of_quarter_with_time_zone | 547 | def test_quarter_start_of_quarter_with_time_zone |
548 | - assert_result_time :quarter, "2013-04-01 00:00:00 PDT", "2013-04-01 07:00:00", true | 548 | + assert_result_date :quarter, "2013-04-01", "2013-04-01 07:00:00", true |
549 | end | 549 | end |
550 | 550 | ||
551 | # quarter starts at 2am | 551 | # quarter starts at 2am |
552 | 552 | ||
553 | def test_quarter_end_of_quarter_day_start_2am | 553 | def test_quarter_end_of_quarter_day_start_2am |
554 | - assert_result_time :quarter, "2013-04-01 02:00:00 UTC", "2013-07-01 01:59:59", false, day_start: 2 | 554 | + assert_result_date :quarter, "2013-04-01", "2013-07-01 01:59:59", false, day_start: 2 |
555 | end | 555 | end |
556 | 556 | ||
557 | def test_quarter_start_of_quarter_day_start_2am | 557 | def test_quarter_start_of_quarter_day_start_2am |
558 | - assert_result_time :quarter, "2013-04-01 02:00:00 UTC", "2013-04-01 02:00:00", false, day_start: 2 | 558 | + assert_result_date :quarter, "2013-04-01", "2013-04-01 02:00:00", false, day_start: 2 |
559 | end | 559 | end |
560 | 560 | ||
561 | def test_quarter_end_of_quarter_with_time_zone_day_start_2am | 561 | def test_quarter_end_of_quarter_with_time_zone_day_start_2am |
562 | - assert_result_time :quarter, "2013-01-01 02:00:00 PST", "2013-04-01 08:59:59", true, day_start: 2 | 562 | + assert_result_date :quarter, "2013-01-01", "2013-04-01 08:59:59", true, day_start: 2 |
563 | end | 563 | end |
564 | 564 | ||
565 | def test_quarter_start_of_quarter_with_time_zone_day_start_2am | 565 | def test_quarter_start_of_quarter_with_time_zone_day_start_2am |
566 | - assert_result_time :quarter, "2013-01-01 02:00:00 PST", "2013-01-01 10:00:00", true, day_start: 2 | 566 | + assert_result_date :quarter, "2013-01-01", "2013-01-01 10:00:00", true, day_start: 2 |
567 | end | 567 | end |
568 | 568 | ||
569 | # year | 569 | # year |
570 | 570 | ||
571 | def test_year_end_of_year | 571 | def test_year_end_of_year |
572 | - assert_result_time :year, "2013-01-01 00:00:00 UTC", "2013-12-31 23:59:59" | 572 | + assert_result_date :year, "2013-01-01", "2013-12-31 23:59:59" |
573 | end | 573 | end |
574 | 574 | ||
575 | def test_year_start_of_year | 575 | def test_year_start_of_year |
576 | - assert_result_time :year, "2014-01-01 00:00:00 UTC", "2014-01-01 00:00:00" | 576 | + assert_result_date :year, "2014-01-01", "2014-01-01 00:00:00" |
577 | end | 577 | end |
578 | 578 | ||
579 | def test_year_end_of_year_with_time_zone | 579 | def test_year_end_of_year_with_time_zone |
580 | - assert_result_time :year, "2013-01-01 00:00:00 PST", "2014-01-01 07:59:59", true | 580 | + assert_result_date :year, "2013-01-01", "2014-01-01 07:59:59", true |
581 | end | 581 | end |
582 | 582 | ||
583 | def test_year_start_of_year_with_time_zone | 583 | def test_year_start_of_year_with_time_zone |
584 | - assert_result_time :year, "2014-01-01 00:00:00 PST", "2014-01-01 08:00:00", true | 584 | + assert_result_date :year, "2014-01-01", "2014-01-01 08:00:00", true |
585 | end | 585 | end |
586 | 586 | ||
587 | # year starts at 2am | 587 | # year starts at 2am |
588 | 588 | ||
589 | def test_year_end_of_year_day_start_2am | 589 | def test_year_end_of_year_day_start_2am |
590 | - assert_result_time :year, "2013-01-01 02:00:00 UTC", "2014-01-01 01:59:59", false, day_start: 2 | 590 | + assert_result_date :year, "2013-01-01", "2014-01-01 01:59:59", false, day_start: 2 |
591 | end | 591 | end |
592 | 592 | ||
593 | def test_year_start_of_year_day_start_2am | 593 | def test_year_start_of_year_day_start_2am |
594 | - assert_result_time :year, "2013-01-01 02:00:00 UTC", "2013-01-01 02:00:00", false, day_start: 2 | 594 | + assert_result_date :year, "2013-01-01", "2013-01-01 02:00:00", false, day_start: 2 |
595 | end | 595 | end |
596 | 596 | ||
597 | def test_year_end_of_year_with_time_zone_day_start_2am | 597 | def test_year_end_of_year_with_time_zone_day_start_2am |
598 | - assert_result_time :year, "2013-01-01 02:00:00 PST", "2014-01-01 09:59:59", true, day_start: 2 | 598 | + assert_result_date :year, "2013-01-01", "2014-01-01 09:59:59", true, day_start: 2 |
599 | end | 599 | end |
600 | 600 | ||
601 | def test_year_start_of_year_with_time_zone_day_start_2am | 601 | def test_year_start_of_year_with_time_zone_day_start_2am |
602 | - assert_result_time :year, "2013-01-01 02:00:00 PST", "2013-01-01 10:00:00", true, day_start: 2 | 602 | + assert_result_date :year, "2013-01-01", "2013-01-01 10:00:00", true, day_start: 2 |
603 | end | 603 | end |
604 | 604 | ||
605 | # hour of day | 605 | # hour of day |
@@ -765,68 +765,68 @@ module TestGroupdate | @@ -765,68 +765,68 @@ module TestGroupdate | ||
765 | end | 765 | end |
766 | 766 | ||
767 | def test_zeros_day | 767 | def test_zeros_day |
768 | - assert_zeros :day, "2013-05-01 20:00:00 UTC", ["2013-04-30 00:00:00 UTC", "2013-05-01 00:00:00 UTC", "2013-05-02 00:00:00 UTC"], "2013-04-30 00:00:00 UTC", "2013-05-02 23:59:59 UTC" | 768 | + assert_zeros_date :day, "2013-05-01 20:00:00 UTC", ["2013-04-30", "2013-05-01", "2013-05-02"], "2013-04-30 00:00:00 UTC", "2013-05-02 23:59:59 UTC" |
769 | end | 769 | end |
770 | 770 | ||
771 | def test_zeros_day_time_zone | 771 | def test_zeros_day_time_zone |
772 | - assert_zeros :day, "2013-05-01 20:00:00 PDT", ["2013-04-30 00:00:00 PDT", "2013-05-01 00:00:00 PDT", "2013-05-02 00:00:00 PDT"], "2013-04-30 00:00:00 PDT", "2013-05-02 23:59:59 PDT", true | 772 | + assert_zeros_date :day, "2013-05-01 20:00:00 PDT", ["2013-04-30", "2013-05-01", "2013-05-02"], "2013-04-30 00:00:00 PDT", "2013-05-02 23:59:59 PDT", true |
773 | end | 773 | end |
774 | 774 | ||
775 | def test_zeros_week | 775 | def test_zeros_week |
776 | - assert_zeros :week, "2013-05-01 20:00:00 UTC", ["2013-04-21 00:00:00 UTC", "2013-04-28 00:00:00 UTC", "2013-05-05 00:00:00 UTC"], "2013-04-27 23:59:59 UTC", "2013-05-11 23:59:59 UTC" | 776 | + assert_zeros_date :week, "2013-05-01 20:00:00 UTC", ["2013-04-21", "2013-04-28", "2013-05-05"], "2013-04-27 23:59:59 UTC", "2013-05-11 23:59:59 UTC" |
777 | end | 777 | end |
778 | 778 | ||
779 | def test_zeros_week_time_zone | 779 | def test_zeros_week_time_zone |
780 | - assert_zeros :week, "2013-05-01 20:00:00 PDT", ["2013-04-21 00:00:00 PDT", "2013-04-28 00:00:00 PDT", "2013-05-05 00:00:00 PDT"], "2013-04-27 23:59:59 PDT", "2013-05-11 23:59:59 PDT", true | 780 | + assert_zeros_date :week, "2013-05-01 20:00:00 PDT", ["2013-04-21", "2013-04-28", "2013-05-05"], "2013-04-27 23:59:59 PDT", "2013-05-11 23:59:59 PDT", true |
781 | end | 781 | end |
782 | 782 | ||
783 | def test_zeros_week_mon | 783 | def test_zeros_week_mon |
784 | - assert_zeros :week, "2013-05-01 20:00:00 UTC", ["2013-04-22 00:00:00 UTC", "2013-04-29 00:00:00 UTC", "2013-05-06 00:00:00 UTC"], "2013-04-27 23:59:59 UTC", "2013-05-11 23:59:59 UTC", false, week_start: :mon | 784 | + assert_zeros_date :week, "2013-05-01 20:00:00 UTC", ["2013-04-22", "2013-04-29", "2013-05-06"], "2013-04-27 23:59:59 UTC", "2013-05-11 23:59:59 UTC", false, week_start: :mon |
785 | end | 785 | end |
786 | 786 | ||
787 | def test_zeros_week_time_zone_mon | 787 | def test_zeros_week_time_zone_mon |
788 | - assert_zeros :week, "2013-05-01 20:00:00 PDT", ["2013-04-22 00:00:00 PDT", "2013-04-29 00:00:00 PDT", "2013-05-06 00:00:00 PDT"], "2013-04-27 23:59:59 PDT", "2013-05-11 23:59:59 PDT", true, week_start: :mon | 788 | + assert_zeros_date :week, "2013-05-01 20:00:00 PDT", ["2013-04-22", "2013-04-29", "2013-05-06"], "2013-04-27 23:59:59 PDT", "2013-05-11 23:59:59 PDT", true, week_start: :mon |
789 | end | 789 | end |
790 | 790 | ||
791 | def test_zeros_week_sat | 791 | def test_zeros_week_sat |
792 | - assert_zeros :week, "2013-05-01 20:00:00 UTC", ["2013-04-20 00:00:00 UTC", "2013-04-27 00:00:00 UTC", "2013-05-04 00:00:00 UTC"], "2013-04-26 23:59:59 UTC", "2013-05-10 23:59:59 UTC", false, week_start: :sat | 792 | + assert_zeros_date :week, "2013-05-01 20:00:00 UTC", ["2013-04-20", "2013-04-27", "2013-05-04"], "2013-04-26 23:59:59 UTC", "2013-05-10 23:59:59 UTC", false, week_start: :sat |
793 | end | 793 | end |
794 | 794 | ||
795 | def test_zeros_week_time_zone_sat | 795 | def test_zeros_week_time_zone_sat |
796 | - assert_zeros :week, "2013-05-01 20:00:00 PDT", ["2013-04-20 00:00:00 PDT", "2013-04-27 00:00:00 PDT", "2013-05-04 00:00:00 PDT"], "2013-04-26 23:59:59 PDT", "2013-05-10 23:59:59 PDT", true, week_start: :sat | 796 | + assert_zeros_date :week, "2013-05-01 20:00:00 PDT", ["2013-04-20", "2013-04-27", "2013-05-04"], "2013-04-26 23:59:59 PDT", "2013-05-10 23:59:59 PDT", true, week_start: :sat |
797 | end | 797 | end |
798 | 798 | ||
799 | def test_zeros_month | 799 | def test_zeros_month |
800 | - assert_zeros :month, "2013-04-16 20:00:00 UTC", ["2013-03-01 00:00:00 UTC", "2013-04-01 00:00:00 UTC", "2013-05-01 00:00:00 UTC"], "2013-03-01 00:00:00 UTC", "2013-05-31 23:59:59 UTC" | 800 | + assert_zeros_date :month, "2013-04-16 20:00:00 UTC", ["2013-03-01", "2013-04-01", "2013-05-01"], "2013-03-01", "2013-05-31 23:59:59 UTC" |
801 | end | 801 | end |
802 | 802 | ||
803 | def test_zeros_month_time_zone | 803 | def test_zeros_month_time_zone |
804 | - assert_zeros :month, "2013-04-16 20:00:00 PDT", ["2013-03-01 00:00:00 PST", "2013-04-01 00:00:00 PDT", "2013-05-01 00:00:00 PDT"], "2013-03-01 00:00:00 PST", "2013-05-31 23:59:59 PDT", true | 804 | + assert_zeros_date :month, "2013-04-16 20:00:00 PDT", ["2013-03-01", "2013-04-01", "2013-05-01"], "2013-03-01 00:00:00 PST", "2013-05-31 23:59:59 PDT", true |
805 | end | 805 | end |
806 | 806 | ||
807 | def test_zeros_quarter | 807 | def test_zeros_quarter |
808 | - assert_zeros :quarter, "2013-04-16 20:00:00 UTC", ["2013-01-01 00:00:00 UTC", "2013-04-01 00:00:00 UTC", "2013-07-01 00:00:00 UTC"], "2013-01-01 00:00:00 UTC", "2013-09-30 23:59:59 UTC" | 808 | + assert_zeros_date :quarter, "2013-04-16 20:00:00 UTC", ["2013-01-01", "2013-04-01", "2013-07-01"], "2013-01-01", "2013-09-30 23:59:59 UTC" |
809 | end | 809 | end |
810 | 810 | ||
811 | def test_zeros_quarter_time_zone | 811 | def test_zeros_quarter_time_zone |
812 | - assert_zeros :quarter, "2013-04-16 20:00:00 PDT", ["2013-01-01 00:00:00 PST", "2013-04-01 00:00:00 PDT", "2013-07-01 00:00:00 PDT"], "2013-01-01 00:00:00 PST", "2013-09-30 23:59:59 PDT", true | 812 | + assert_zeros_date :quarter, "2013-04-16 20:00:00 PDT", ["2013-01-01", "2013-04-01", "2013-07-01"], "2013-01-01 00:00:00 PST", "2013-09-30 23:59:59 PDT", true |
813 | end | 813 | end |
814 | 814 | ||
815 | def test_zeros_year | 815 | def test_zeros_year |
816 | - assert_zeros :year, "2013-04-16 20:00:00 UTC", ["2012-01-01 00:00:00 UTC", "2013-01-01 00:00:00 UTC", "2014-01-01 00:00:00 UTC"], "2012-01-01 00:00:00 UTC", "2014-12-31 23:59:59 UTC" | 816 | + assert_zeros_date :year, "2013-04-16 20:00:00 UTC", ["2012-01-01", "2013-01-01", "2014-01-01"], "2012-01-01", "2014-12-31 23:59:59 UTC" |
817 | end | 817 | end |
818 | 818 | ||
819 | def test_zeros_year_time_zone | 819 | def test_zeros_year_time_zone |
820 | - assert_zeros :year, "2013-04-16 20:00:00 PDT", ["2012-01-01 00:00:00 PST", "2013-01-01 00:00:00 PST", "2014-01-01 00:00:00 PST"], "2012-01-01 00:00:00 PST", "2014-12-31 23:59:59 PST", true | 820 | + assert_zeros_date :year, "2013-04-16 20:00:00 PDT", ["2012-01-01 00:00:00 PST", "2013-01-01 00:00:00 PST", "2014-01-01 00:00:00 PST"], "2012-01-01 00:00:00 PST", "2014-12-31 23:59:59 PST", true |
821 | end | 821 | end |
822 | 822 | ||
823 | def test_zeros_day_of_week | 823 | def test_zeros_day_of_week |
824 | - create_user "2013-05-01 00:00:00 UTC" | 824 | + create_user "2013-05-01" |
825 | expected = {} | 825 | expected = {} |
826 | 7.times do |n| | 826 | 7.times do |n| |
827 | expected[n] = n == 3 ? 1 : 0 | 827 | expected[n] = n == 3 ? 1 : 0 |
828 | end | 828 | end |
829 | - assert_equal expected, call_method(:day_of_week, :created_at, {}) | 829 | + assert_equal expected, call_method(:day_of_week, :created_at, {series: true}) |
830 | end | 830 | end |
831 | 831 | ||
832 | def test_zeros_hour_of_day | 832 | def test_zeros_hour_of_day |
@@ -835,130 +835,130 @@ module TestGroupdate | @@ -835,130 +835,130 @@ module TestGroupdate | ||
835 | 24.times do |n| | 835 | 24.times do |n| |
836 | expected[n] = n == 20 ? 1 : 0 | 836 | expected[n] = n == 20 ? 1 : 0 |
837 | end | 837 | end |
838 | - assert_equal expected, call_method(:hour_of_day, :created_at, {}) | 838 | + assert_equal expected, call_method(:hour_of_day, :created_at, {series: true}) |
839 | end | 839 | end |
840 | 840 | ||
841 | def test_zeros_day_of_month | 841 | def test_zeros_day_of_month |
842 | - create_user "1978-12-18 00:00:00 UTC" | 842 | + create_user "1978-12-18" |
843 | expected = {} | 843 | expected = {} |
844 | (1..31).each do |n| | 844 | (1..31).each do |n| |
845 | expected[n] = n == 18 ? 1 : 0 | 845 | expected[n] = n == 18 ? 1 : 0 |
846 | end | 846 | end |
847 | - assert_equal expected, call_method(:day_of_month, :created_at, {}) | 847 | + assert_equal expected, call_method(:day_of_month, :created_at, {series: true}) |
848 | end | 848 | end |
849 | 849 | ||
850 | def test_zeros_month_of_year | 850 | def test_zeros_month_of_year |
851 | - create_user "2013-05-01 00:00:00 UTC" | 851 | + create_user "2013-05-01" |
852 | expected = {} | 852 | expected = {} |
853 | (1..12).each do |n| | 853 | (1..12).each do |n| |
854 | expected[n] = n == 5 ? 1 : 0 | 854 | expected[n] = n == 5 ? 1 : 0 |
855 | end | 855 | end |
856 | - assert_equal expected, call_method(:month_of_year, :created_at, {}) | 856 | + assert_equal expected, call_method(:month_of_year, :created_at, {series: true}) |
857 | end | 857 | end |
858 | 858 | ||
859 | def test_zeros_excludes_end | 859 | def test_zeros_excludes_end |
860 | - create_user "2013-05-02 00:00:00 UTC" | 860 | + create_user "2013-05-02" |
861 | expected = { | 861 | expected = { |
862 | - utc.parse("2013-05-01 00:00:00 UTC") => 0 | 862 | + Date.parse("2013-05-01") => 0 |
863 | } | 863 | } |
864 | - assert_equal expected, call_method(:day, :created_at, range: Time.parse("2013-05-01 00:00:00 UTC")...Time.parse("2013-05-02 00:00:00 UTC")) | 864 | + assert_equal expected, call_method(:day, :created_at, range: Date.parse("2013-05-01")...Date.parse("2013-05-02"), series: true) |
865 | end | 865 | end |
866 | 866 | ||
867 | def test_zeros_datetime | 867 | def test_zeros_datetime |
868 | - create_user "2013-05-01 00:00:00 UTC" | 868 | + create_user "2013-05-01" |
869 | expected = { | 869 | expected = { |
870 | - utc.parse("2013-05-01 00:00:00 UTC") => 1 | 870 | + Date.parse("2013-05-01") => 1 |
871 | } | 871 | } |
872 | - assert_equal expected, call_method(:day, :created_at, range: DateTime.parse("2013-05-01 00:00:00 UTC")..DateTime.parse("2013-05-01 00:00:00 UTC")) | 872 | + assert_equal expected, call_method(:day, :created_at, range: DateTime.parse("2013-05-01")..DateTime.parse("2013-05-01"), series: true) |
873 | end | 873 | end |
874 | 874 | ||
875 | def test_zeros_null_value | 875 | def test_zeros_null_value |
876 | create_user nil | 876 | create_user nil |
877 | - assert_equal 0, call_method(:hour_of_day, :created_at, range: true)[0] | 877 | + assert_equal 0, call_method(:hour_of_day, :created_at, range: true, series: true)[0] |
878 | end | 878 | end |
879 | 879 | ||
880 | def test_zeroes_range_true | 880 | def test_zeroes_range_true |
881 | - create_user "2013-05-01 00:00:00 UTC" | ||
882 | - create_user "2013-05-03 00:00:00 UTC" | 881 | + create_user "2013-05-01" |
882 | + create_user "2013-05-03" | ||
883 | expected = { | 883 | expected = { |
884 | - utc.parse("2013-05-01 00:00:00 UTC") => 1, | ||
885 | - utc.parse("2013-05-02 00:00:00 UTC") => 0, | ||
886 | - utc.parse("2013-05-03 00:00:00 UTC") => 1 | 884 | + Date.parse("2013-05-01") => 1, |
885 | + Date.parse("2013-05-02") => 0, | ||
886 | + Date.parse("2013-05-03") => 1 | ||
887 | } | 887 | } |
888 | - assert_equal expected, call_method(:day, :created_at, range: true) | 888 | + assert_equal expected, call_method(:day, :created_at, range: true, series: true) |
889 | end | 889 | end |
890 | 890 | ||
891 | # week_start | 891 | # week_start |
892 | 892 | ||
893 | def test_week_start | 893 | def test_week_start |
894 | Groupdate.week_start = :mon | 894 | Groupdate.week_start = :mon |
895 | - assert_result_time :week, "2013-03-18 00:00:00 UTC", "2013-03-24 23:59:59" | 895 | + assert_result_date :week, "2013-03-18", "2013-03-24 23:59:59" |
896 | end | 896 | end |
897 | 897 | ||
898 | def test_week_start_and_start_option | 898 | def test_week_start_and_start_option |
899 | Groupdate.week_start = :mon | 899 | Groupdate.week_start = :mon |
900 | - assert_result_time :week, "2013-03-16 00:00:00 UTC", "2013-03-22 23:59:59", false, week_start: :sat | 900 | + assert_result_date :week, "2013-03-16", "2013-03-22 23:59:59", false, week_start: :sat |
901 | end | 901 | end |
902 | 902 | ||
903 | # misc | 903 | # misc |
904 | 904 | ||
905 | def test_order_hour_of_day_reverse_option | 905 | def test_order_hour_of_day_reverse_option |
906 | - assert_equal 23, call_method(:hour_of_day, :created_at, reverse: true).keys.first | 906 | + assert_equal 23, call_method(:hour_of_day, :created_at, reverse: true, series: true).keys.first |
907 | end | 907 | end |
908 | 908 | ||
909 | def test_time_zone | 909 | def test_time_zone |
910 | - create_user "2013-05-01 00:00:00 UTC" | 910 | + create_user "2013-05-01" |
911 | time_zone = "Pacific Time (US & Canada)" | 911 | time_zone = "Pacific Time (US & Canada)" |
912 | - assert_equal time_zone, call_method(:day, :created_at, time_zone: time_zone).keys.first.time_zone.name | 912 | + assert_equal time_zone, call_method(:hour, :created_at, time_zone: time_zone).keys.first.time_zone.name |
913 | end | 913 | end |
914 | 914 | ||
915 | def test_format_day | 915 | def test_format_day |
916 | - create_user "2014-03-01 00:00:00 UTC" | 916 | + create_user "2014-03-01" |
917 | assert_format :day, "March 1, 2014", "%B %-e, %Y" | 917 | assert_format :day, "March 1, 2014", "%B %-e, %Y" |
918 | end | 918 | end |
919 | 919 | ||
920 | def test_format_month | 920 | def test_format_month |
921 | - create_user "2014-03-01 00:00:00 UTC" | 921 | + create_user "2014-03-01" |
922 | assert_format :month, "March 2014", "%B %Y" | 922 | assert_format :month, "March 2014", "%B %Y" |
923 | end | 923 | end |
924 | 924 | ||
925 | def test_format_quarter | 925 | def test_format_quarter |
926 | - create_user "2014-03-05 00:00:00 UTC" | 926 | + create_user "2014-03-05" |
927 | assert_format :quarter, "January 1, 2014", "%B %-e, %Y" | 927 | assert_format :quarter, "January 1, 2014", "%B %-e, %Y" |
928 | end | 928 | end |
929 | 929 | ||
930 | def test_format_year | 930 | def test_format_year |
931 | - create_user "2014-03-01 00:00:00 UTC" | 931 | + create_user "2014-03-01" |
932 | assert_format :year, "2014", "%Y" | 932 | assert_format :year, "2014", "%Y" |
933 | end | 933 | end |
934 | 934 | ||
935 | def test_format_hour_of_day | 935 | def test_format_hour_of_day |
936 | - create_user "2014-03-01 00:00:00 UTC" | 936 | + create_user "2014-03-01" |
937 | assert_format :hour_of_day, "12 am", "%-l %P" | 937 | assert_format :hour_of_day, "12 am", "%-l %P" |
938 | end | 938 | end |
939 | 939 | ||
940 | def test_format_hour_of_day_day_start | 940 | def test_format_hour_of_day_day_start |
941 | - create_user "2014-03-01 00:00:00 UTC" | 941 | + create_user "2014-03-01" |
942 | assert_format :hour_of_day, "2 am", "%-l %P", day_start: 2 | 942 | assert_format :hour_of_day, "2 am", "%-l %P", day_start: 2 |
943 | end | 943 | end |
944 | 944 | ||
945 | def test_format_day_of_week | 945 | def test_format_day_of_week |
946 | - create_user "2014-03-01 00:00:00 UTC" | 946 | + create_user "2014-03-01" |
947 | assert_format :day_of_week, "Sun", "%a" | 947 | assert_format :day_of_week, "Sun", "%a" |
948 | end | 948 | end |
949 | 949 | ||
950 | def test_format_day_of_week_week_start | 950 | def test_format_day_of_week_week_start |
951 | - create_user "2014-03-01 00:00:00 UTC" | 951 | + create_user "2014-03-01" |
952 | assert_format :day_of_week, "Sun", "%a", week_start: :sat | 952 | assert_format :day_of_week, "Sun", "%a", week_start: :sat |
953 | end | 953 | end |
954 | 954 | ||
955 | def test_format_day_of_month | 955 | def test_format_day_of_month |
956 | - create_user "2014-03-01 00:00:00 UTC" | 956 | + create_user "2014-03-01" |
957 | assert_format :day_of_month, " 1", "%e" | 957 | assert_format :day_of_month, " 1", "%e" |
958 | end | 958 | end |
959 | 959 | ||
960 | def test_format_month_of_year | 960 | def test_format_month_of_year |
961 | - create_user "2014-01-01 00:00:00 UTC" | 961 | + create_user "2014-01-01" |
962 | assert_format :month_of_year, "Jan", "%b" | 962 | assert_format :month_of_year, "Jan", "%b" |
963 | end | 963 | end |
964 | 964 | ||
@@ -983,17 +983,17 @@ module TestGroupdate | @@ -983,17 +983,17 @@ module TestGroupdate | ||
983 | # day start | 983 | # day start |
984 | 984 | ||
985 | def test_day_start_decimal_end_of_day | 985 | def test_day_start_decimal_end_of_day |
986 | - assert_result_time :day, "2013-05-03 02:30:00 UTC", "2013-05-04 02:29:59", false, day_start: 2.5 | 986 | + assert_result_date :day, "2013-05-03", "2013-05-04 02:29:59", false, day_start: 2.5 |
987 | end | 987 | end |
988 | 988 | ||
989 | def test_day_start_decimal_start_of_day | 989 | def test_day_start_decimal_start_of_day |
990 | - assert_result_time :day, "2013-05-03 02:30:00 UTC", "2013-05-03 02:30:00", false, day_start: 2.5 | 990 | + assert_result_date :day, "2013-05-03", "2013-05-03 02:30:00", false, day_start: 2.5 |
991 | end | 991 | end |
992 | 992 | ||
993 | # helpers | 993 | # helpers |
994 | 994 | ||
995 | def assert_format(method, expected, format, options = {}) | 995 | def assert_format(method, expected, format, options = {}) |
996 | - assert_equal expected, call_method(method, :created_at, options.merge(format: format)).keys.first | 996 | + assert_equal expected, call_method(method, :created_at, options.merge(format: format, series: true)).keys.first |
997 | end | 997 | end |
998 | 998 | ||
999 | def assert_result_time(method, expected, time_str, time_zone = false, options = {}) | 999 | def assert_result_time(method, expected, time_str, time_zone = false, options = {}) |
@@ -1001,6 +1001,15 @@ module TestGroupdate | @@ -1001,6 +1001,15 @@ module TestGroupdate | ||
1001 | assert_equal expected, result(method, time_str, time_zone, options) | 1001 | assert_equal expected, result(method, time_str, time_zone, options) |
1002 | end | 1002 | end |
1003 | 1003 | ||
1004 | + def assert_result_date(method, expected_str, time_str, time_zone = false, options = {}) | ||
1005 | + create_user time_str | ||
1006 | + expected = {Date.parse(expected_str) => 1} | ||
1007 | + assert_equal expected, call_method(method, :created_at, options.merge(time_zone: time_zone ? "Pacific Time (US & Canada)" : nil)) | ||
1008 | + expected = {(time_zone ? pt : utc).parse(expected_str) + options[:day_start].to_f.hours => 1} | ||
1009 | + assert_equal expected, call_method(method, :created_at, options.merge(dates: false, time_zone: time_zone ? "Pacific Time (US & Canada)" : nil)) | ||
1010 | + # assert_equal expected, call_method(method, :created_on, options.merge(time_zone: time_zone ? "Pacific Time (US & Canada)" : nil)) | ||
1011 | + end | ||
1012 | + | ||
1004 | def assert_result(method, expected, time_str, time_zone = false, options = {}) | 1013 | def assert_result(method, expected, time_str, time_zone = false, options = {}) |
1005 | assert_equal 1, result(method, time_str, time_zone, options)[expected] | 1014 | assert_equal 1, result(method, time_str, time_zone, options)[expected] |
1006 | end | 1015 | end |
@@ -1016,7 +1025,16 @@ module TestGroupdate | @@ -1016,7 +1025,16 @@ module TestGroupdate | ||
1016 | keys.each_with_index do |key, i| | 1025 | keys.each_with_index do |key, i| |
1017 | expected[utc.parse(key).in_time_zone(time_zone ? "Pacific Time (US & Canada)" : utc)] = i == 1 ? 1 : 0 | 1026 | expected[utc.parse(key).in_time_zone(time_zone ? "Pacific Time (US & Canada)" : utc)] = i == 1 ? 1 : 0 |
1018 | end | 1027 | end |
1019 | - assert_equal expected, call_method(method, :created_at, options.merge(time_zone: time_zone ? "Pacific Time (US & Canada)" : nil, range: Time.parse(range_start)..Time.parse(range_end))) | 1028 | + assert_equal expected, call_method(method, :created_at, options.merge(series: true, time_zone: time_zone ? "Pacific Time (US & Canada)" : nil, range: Time.parse(range_start)..Time.parse(range_end))) |
1029 | + end | ||
1030 | + | ||
1031 | + def assert_zeros_date(method, created_at, keys, range_start, range_end, time_zone = nil, options = {}) | ||
1032 | + create_user created_at | ||
1033 | + expected = {} | ||
1034 | + keys.each_with_index do |key, i| | ||
1035 | + expected[Date.parse(key)] = i == 1 ? 1 : 0 | ||
1036 | + end | ||
1037 | + assert_equal expected, call_method(method, :created_at, options.merge(series: true, time_zone: time_zone ? "Pacific Time (US & Canada)" : nil, range: Time.parse(range_start)..Time.parse(range_end))) | ||
1020 | end | 1038 | end |
1021 | 1039 | ||
1022 | def this_year | 1040 | def this_year |
@@ -1027,6 +1045,10 @@ module TestGroupdate | @@ -1027,6 +1045,10 @@ module TestGroupdate | ||
1027 | ActiveSupport::TimeZone["UTC"] | 1045 | ActiveSupport::TimeZone["UTC"] |
1028 | end | 1046 | end |
1029 | 1047 | ||
1048 | + def pt | ||
1049 | + ActiveSupport::TimeZone["Pacific Time (US & Canada)"] | ||
1050 | + end | ||
1051 | + | ||
1030 | def brasilia | 1052 | def brasilia |
1031 | ActiveSupport::TimeZone["Brasilia"] | 1053 | ActiveSupport::TimeZone["Brasilia"] |
1032 | end | 1054 | end |