Skip to content

Instantly share code, notes, and snippets.

@mikz
Created September 10, 2010 17:14
Show Gist options
  • Save mikz/574015 to your computer and use it in GitHub Desktop.
Save mikz/574015 to your computer and use it in GitHub Desktop.
def quoted_date(value)
if value.acts_like?(:time) && value.respond_to?(:usec)
begin
"#{value.getutc.to_s(:db)}.#{sprintf("%06d", value.usec)} #{value.formatted_offset}"
rescue
"#{super}.#{sprintf("%06d", value.usec)}"
end
else
super
end
end
@sunaku
Copy link

sunaku commented Sep 10, 2010

I don't like the rescue clause here (exceptions are not meant to replace if-statements) and the sprintf() call can be DRYed up. See my original patch for an example of these things:

http://s3.amazonaws.com/activereload-lighthouse/assets/d66895a49d1f4088200b8bc17b8127f1504be139/0001-postgresql_adapter-Include-time-zone-in-result-of-q.patch?AWSAccessKeyId=1AJ9W2TX1B2Z7C2KYB82&Expires=1284141301&Signature=K4F%2BRrtjwwE3Dyxo9PFRvZfVICg%3D

@mikz
Copy link
Author

mikz commented Sep 15, 2010

AccessKey expired

@sunaku
Copy link

sunaku commented Sep 15, 2010

I don't understand. AccessKey for what? The link to the original patch I posted?

By the way, here is my final revision to your (this) gist: http://gist.github.com/574080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment