Method: XeroRuby::PayrollUk::LeaveTypes#parse_date

Defined in:
lib/xero-ruby/models/payroll_uk/leave_types.rb

#parse_date(datestring) ⇒ Object



231
232
233
234
235
236
237
238
239
240
# File 'lib/xero-ruby/models/payroll_uk/leave_types.rb', line 231

def parse_date(datestring)
  if datestring.include?('Date')
    date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
    original, date, timezone = *date_pattern.match(datestring)
    date = (date.to_i / 1000)
    Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
  else # handle date 'types' for small subset of payroll API's
    Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
  end
end