Skip to content

Commit 5f3d13d

Browse files
committed
[FIX] hr_holidays: don't assume default date strings are datetimes
Versions -------- - saas-16.3+ Steps ----- 1. Set timezone of User and browser to America/Los_Angeles; 2. go to Time Off; 3. click on calendar to create a new leave. Issue ----- Date defaults to the day before the selected date. Cause ----- Commit 0a0c691 added a TZ conversion in JS to add default start & end times for leaves. The issue is that it assumes the context values are always datetime strings, therefore always using `deserializeDateTime`, which does a timezone conversion from UTC to local time, which is incorrect when the context values are date strings. For a UTC-7 zone like America/Los_Angeles, it deserializes a date string like '2024-01-01' to '2023-12-12 17:00:00' (7 hours before midnight). It then sets the start hour to 7, and serializes it back to UTC, adding 7 hours, resulting in '2023-12-12 14:00:00'. Instead, Jan 1, 7 AM in America/Los_Angeles should convert to '2024-01-01 14:00:00' UTC. Solution -------- Use `deserializeDate` instead of `deserializeDateTime` when the `default_date_{from,to}` in the context is a date rather than a datetime. This way, '2024-01-01' gets deserialized into '2024-01-01 00:00:00' local time. When this value gets used for the default hours, '2024-01-01 07:00:00' local time will get serialized to '2024-01-01 14:00:00' UTC as expected. opw-3757712 closes odoo#162270 X-original-commit: 1344551 Signed-off-by: Levi Siuzdak <[email protected]>
1 parent 261f428 commit 5f3d13d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

addons/hr_holidays/static/src/views/calendar/calendar_model.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
/** @odoo-module */
22

33
import { CalendarModel } from '@web/views/calendar/calendar_model';
4-
import { deserializeDateTime, serializeDate, serializeDateTime } from "@web/core/l10n/dates";
4+
import {
5+
deserializeDate,
6+
deserializeDateTime,
7+
serializeDate,
8+
serializeDateTime,
9+
} from "@web/core/l10n/dates";
510

611
export class TimeOffCalendarModel extends CalendarModel {
712
setup(params, services) {
@@ -31,14 +36,18 @@ export class TimeOffCalendarModel extends CalendarModel {
3136
context["default_employee_id"] = this.employeeId;
3237
}
3338

39+
function deserialize(str) {
40+
// "YYYY-MM-DD".length == 10
41+
return str.length > 10 ? deserializeDateTime(str) : deserializeDate(str);
42+
}
3443
if ("default_date_from" in context) {
3544
context["default_date_from"] = serializeDateTime(
36-
deserializeDateTime(context["default_date_from"]).set({ hours: 7 })
45+
deserialize(context["default_date_from"]).set({ hours: 7 })
3746
);
3847
}
3948
if ("default_date_to" in context) {
4049
context["default_date_to"] = serializeDateTime(
41-
deserializeDateTime(context["default_date_to"]).set({ hours: 19 })
50+
deserialize(context["default_date_to"]).set({ hours: 19 })
4251
);
4352
}
4453
return context;

0 commit comments

Comments
 (0)