Skip to content

Commit

Permalink
Assume local time if database timezone not specified when handling BC…
Browse files Browse the repository at this point in the history
… timestamps on JRuby 9.2.0.0 in the pg_extended_date_support extension

DateTime.parse assumes UTC, and therefore the resulting Time object
will be UTC without this.
  • Loading branch information
jeremyevans committed Jun 26, 2018
1 parent e36cfaf commit 5dd5d52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Assume local time if database timezone not specified when handling BC timestamps on JRuby 9.2.0.0 in the pg_extended_date_support extension (jeremyevans)

* Fix parsing of timetz types in the jdbc/postgresql adapter (jeremyevans)

* Make SQLTime.parse respect SQLTime.date and Sequel.application_timezone (jeremyevans)
Expand Down
15 changes: 11 additions & 4 deletions lib/sequel/extensions/pg_extended_date_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def convert_infinite_timestamps=(v)
# If convert_infinite_timestamps is true and the value is infinite, return an appropriate
# value based on the convert_infinite_timestamps setting.
def to_application_timestamp(value)
if value.is_a?(String) && (m = value.match(/(?:(?:[-+]\d\d:\d\d)(:\d\d)?)?( BC)?\z/)) && (m[1] || m[2])
if m[2]
if value.is_a?(String) && (m = value.match(/((?:[-+]\d\d:\d\d)(:\d\d)?)?( BC)?\z/)) && (m[2] || m[3])
if m[3]
value = value.sub(' BC', '').sub(' ', ' BC ')
conv = defined?(JRUBY_VERSION) && JRUBY_VERSION == '9.2.0.0'
end
if m[1] || conv
if m[2] || conv
dt = DateTime.parse(value)
if conv
# :nocov:
Expand All @@ -99,7 +99,14 @@ def to_application_timestamp(value)
end
# :nocov:
end
dt = dt.to_time unless Sequel.datetime_class == DateTime
unless Sequel.datetime_class == DateTime
dt = dt.to_time
if conv && (timezone == nil || timezone == :local) && !m[1]
# :nocov:
dt = Sequel.send(:convert_input_timestamp, dt.strftime("%F %T.%6N"), :local)
# :nocov:
end
end
Sequel.convert_output_timestamp(dt, Sequel.application_timezone)
else
super(value)
Expand Down

0 comments on commit 5dd5d52

Please sign in to comment.