| Class | Sequel::SQL::DateAdd |
| In: |
lib/sequel/extensions/date_arithmetic.rb
|
| Parent: | GenericExpression |
The DateAdd class represents the addition of an interval to a date/timestamp expression.
| expr | [R] | The expression that the interval is being added to. |
| interval | [R] | The interval added to the expression, as a hash with symbol keys. |
Supports two types of intervals:
| Hash : | Used directly, but values cannot be plain strings. |
| ActiveSupport::Duration : | Converted to a hash using the interval‘s parts. |
# File lib/sequel/extensions/date_arithmetic.rb, line 164
164: def initialize(expr, interval)
165: @expr = expr
166: @interval = if interval.is_a?(Hash)
167: interval.each_value do |v|
168: # Attempt to prevent SQL injection by users who pass untrusted strings
169: # as interval values.
170: if v.is_a?(String) && !v.is_a?(LiteralString)
171: raise Sequel::InvalidValue, "cannot provide String value as interval part: #{v.inspect}"
172: end
173: end
174: interval
175: else
176: h = Hash.new(0)
177: interval.parts.each{|unit, value| h[unit] += value}
178: {}.merge(h)
179: end
180: end