import { addDays , isSameDay } from 'proton-shared/lib/date-fns-utc' ; import { EventModel } from 'proton-shared/lib/interfaces/calendar' ; import { getInitialDateTimeModel } from './state' ; import { getTimeInUtc } from './time' ; const isZeroHoursMinutes = ( date ) => date . getHours ( ) === 0 && date . getMinutes ( ) === 0 ; export const getAllDayCheck = ( oldModel , isAllDay ) => { if ( ! isAllDay && oldModel . isAllDay ) { if ( isZeroHoursMinutes ( oldModel . start . time ) && isZeroHoursMinutes ( oldModel . end . time ) ) { const { start : { date : startDate , time : startTime } , end : { date : endDate , time : endTime } , } = getInitialDateTimeModel ( oldModel . initialDate , oldModel . defaultEventDuration , '' ) ; const newStartDate = oldModel . start . date ; const newEndDate = ! isSameDay ( startDate , endDate ) ? addDays ( oldModel . end . date , 1 ) : oldModel . end . date ; return { isAllDay , start : { tzid : oldModel . initialTzid , date : newStartDate , time : startTime } , end : { tzid : oldModel . initialTzid , date : newEndDate , time : endTime } , } ; } const startUtcDate = getTimeInUtc ( oldModel . start , isAllDay ) ; const endUtcDate = getTimeInUtc ( oldModel . end , isAllDay ) ; if ( + endUtcDate < + startUtcDate ) { return { isAllDay , end : { tzid : oldModel . initialTzid , date : oldModel . start . date , time : oldModel . start . time } , } ; } } return { isAllDay , } ; } ;