Browse files

Optimization for very specific use case of all UTC times in database …

…and app
  • Loading branch information...
1 parent 1c8dd00 commit 3bb7a7350a711b06424ec0a2b912c0399ca226e5 Andy Goodell committed Nov 17, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/sequel/database/misc.rb
6 lib/sequel/database/misc.rb
@@ -169,7 +169,11 @@ def timezone
# from the databases's timezone or the default database timezone if
# the database does not have a timezone.
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
# Typecast the value to the given column_type. Calls

1 comment on commit 3bb7a73


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.