Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

Convert DateTime to Time before quoting #68

Open
wants to merge 1 commit into
base: 3-0-github
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def quoted_false
end

def quoted_date(value)
if value.is_a?(DateTime)
# hackily convert this DateTime to a Time so we can properly call
# `getlocal` on it to convert it to localtime.
#
# DateTime has a getutc method, but not a getlocal method, so the
# code below will just not even convert it before calling `to_s(:db)`
# unless we intervene.
#
value = Time.parse(value.to_s)
end

if value.acts_like?(:time)
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
Expand Down