As part of an information portal I worked on recently, users needed the ability to enter a start and end date and retrieve a list of news articles with article dates within that range. Seems simple, right? It was… almost.
Users from a timezone other than the one where the content was created try to query for data. For instance, if a user from Adelaide (UTC+9:30) searched for the article above, they would end up with 2017-12-14T23:30:00. If I was searching for a date range of 15/12/2017 to 22/12/2017, the article wouldn’t come up!
In SharePoint’s _spPageContextInfo object, the ‘webTimeZoneData’ property has an Id object to let us know which timezone is being used for the current site. Using this, and cross-referencing this list of SharePoint timezone ID to IANA time zone names, we could retrieve the right name to pass to Moment Timezone.