lib/sequel/extensions/date_arithmetic.rb in sequel-4.49.0 vs lib/sequel/extensions/date_arithmetic.rb in sequel-5.0.0
- old
+ new
@@ -8,12 +8,12 @@
# DB.extension :date_arithmetic
#
# Then you can use the Sequel.date_add and Sequel.date_sub methods
# to return Sequel expressions:
#
-# add = Sequel.date_add(:date_column, :years=>1, :months=>2, :days=>3)
-# sub = Sequel.date_sub(:date_column, :hours=>1, :minutes=>2, :seconds=>3)
+# add = Sequel.date_add(:date_column, years: 1, months: 2, days: 3)
+# sub = Sequel.date_sub(:date_column, hours: 1, minutes: 2, seconds: 3)
#
# In addition to specifying the interval as a hash, there is also
# support for specifying the interval as an ActiveSupport::Duration
# object:
#
@@ -64,12 +64,10 @@
MSSQL_DURATION_UNITS = DURATION_UNITS.zip(DURATION_UNITS.map{|s| Sequel.lit(s.to_s[0...-1]).freeze}).freeze
H2_DURATION_UNITS = DURATION_UNITS.zip(DURATION_UNITS.map{|s| s.to_s[0...-1].freeze}).freeze
DERBY_DURATION_UNITS = DURATION_UNITS.zip(DURATION_UNITS.map{|s| Sequel.lit("SQL_TSI_#{s.to_s.upcase[0...-1]}").freeze}).freeze
ACCESS_DURATION_UNITS = DURATION_UNITS.zip(%w'yyyy m d h n s'.map(&:freeze)).freeze
DB2_DURATION_UNITS = DURATION_UNITS.zip(DURATION_UNITS.map{|s| Sequel.lit(s.to_s).freeze}).freeze
- FDBSQL_DURATION_UNITS = DURATION_UNITS.zip(DURATION_UNITS.map{|s| Sequel.lit(s.to_s.chop).freeze}).freeze
- Sequel::Deprecation.deprecate_constant(self, :FDBSQL_DURATION_UNITS)
# Append the SQL fragment for the DateAdd expression to the SQL query.
def date_add_sql_append(sql, da)
if defined?(super)
return super
@@ -91,12 +89,11 @@
args = [expr]
each_valid_interval_unit(h, DEF_DURATION_UNITS) do |value, sql_unit|
args << "#{value} #{sql_unit}"
end
return function_sql_append(sql, Sequel.function(:datetime, *args))
- # SEQUEL5: Remove cubrid
- when :mysql, :hsqldb, :cubrid
+ when :mysql, :hsqldb
if db_type == :hsqldb
# HSQLDB requires 2.2.9+ for the DATE_ADD function
expr = Sequel.cast(expr, Time)
end
each_valid_interval_unit(h, MYSQL_DURATION_UNITS) do |value, sql_unit|
@@ -179,15 +176,18 @@
# 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
- interval
+ Hash[interval]
else
h = Hash.new(0)
interval.parts.each{|unit, value| h[unit] += value}
Hash[h]
end
+
+ @interval.freeze
+ freeze
end
to_s_method :date_add_sql
end
end