Skip to content

Instantly share code, notes, and snippets.

@dylanmei
Created January 26, 2012 18:33
Show Gist options
  • Save dylanmei/1684240 to your computer and use it in GitHub Desktop.
Save dylanmei/1684240 to your computer and use it in GitHub Desktop.
Microsoft JSON date retardify & unretardify
class Time
def to_json(*)
"\/Date(#{self.strftime("%s000%z")})\/"
end
def self.from_json(jsonDate)
/Date\((?<msecs>\d+)(?<offset>-?\d+)\)/ =~ jsonDate
return nil if msecs.nil?
Time.at(msecs.to_i / 1000)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment