import { getDateProperty , getDateTimeProperty , getUntilProperty , propertyToUTCDate , } from 'proton-shared/lib/calendar/vcalConverter' ; import { getIsAllDay , getPropertyTzid } from 'proton-shared/lib/calendar/vcalHelper' ; import { toUTCDate } from 'proton-shared/lib/date/timezone' ; import { VcalDateOrDateTimeProperty , VcalDateProperty , VcalDateTimeProperty , VcalRruleProperty , VcalVeventComponent , } from 'proton-shared/lib/interfaces/calendar/VcalModel' ; import { DateTimeValue } from 'proton-shared/lib/interfaces/calendar' ; export const toExdate = ( dateObject , isAllDay , tzid = 'UTC' ) : VcalDateOrDateTimeProperty => { if ( isAllDay ) { return getDateProperty ( dateObject ) as VcalDateProperty ; } return getDateTimeProperty ( dateObject , tzid ) as VcalDateTimeProperty ; } ; export const getSafeRruleCount = ( rrule , newCount ) => { if ( newCount < 1 ) { return ; } return { ... rrule , value : { ... rrule . value , count : newCount , } , } ; } ; export const getSafeRruleUntil = ( rrule , component ) => { const { dtstart } = component ; if ( ! rrule . value . until ) { throw new Error ( 'Until required' ) ; } const originalUntilDateTime = toUTCDate ( rrule . value . until ) ; const newStartTime = propertyToUTCDate ( dtstart ) ; if ( newStartTime > originalUntilDateTime ) { const until = getUntilProperty ( dtstart . value , getIsAllDay ( component ) , getPropertyTzid ( dtstart ) ) ; return { ... rrule , value : { ... rrule . value , until , } , } ; } return rrule ; } ;