2

I've observed that if you create an activity with a timestamp like this:

2010-09-17T14:27:37.860Z

It will be stored like this:

2010-09-17T14:27:37.860

Note the missing time zone code. From what I can tell, this violates the ISO standard, and it definitely produces complications in JavaScript with the Date object. I have always had to map the timestamp back to the correct timestamp by adding a Z character, which is kind of crazy.

Here's some code that hopefully illustrates why this is a problem:

const now = new Date('2010-09-17T14:27:37.860Z');
const notNow = new Date('2010-09-17T14:27:37.860');
console.log(now);
// Fri Sep 17 2010 09:27:37 GMT-0500 (Central Daylight Time)
console.log(notNow);
// Fri Sep 17 2010 14:27:37 GMT-0500 (Central Daylight Time)

What's going on here? Am I misunderstanding something or is this a bug with Stream?

Eric
  • 999
  • 2
  • 8
  • 23

1 Answers1

1

You are right; the activity.time field is returned without offset information even though they are localized as UTC.

This is something that was introduced early on and that was not possible to fix without breaking a number of existing API clients that rely on this time format.

Stream's API stores activity.time as UTC (the offset specified in the user input will be respected). If you use moment.js you can parse the time string correctly like this

moment.tz("2010-09-17T14:27:37.860", "UTC")
Tommaso Barbugli
  • 11,781
  • 2
  • 42
  • 41
  • Thanks for the answer. How do you recommend working around this in a JavaScript ecosystem? Should times be massaged before sending them to Stream? Or should the timestamps from Stream be corrected? – Eric Oct 10 '19 at 17:55
  • The API will respect activity.time timezone information and will store that as UTC (offset will be applied ofc). – Tommaso Barbugli Oct 11 '19 at 11:47
  • Thanks. I don't use moment but I'll see what I can figure out. Appreciate the reply! – Eric Oct 12 '19 at 13:30
  • 2
    May I suggest documenting this more explicitly? – Eric Oct 12 '19 at 13:30
  • For others who stumble upon this, the following question is related: https://stackoverflow.com/questions/39531436/timezone-bug-when-retrieving-time-field – tobias Jan 26 '21 at 07:21