Skip to content

Commit

Permalink
Optimization for very specific use case of all UTC times in database …
Browse files Browse the repository at this point in the history
…and app
  • Loading branch information
Andy Goodell committed Nov 17, 2011
1 parent 1c8dd00 commit 3bb7a73
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/sequel/database/misc.rb
Expand Up @@ -169,7 +169,11 @@ def timezone
# from the databases's timezone or the default database timezone if # from the databases's timezone or the default database timezone if
# the database does not have a timezone. # the database does not have a timezone.
def to_application_timestamp(v) def to_application_timestamp(v)
Sequel.convert_timestamp(v, timezone) if v.is_a? String && v.length >= 19
Time.utc(v[0,4], v[5,7], v[8,10], v[11,13], v[14,16], v[17,19])
else
Sequel.convert_timestamp(v, timezone)
end
end end


# Typecast the value to the given column_type. Calls # Typecast the value to the given column_type. Calls
Expand Down

1 comment on commit 3bb7a73

@jeremyevans
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are assuming a very specific format here (probably valid in your own application, but not valid in general). Instead of monkey patching, I would recommend extending the Sequel::Database object with a module that did the same check, but called super if v was not a String or the length was less than 19.

Please sign in to comment.