Module: ScoutAgent::CoreExtensions::TimeClass
- Defined in:
- lib/scout_agent/core_extensions.rb
Overview
Class extensions for Time.
Instance Method Summary collapse
-
#from_db_s(str) ⇒ Object
Converts a String (
str
) in the form"NNNN-NN-NN NN:NN"
or"NNNN-NN-NN NN:NN:NN"
into a proper Time object. -
#json_create(object) ⇒ Object
Half of the support for the round-tripping of Time objects to and from JSON.
Instance Method Details
#from_db_s(str) ⇒ Object
Converts a String (str
) in the form "NNNN-NN-NN NN:NN"
or "NNNN-NN-NN NN:NN:NN"
into a proper Time object.
278 279 280 281 282 |
# File 'lib/scout_agent/core_extensions.rb', line 278 def from_db_s(str) if str and str.to_s =~ /\A\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}(?::\d{2})?\z/ ::Time.local(*str.to_s.scan(/\d+/)) end end |
#json_create(object) ⇒ Object
Half of the support for the round-tripping of Time objects to and from JSON. This method reconstructs a Time object from a raw JSON object representation built by our to_json() override.
289 290 291 |
# File 'lib/scout_agent/core_extensions.rb', line 289 def json_create(object) ::Time.local(*object["data"]) end |