Sha256: b6df11544806fb25cb6e63fdf55c1785c895aaa4a50084bf431222286f099b68

Contents?: true

Size: 1.13 KB

Versions: 79

Compression:

Stored size: 1.13 KB

Contents

# frozen-string-literal: true
#
# This switches the default parsing of strings into Time values
# from using Time.parse to using DateTime.parse.to_time.  This
# fixes issues when the times being parsed have no timezone
# information, the implicit timezone for the Database instance
# is set to +:utc+, and the timestamps being used include values
# not valid in the local timezone, such as during a daylight
# savings time switch.  
#
# To load the extension:
#
#   Sequel.extension :datetime_parse_to_time

#
module Sequel::DateTimeParseToTime
  private

  # Use DateTime.parse.to_time to do the conversion if the input a string and is assumed to
  # be in UTC and there is no offset information in the string.
  def convert_input_timestamp(v, input_timezone)
    if v.is_a?(String) && datetime_class == Time && input_timezone == :utc && !Date._parse(v).has_key?(:offset)
      t = DateTime.parse(v).to_time
      case application_timezone
      when nil, :local
        t = t.localtime
      end
      t
    else
      super
    end
  rescue => e
    raise convert_exception_class(e, Sequel::InvalidValue)
  end
end

Sequel.extend(Sequel::DateTimeParseToTime)

Version data entries

79 entries across 63 versions & 2 rubygems

Version Path
sequel-5.51.0 lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/sequel-5.50.0/lib/sequel/extensions/datetime_parse_to_time.rb
sequel-5.50.0 lib/sequel/extensions/datetime_parse_to_time.rb
sequel-5.49.0 lib/sequel/extensions/datetime_parse_to_time.rb
sequel-5.48.0 lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/sequel-5.47.0/lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/datetime_parse_to_time.rb
sequel-5.47.0 lib/sequel/extensions/datetime_parse_to_time.rb
sequel-5.46.0 lib/sequel/extensions/datetime_parse_to_time.rb
sequel-5.45.0 lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.39.0/lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.43.0/lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/extensions/datetime_parse_to_time.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/sequel-5.44.0/lib/sequel/extensions/datetime_parse_to_time.rb
sequel-5.44.0 lib/sequel/extensions/datetime_parse_to_time.rb
sequel-5.43.0 lib/sequel/extensions/datetime_parse_to_time.rb