The DateAdd class represents the addition of an interval to a date/timestamp expression.
The type to cast the expression to. nil if not overridden, in which cast the generic timestamp type for the database will be used.
The expression that the interval is being added to.
The interval added to the expression, as a hash with symbol keys.
Supports two types of intervals:
Used directly, but values cannot be plain strings.
Converted to a hash using the interval's parts.
# File lib/sequel/extensions/date_arithmetic.rb, line 187 def initialize(expr, interval, opts=OPTS) @expr = expr @interval = if interval.is_a?(Hash) interval.each_value do |v| # Attempt to prevent SQL injection by users who pass untrusted strings # as interval values. if v.is_a?(String) && !v.is_a?(LiteralString) raise Sequel::InvalidValue, "cannot provide String value as interval part: #{v.inspect}" end end Hash[interval] else h = Hash.new(0) interval.parts.each{|unit, value| h[unit] += value} Hash[h] end @interval.freeze @cast_type = opts[:cast] if opts[:cast] freeze end