Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / time.ts
blob739230337ceba1bb58c833d8957ff274d88cf74e
1 import { convertZonedDateTimeToUTC, toUTCDate } from '@proton/shared/lib/date/timezone';
2 import type { DateTimeModel } from '@proton/shared/lib/interfaces/calendar';
4 export const getDateTimeState = (utcDate: Date, tzid: string): DateTimeModel => {
5     return {
6         // These should be local dates since the mini calendar and time input uses that.
7         date: new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate(), 0, 0),
8         // Assuming there is no timezone that has a DST shift at this date
9         time: new Date(2000, 0, 1, utcDate.getUTCHours(), utcDate.getUTCMinutes()),
10         tzid,
11     };
14 export const getDateTime = ({ date, time }: DateTimeModel) => {
15     return new Date(date.getFullYear(), date.getMonth(), date.getDate(), time.getHours(), time.getMinutes());
18 export const getTimeInUtc = ({ date, time, tzid }: DateTimeModel, isAllDay: boolean) => {
19     if (isAllDay) {
20         return toUTCDate({
21             year: date.getFullYear(),
22             month: date.getMonth() + 1,
23             day: date.getDate(),
24         });
25     }
26     return toUTCDate(
27         convertZonedDateTimeToUTC(
28             {
29                 year: date.getFullYear(),
30                 month: date.getMonth() + 1,
31                 day: date.getDate(),
32                 hours: time.getHours(),
33                 minutes: time.getMinutes(),
34                 seconds: 0,
35             },
36             tzid
37         )
38     );