Created
September 4, 2015 01:16
-
-
Save aquach/8781c7fda5e1b3ce4932 to your computer and use it in GitHub Desktop.
Automatic Unix timestamp conversion for Hirb tables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AutoTimestamp | |
def query_callback(rows, options) | |
rows.each do |r| | |
r.each do |k, v| | |
if v.is_a?(Integer) | |
dates = [ Time.at(v), Time.at(v / 1000) ] | |
plausible_date = dates.find { |d| | |
d >= Time.now - 10.years && d <= Time.now + 10.years | |
} | |
if plausible_date | |
r[k] = "#{plausible_date.localtime('-07:00').to_s} (#{v})" | |
end | |
end | |
end | |
end | |
end | |
end | |
Hirb::Helpers::Table.send :include, AutoTimestamp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment