Method: XeroRuby::PayrollAu::APIException#parse_date

Defined in:
lib/xero-ruby/models/payroll_au/api_exception.rb

#parse_date(datestring) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/xero-ruby/models/payroll_au/api_exception.rb', line 230

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
  elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
    Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').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