Skip to content

Instantly share code, notes, and snippets.

@godfat
Created August 24, 2015 11:33
Show Gist options
  • Save godfat/3dff9f88f46a58f56927 to your computer and use it in GitHub Desktop.
Save godfat/3dff9f88f46a58f56927 to your computer and use it in GitHub Desktop.
require 'sequel'
module FasterSequelTimeParser # from activerecord
module_function
def parse string
string =~ /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
microsec = ($7.to_r * 1_000_000).to_i
::Time.utc($1.to_i, $2.to_i, $3.to_i, $4.to_i,
$5.to_i, $6.to_i, microsec)
end
def now
::Time.now
end
end
Sequel.datetime_class = FasterSequelTimeParser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment