Using date.UtcDateTime with goog.i18n.DateTimeFormat and timezones
So I am trying to store date-times as UTC on the server and then convert to a user specified timezone on the browser end. This should be independent of the browser timezone settings.
To do this I converted the date stored to a UtcDateTime and then passed it to goog.i18n.DateTimeFormat.format along with timezone data I generated from pytz as suggested in the closure documentation.
This never seemed to work correctly unless I passed no timezone at all. After some debugging I realised that the format method converted to a built-in javascript date type (if a timezone was passed) before creating the formatted string. When using UtcDateTime this breaks the process as it uses the normal date methods (getHours instead of getUTCHours etc) which have the browser timezone as well as the already applied settings from the opt_timezone parameter which gives an incorrect result.
I wrote a fix for this which can be seen here: https://github.com/BradMclain/closure-library/commit/dd06bf5771ea9c0de9e096a91d7626b48ce41029
Is this the correct approach or am I doing something wrong? Is my fix appropriate or does it need changes?
I'm seeing the same behaviour of current timezone being applied to the passed in timezone while formatting. Also storing locally in UTC.
This would be much easier to diagnose if you could provide a failing test case. Here's a fiddle template you can use to load Closure deps: https://jsfiddle.net/2mjc800g/