1

I'm working with an API that returns time values in the following format:

2013:02:27T06:39:25

Note the lack of any identifier for timezone.

From the API Docs:

https://partner-api.groupon.com/ledger

"Transaction timestamp of the ledger entry in the affiliate's time-zone.. The format is YYYY-MM-DDThh:mm:ss.. Example 2013:02:27T06:39:25"

Apparently the API response time zone is EST (the affiliate's time-zone). What is the best way to derive a UTC timezone value from this for storage in a MongoDB database.

verybadalloc
  • 5,768
  • 2
  • 33
  • 49
Casey Flynn
  • 13,654
  • 23
  • 103
  • 194
  • Check this answer [How do you create a JavaScript Date object with a set timezone without using a string representation](http://stackoverflow.com/questions/439630/how-do-you-create-a-javascript-date-object-with-a-set-timezone-without-using-a-s). There is example of `parseISO8601String()` function. – Anto Jurković Dec 03 '13 at 22:16

1 Answers1

2

The format is YYYY-MM-DDThh:mm:ss.. Example 2013:02:27T06:39:25"

It looks like there is a mistake in this documentation example as it doesn't match the suggested format (2013:02:27T06:39:25 should be 2013-02-27T06:39:25).

The sample response later on that page does match the expected format:

"orderDate": "2012-11-21T04:57:03"

I would suggest using moment-timezone -- it has a moment.tz() constructor which will parse the date string and set the expected time zone:

> var moment = require('moment-timezone');
> var orderDate = moment.tz("2012-11-21T04:57:03", "America/New_York")

> orderDate.toString()
'Wed Nov 21 2012 04:57:03 GMT-0500'

> orderDate.toISOString()
'2012-11-20T17:57:03.000Z'
Stennie
  • 63,885
  • 14
  • 149
  • 175