Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / propertiesToDateTimeModel.ts
blob1aea004358d9adf5734138b4ad9fad126eb5c705
1 import { getPropertyTzid } from '@proton/shared/lib/calendar/vcalHelper';
2 import { addDays } from '@proton/shared/lib/date-fns-utc';
3 import { toUTCDate } from '@proton/shared/lib/date/timezone';
4 import type { VcalDateOrDateTimeProperty } from '@proton/shared/lib/interfaces/calendar/VcalModel';
6 import { getDateTimeState } from './time';
8 const propertiesToDateTimeModel = (
9     dtstart: VcalDateOrDateTimeProperty,
10     dtend: VcalDateOrDateTimeProperty,
11     isAllDay: boolean,
12     tzid: string
13 ) => {
14     const localStart = toUTCDate(dtstart.value);
15     const localEnd = toUTCDate(dtend.value);
17     if (isAllDay) {
18         // All day events date ranges are stored non-inclusively, so remove a full day from the end date
19         const modifiedEnd = addDays(localEnd, -1);
21         return {
22             start: getDateTimeState(localStart, tzid),
23             end: getDateTimeState(modifiedEnd, tzid),
24         };
25     }
27     const tzStart = getPropertyTzid(dtstart) || tzid;
28     const tzEnd = getPropertyTzid(dtend) || tzid;
30     return {
31         start: getDateTimeState(localStart, tzStart),
32         end: getDateTimeState(localEnd, tzEnd),
33     };
36 export default propertiesToDateTimeModel;