Reputation: 4027
I inherited a web app app that uses this setting for serializing date/time values.
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Unspecified;
All the users of the app are in the PST timezone.
Firefox & Chrome parse "yyyy-mm-ddThh:mi:ss" values as local dates (local to the browser). However, Safari parses "2019-08-16T00:00:00"
(i.e. new Date("2019-08-16T00:00:00")
as "Thu Aug 15 2019 17:00:00 GMT-0700 (PDT)"
while the other two browsers parse the date as "Fri Aug 16 2019 00:00:00 GMT-0700 (Pacific Daylight Time)"
. In other words Safari thinks the date is in Zulu timezone (UTC), the other browsers interpret the date as being in the local timezone.
The application uses ExtJs 6.6 and due to this issue a value that was saved in the database as 2019-08-16T00:00:00 gets rendered in Safari as 2019-08-15 (in a grid or in date field on a form).
I also created a sencha fiddle to reproduce this issue here. When you run the fiddle in safari, the Some Date field will contain 15-Aug-2019, while in Chrome and FF it contains 16-Aug-2019.
I know that the correct value according to the specification should be added the time zone (see this as well). As an example this value works in all browsers: "2019-08-16T00:00:00-07:00"
.
Using DateTimeZoneHandling.Local might have been a better option in the app, however, changing this value now will probably require a huge test effort. There was/is also no mandate to support MacOs & Safari users. However, I personally find this issue annoying and I want to explore options to address it.
What other options are there to fix this for Safari? Is there a script that patches the behaviour of the JavaScript Date in Safari to behave the same as in FireFox/Chrome? Another option would be to change the parsing of these values in ExtJs but I don't know exactly where this can be done. I could use the new Date(year, month, day-of-month, hour, minutes, seconds)
which creates a local date in Safari as well.
Other ideas?
Thanks
Upvotes: 0
Views: 100
Reputation: 4027
I ended up applying this patch:
if (Ext.browser.is.Safari) {
Ext.data.field.Date.override({
dateReadFormat: 'Y-m-dTH:i:s'
});
}
The method used by ExtJs to parse the json value uses this date/time format and the resulting date uses the local timezone.
Upvotes: 1