groupdate 4.1.2 → 4.2.0

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
  SHA256:
3
- metadata.gz: 28ba8881c2af7869f774eceebed739e851e81d7d28b53473762260e7c4297134
4
- data.tar.gz: e0031f94b52b53255bdbe01c0f72d5c7abcb20d94b02d81bf9e31344a957919a
3
+ metadata.gz: 5a10a3b53e404c803b6f78e42b3d4cb43088cf9884db7de2e7a8ffd10d91b786
4
+ data.tar.gz: 6b8123a4e90331d58d656f176684660eedeb7722b754d0325feaea87d897c9fd
5
5
  SHA512:
6
- metadata.gz: cb863625ed13dea87c18b31bf897f0e6d6c00bb02b3c41aaf08a11221cc52a8cbfea5cb4f8fe991d33552b0f9294c9c2c04bfb1c220bdcfb8688dbacc848ceed
7
- data.tar.gz: 805c5290d0652b2f82c3426fb253dc962bc9c2e4903b3edb1aa2451dc252f0c94bbc7737d3c1b8ddd429c5844ca99c8c01b1e872f1efd4980a747eb4cd2c4294
6
+ metadata.gz: eb01ba56326b819e783784dfe09b14ece4bda6ab53bcf2ea7b61a19b94f4d54eaa7ac7b6847cbec3c9e3056d7fac866a4eff83edf1d5b4a0b5a89d9a2ac82d9a
7
+ data.tar.gz: 57167fca94dd3b1f61003cb6e3af9164085daaa46da3ff51190d356b1332c3fcf9bac6e26a95cabc803cabd18c1c6d38644163a80ade6b762fea6316ab42a562
@@ -1,3 +1,8 @@
1
+ ## 4.2.0
2
+
3
+ - Added `day_of_year`
4
+ - Dropped support for Rails 4.2
5
+
1
6
  ## 4.1.2
2
7
 
3
8
  - Fixed error with empty data and `current: false`
@@ -57,7 +57,7 @@ brew services start mysql
57
57
 
58
58
  # create databases
59
59
  createdb groupdate_test
60
- mysql -u root -e "create database groupdate_test"
60
+ mysqladmin create groupdate_test
61
61
  mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
62
62
 
63
63
  # clone the repo and run the tests
data/README.md CHANGED
@@ -56,9 +56,10 @@ and
56
56
  - hour_of_day
57
57
  - day_of_week (Sunday = 0, Monday = 1, etc)
58
58
  - day_of_month
59
+ - day_of_year
59
60
  - month_of_year
60
61
 
61
- Use it anywhere you can use `group`. Works with `count`, `sum`, `minimum`, `maximum`, and `average`. For `median`, check out [ActiveMedian](https://github.com/ankane/active_median). For other aggregate functions, including multiple together, check out [CalculateAll](https://github.com/codesnik/calculate-all).
62
+ Use it anywhere you can use `group`. Works with `count`, `sum`, `minimum`, `maximum`, and `average`. For `median`, check out [ActiveMedian](https://github.com/ankane/active_median).
62
63
 
63
64
  ### Time Zones
64
65
 
@@ -228,7 +229,13 @@ users.group_by_day(time_zone: time_zone) { |u| u.created_at }
228
229
  Count
229
230
 
230
231
  ```ruby
231
- Hash[ users.group_by_day { |u| u.created_at }.map { |k, v| [k, v.size] } ]
232
+ users.group_by_day { |u| u.created_at }.map { |k, v| [k, v.size] }.to_h
233
+ ```
234
+
235
+ Get the entire series with:
236
+
237
+ ```ruby
238
+ users.group_by_day(series: true) { |u| u.created_at }
232
239
  ```
233
240
 
234
241
  ## Additional Instructions
@@ -8,7 +8,7 @@ require "groupdate/magic"
8
8
  module Groupdate
9
9
  class Error < RuntimeError; end
10
10
 
11
- PERIODS = [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :minute_of_hour, :day_of_month, :month_of_year]
11
+ PERIODS = [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :minute_of_hour, :day_of_month, :day_of_year, :month_of_year]
12
12
  METHODS = PERIODS.map { |v| :"group_by_#{v}" } + [:group_by_period]
13
13
 
14
14
  mattr_accessor :week_start, :day_start, :time_zone, :dates
@@ -87,7 +87,7 @@ module Groupdate
87
87
  case period
88
88
  when :day_of_week
89
89
  lambda { |k| (k.to_i - 1 - week_start) % 7 }
90
- when :hour_of_day, :day_of_month, :month_of_year, :minute_of_hour
90
+ when :hour_of_day, :day_of_month, :day_of_year, :month_of_year, :minute_of_hour
91
91
  lambda { |k| k.to_i }
92
92
  else
93
93
  utc = ActiveSupport::TimeZone["UTC"]
@@ -31,6 +31,8 @@ module Groupdate
31
31
  case period
32
32
  when :day_of_week
33
33
  ["DAYOFWEEK(CONVERT_TZ(DATE_SUB(#{column}, INTERVAL #{day_start} second), '+00:00', ?)) - 1", time_zone]
34
+ when :day_of_year
35
+ ["DAYOFYEAR(CONVERT_TZ(DATE_SUB(#{column}, INTERVAL #{day_start} second), '+00:00', ?))", time_zone]
34
36
  when :hour_of_day
35
37
  ["(EXTRACT(HOUR from CONVERT_TZ(#{column}, '+00:00', ?)) + 24 - #{day_start / 3600}) % 24", time_zone]
36
38
  when :minute_of_hour
@@ -66,6 +68,8 @@ module Groupdate
66
68
  case period
67
69
  when :day_of_week
68
70
  ["EXTRACT(DOW from #{column}::timestamptz AT TIME ZONE ? - INTERVAL '#{day_start} second')::integer", time_zone]
71
+ when :day_of_year
72
+ ["EXTRACT(DOY from #{column}::timestamptz AT TIME ZONE ? - INTERVAL '#{day_start} second')::integer", time_zone]
69
73
  when :hour_of_day
70
74
  ["EXTRACT(HOUR from #{column}::timestamptz AT TIME ZONE ? - INTERVAL '#{day_start} second')::integer", time_zone]
71
75
  when :minute_of_hour
@@ -99,6 +103,8 @@ module Groupdate
99
103
  "%d"
100
104
  when :month_of_year
101
105
  "%m"
106
+ when :day_of_year
107
+ "%j"
102
108
  when :second
103
109
  "%Y-%m-%d %H:%M:%S UTC"
104
110
  when :minute
@@ -127,6 +133,8 @@ module Groupdate
127
133
  ["EXTRACT(MINUTE from CONVERT_TIMEZONE(?, #{column}::timestamp) - INTERVAL '#{day_start} second')::integer", time_zone]
128
134
  when :day_of_month
129
135
  ["EXTRACT(DAY from CONVERT_TIMEZONE(?, #{column}::timestamp) - INTERVAL '#{day_start} second')::integer", time_zone]
136
+ when :day_of_year
137
+ ["EXTRACT(DOY from CONVERT_TIMEZONE(?, #{column}::timestamp) - INTERVAL '#{day_start} second')::integer", time_zone]
130
138
  when :month_of_year
131
139
  ["EXTRACT(MONTH from CONVERT_TIMEZONE(?, #{column}::timestamp) - INTERVAL '#{day_start} second')::integer", time_zone]
132
140
  when :week # start on Sunday, not Redshift default Monday
@@ -79,6 +79,8 @@ module Groupdate
79
79
  time.day
80
80
  when :month_of_year
81
81
  time.month
82
+ when :day_of_year
83
+ time.yday
82
84
  else
83
85
  raise Groupdate::Error, "Invalid period"
84
86
  end
@@ -141,6 +143,8 @@ module Groupdate
141
143
  0..59
142
144
  when :day_of_month
143
145
  1..31
146
+ when :day_of_year
147
+ 1..366
144
148
  when :month_of_year
145
149
  1..12
146
150
  else
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "4.1.2"
2
+ VERSION = "4.2.0"
3
3
  end
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: 4.1.2
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-27 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,44 +84,44 @@ dependencies:
84
84
  name: pg
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "<"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '1'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "<"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '1'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: mysql2
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "<"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0.5'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "<"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '0.5'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: sqlite3
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 1.3.0
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 1.3.0
124
+ version: '0'
125
125
  description:
126
126
  email: andrew@chartkick.com
127
127
  executables: []
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
154
  - - ">="
155
155
  - !ruby/object:Gem::Version
156
- version: '2.2'
156
+ version: '2.4'
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
159
  - - ">="