Module: Safrano::CoreExt::Date::Format
- Defined in:
- lib/core_ext/Date/format.rb
Constant Summary collapse
- REGEX =
Date is a DateTime with time 00:00:00 thus the milliseconds are ALWAYS 000 excepted when we get Date(0) = Epoch date
/\/Date\((?:(-?\d+)000|0+)\)\//.freeze
Instance Method Summary collapse
-
#from_edm_json(instr) ⇒ Object
Input: /Date(86400000)/ Match groups 1.
Instance Method Details
#from_edm_json(instr) ⇒ Object
Input: /Date(86400000)/ Match groups 1. 86400 Input: /Date(0)/ Match groups 1.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/core_ext/Date/format.rb', line 17 def from_edm_json(instr) return unless (md = instr.match(REGEX)) if md[1].nil? # no offset relative to Epoch ::Date.new(1970, 1, 1).freeze else # parse as seconds since epoch ::Date.strptime(md[1], '%s') end end |