Get predictive Time-zones in DateTime Properties
Episerver is by default relying on a dijit/form/_DateTimeTextBox widget when representing the Date and Time picker appearing when DateTime properties are used as part of any PageType or BlockType property. By default, this widget adjusts its Date selection to the users Time-zone (e.g. GMT-4) defined by the browser. It makes it hard to show the actual date and time selected to the end users.
We had two options.. We could adjust the timezone of our servers to match the timezone of the browser our editors were using. It was though, in this situation, not a solution due to the platform being globally used in a large international corporation.
Secondly, and the solution we ended up with, was to enforce the dijit/form/_DateTimeTextBox to select a Date and Time in UTC and thereby ignore the browser timezone.
It requires some minor code snippets, but can easily be added to any Episerver CMS and Episerver Commerce platform.
Below widget ensures that the date selected are being converted to UTC before handed over to Episerver and saved in our database.
Episerver has to be told when to use this widget. That can be done via a EditorDescriptor, that allows developers to mark any DateTime or DateTime? property with a UiHint called “UTC”.
Be aware that it is important that you register the path for any client side modules that are registered as widgets to “newsevents”.
<add name=”newsevents” path=”Static/NewsEvents/Dojo” />
Be aware that above snippets automatically converts dates and time to UTC. It means the widget expects that your environment runs Coordinated Universal Time. It would of course be possible to adjust above implementation slightly to utilize the EditorConfiguration, supported by Episerver, to indicate the timezone we want to convert to.