Method: Sequel::Postgres::ExtendedDateSupport#to_application_timestamp

Defined in:
lib/sequel/extensions/pg_extended_date_support.rb

#to_application_timestamp(value) ⇒ Object

Handle BC dates in timestamps by moving the BC from after the time to after the date, to appease ruby’s date parser. If convert_infinite_timestamps is true and the value is infinite, return an appropriate value based on the convert_infinite_timestamps setting.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/sequel/extensions/pg_extended_date_support.rb', line 107

def to_application_timestamp(value)
  if value.is_a?(String) && (m = /((?:[-+]\d\d:\d\d)(:\d\d)?)?( BC)?\z/.match(value)) && (m[2] || m[3])
    if m[3]
      value = value.sub(' BC', '').sub(' ', ' BC ')
    end
    if m[2]
      dt = if Sequel.datetime_class == DateTime
        DateTime.parse(value)
      elsif TIME_CAN_PARSE_BC
        Time.parse(value)
      # :nocov:
      else
        DateTime.parse(value).to_time
      # :nocov:
      end

      Sequel.convert_output_timestamp(dt, Sequel.application_timezone)
    else
      super(value)
    end
  elsif convert_infinite_timestamps
    case value
    when *INFINITE_TIMESTAMP_STRINGS
      infinite_timestamp_value(value)
    else
      super
    end
  else
    super
  end
end