Class: Infostrada::Formatter
- Inherits:
-
Object
- Object
- Infostrada::Formatter
- Defined in:
- lib/infostrada/formatter.rb
Overview
This class is used to format types that come from Infostrada like dates.
Class Method Summary collapse
-
.format_date(date) ⇒ Object
Formats the strange date format from Infostrada.
Class Method Details
.format_date(date) ⇒ Object
Formats the strange date format from Infostrada.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/infostrada/formatter.rb', line 5 def self.format_date(date) if date && match = date.match(/\/Date\(([0-9]+)([\+\-])([0-9]+)\)\//i) # The date was in miliseconds since Unix epoch stamp = match[1].to_i / 1000 offset = match[3].scan(/.{2}/) offset = offset[0].to_i * 3600 + offset[1].to_i final = stamp.send(match[2], offset) Time.at(final).utc else Time.now.utc end end |