[FIX] web: no safari issue with DST at midnight

On safari with apple device in belgium timezone, this code:

```
x = new Date(2020, 2, 28, 2)
x.setDate(29)
```

returns:

> Sat Mar 28 2020 02:00:00 GMT+0100 (CET)
> Sun Mar 29 2020 01:00:00 GMT+0100 (CET)

This is not consistent with any other combination of OS and browser
tested, where this code would return eg. for chrome on macOS:

> Sat Mar 28 2020 02:00:00 GMT+0100 (Central European Standard Time)
> Sun Mar 29 2020 03:00:00 GMT+0200 (Central European Summer Time)

In most instance, this is not an issue, but for country with midnight as
Daylight Saving Time (DST) change, this is an issue, because the Tempus
Dominus calendar widget will have a duplicated day which might eg. make
a month totally not usable.

This issue can eg. be reproduced in Lebanon timezone at this address:

https://tempusdominus.github.io/bootstrap-4/Usage/

Going to the month of April 2020, an error happen  because to get the
first day of the week of 1st April, we do:

```
this._viewDate.clone().startOf('M').startOf('w').startOf('d');
// .startOf('M') => Apr 01 00:00:00
// .startOf('w') => Mar 28 23:00:00 (safari bug)
// .startOf('d') => Mar 28 00:00:00
```

which gives us the wrong day (28 instead of 29) which causes an error.

Other report of the issue:

- https://www.donedone.com/timezone-specific-browser-specific-datetime-bug-2014/
- https://github.com/date-fns/date-fns : issue 571
- https://forum.mobiscroll.com/t/issue-with-invalid-dates-range-script/108

opw-2271482
closes #59786

closes odoo/odoo#59908

X-original-commit: 112267d62544c56acfdcef96727c32c314c15f16
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
Nicolas Lempereur
2020-10-13 16:16:45 +00:00
parent 066f4ec97c
commit f0ba2dbfa5
@@ -2092,9 +2092,11 @@ var TempusDominusBootstrap4 = function ($) {
daysViewHeader.eq(2).addClass('disabled');
}
currentDate = this._viewDate.clone().startOf('M').startOf('w').startOf('d');
// !! ODOO FIX START !!
var now = this.getMoment();
// currentDate = this._viewDate.clone().startOf('M').startOf('w').startOf('d');
// avoid issue of safari + DST at midnight
currentDate = this._viewDate.clone().startOf('M').startOf('w').add(12, 'hours');
// !! ODOO FIX END !!
for (i = 0; i < 42; i++) {