11ty / eleventy-plugin-rss

A pack of Eleventy plugins for generating an RSS feed.
https://www.11ty.dev/docs/plugins/rss/
MIT License
92 stars 22 forks source link

Force dates to UTC? #9

Closed robdodson closed 3 years ago

robdodson commented 5 years ago

I should preface this by saying I'm terrible with dates and timezones so if I'm totally incorrect please feel free to close :)

I was testing out the plugin and noticed that the rssDate filter generates an ISO date that includes the local machine's offset. I think this means that if I publish the feed in SF one day, and then my teammate in New York publishes the feed the next day, we'd end up overwriting each others dates.

While this will technically refer to the same point in time, it also means we'd constantly be generating diffs in the RSS.

<updated>2019-04-22T17:00:00-07:00</updated> # America/Los_Angeles
<updated>2019-04-22T20:00:00-04:00</updated> # America/New_York

In our case, we check the built feed.xml into our version control, so we'd always have this big diff depending on whoever published it.

I'm not sure if this would mess things up, but would it make sense to force the dates to UTC time?

// dateToISO.js

module.exports = function(dateObj) {
  // return DateTime.fromJSDate(dateObj).toISO({ includeOffset: true, suppressMilliseconds: true });
  return DateTime.fromISO(dateObj.toISOString(), { zone: 'utc' }).toISO();
}

// 2019-04-23 => 2019-04-23T00:00:00.000Z
datashaman commented 4 years ago

Using dateObj.toISOString() produces UTC time as per the spec. Avoid all this code and use the native method.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString