Class: Halo::Reach::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/halo-reach-util.rb

Class Method Summary collapse

Class Method Details

.parse_timestamp(timestamp = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/halo-reach-util.rb', line 4

def self.parse_timestamp(timestamp = nil)
  # Expected format: '/Date(1284497520000-0700)/'
  # The API returns the date as a UNIX timestamp in milliseconds
  # The "0700" represents the timezone, in this example the U.S. Pacific (GMT-7) timezone
  # (http://www.haloreachapi.net/wiki/Date_time_format)

  if timestamp && (timestamp =~ /^\/Date\((\d+)-(\d+)\)\/$/)
    return [Time.at($1.to_i / 1000).utc, $2]
  else
    raise ArgumentError.new('Invalid timestamp') 
  end
end