Module: Safrano::CoreIncl::Time::Format

Defined in:
lib/core_ext/Time/format.rb

Instance Method Summary collapse

Instance Method Details

#to_edm_jsonObject

Formatting: look at services.odata.org/V2/Northwind/Northwind.svc/Employees?$format=json the json raw data is like this : “HireDate”: “/Date(704678400000)/” –> //



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/core_ext/Time/format.rb', line 59

def to_edm_json
  if utc? || gmt_offset.zero?
    # no offset
    # %s : seconds since unix epoch
    # %L : milliseconds 000-999
    # --> %S%L milliseconds since epoch
    strftime('/Date(%s%L)/')
  else
    # same as above with GMT offset in minutes

    min_off_s = (min_off = gmt_offset / 60).positive? ? "+#{min_off}" : min_off.to_s
    "/Date(#{strftime('%s%L')}#{min_off_s})/"
  end
end