Commit 395709249796cf984a027d2ab2ff10053753956b

Authored by Andrew Kane
2 parents 4edaed72 a0ed30ca
Exists in sqlite

Merge branch 'master' into sqlite

Showing 2 changed files with 6 additions and 6 deletions   Show diff stats
lib/groupdate.rb
... ... @@ -4,7 +4,7 @@ require "groupdate/version"
4 4 require "groupdate/magic"
5 5  
6 6 module Groupdate
7   - class Error < StandardError; end
  7 + class Error < RuntimeError; end
8 8  
9 9 PERIODS = [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :day_of_month, :month_of_year]
10 10 # backwards compatibility for anyone who happened to use it
... ...
lib/groupdate/magic.rb
... ... @@ -8,9 +8,9 @@ module Groupdate
8 8 @field = field
9 9 @options = options
10 10  
11   - raise "Unrecognized time zone" unless time_zone
  11 + raise Groupdate::Error, "Unrecognized time zone" unless time_zone
12 12  
13   - raise "Unrecognized :week_start option" if field == :week && !week_start
  13 + raise Groupdate::Error, "Unrecognized :week_start option" if field == :week && !week_start
14 14 end
15 15  
16 16 def group_by(enum, &_block)
... ... @@ -20,7 +20,7 @@ module Groupdate
20 20  
21 21 def relation(column, relation)
22 22 if relation.default_timezone == :local
23   - raise "ActiveRecord::Base.default_timezone must be :utc to use Groupdate"
  23 + raise Groupdate::Error, "ActiveRecord::Base.default_timezone must be :utc to use Groupdate"
24 24 end
25 25  
26 26 time_zone = self.time_zone.tzinfo.name
... ... @@ -131,7 +131,7 @@ module Groupdate
131 131 ["CONVERT_TIMEZONE(?, 'Etc/UTC', DATE_TRUNC(?, CONVERT_TIMEZONE(?, #{column}) - INTERVAL '#{day_start} second'))::timestamp + INTERVAL '#{day_start} second'", time_zone, field, time_zone]
132 132 end
133 133 else
134   - raise "Connection adapter not supported: #{adapter_name}"
  134 + raise Groupdate::Error, "Connection adapter not supported: #{adapter_name}"
135 135 end
136 136  
137 137 if adapter_name == "MySQL" && field == :week
... ... @@ -383,7 +383,7 @@ module Groupdate
383 383 when :month_of_year
384 384 time.month
385 385 else
386   - raise "Invalid field"
  386 + raise Groupdate::Error, "Invalid field"
387 387 end
388 388  
389 389 time.is_a?(Time) ? time + day_start.seconds : time
... ...