1 import { getDtendPropertyFromDuration, getSupportedDtstamp } from '../../../lib/calendar/icsSurgery/vevent';
3 describe('getSupportedDtstamp()', () => {
4 it('leaves untouched a proper DTSTAMP', () => {
8 value: { year: 2020, month: 1, day: 31, hours: 15, minutes: 11, seconds: 11, isUTC: true },
12 ).toEqual({ value: { year: 2020, month: 1, day: 31, hours: 15, minutes: 11, seconds: 11, isUTC: true } });
15 it('leaves untouched a DTSTAMP with Zulu marker and time zone', () => {
19 value: { year: 2020, month: 1, day: 31, hours: 15, minutes: 11, seconds: 11, isUTC: true },
20 parameters: { tzid: 'Asia/Seoul' },
24 ).toEqual({ value: { year: 2020, month: 1, day: 31, hours: 15, minutes: 11, seconds: 11, isUTC: true } });
27 it('converts a time-zoned DTSTAMP', () => {
31 value: { year: 2020, month: 1, day: 31, hours: 15, minutes: 11, seconds: 11, isUTC: false },
32 parameters: { tzid: 'America/Montevideo' },
36 ).toEqual({ value: { year: 2020, month: 1, day: 31, hours: 18, minutes: 11, seconds: 11, isUTC: true } });
39 it('converts a time-zoned DTSTAMP with a TZID that needs conversion', () => {
43 value: { year: 2020, month: 1, day: 31, hours: 15, minutes: 11, seconds: 11, isUTC: false },
44 parameters: { tzid: '/mozilla.org/20050126_1/Asia/Pyongyang' },
48 ).toEqual({ value: { year: 2020, month: 1, day: 31, hours: 6, minutes: 11, seconds: 11, isUTC: true } });
51 it('converts a floating DTSTAMP', () => {
55 value: { year: 2020, month: 1, day: 31, hours: 15, minutes: 11, seconds: 11, isUTC: false },
59 ).toEqual({ value: { year: 2020, month: 1, day: 31, hours: 15, minutes: 11, seconds: 11, isUTC: true } });
62 it('converts an all-day DTSTAMP', () => {
66 value: { year: 2020, month: 1, day: 31 },
67 parameters: { type: 'date' },
71 ).toEqual({ value: { year: 2020, month: 1, day: 31, hours: 0, minutes: 0, seconds: 0, isUTC: true } });
74 it('converts an all-day DTSTAMP with TZID', () => {
78 value: { year: 2020, month: 1, day: 31 },
79 parameters: { type: 'date', tzid: 'America/Montevideo' },
83 ).toEqual({ value: { year: 2020, month: 1, day: 31, hours: 3, minutes: 0, seconds: 0, isUTC: true } });
86 it('defaults to the given timestamp if a time zone is present but not supported', () => {
90 value: { year: 2020, month: 1, day: 31 },
91 parameters: { type: 'date', tzid: 'Europe/My_home' },
95 ).toEqual({ value: { year: 2022, month: 10, day: 17, hours: 14, minutes: 40, seconds: 19, isUTC: true } });
99 describe('getDtendPropertyFromDuration()', () => {
100 it('returns the appropriate dtend when given a duration and start', () => {
103 getDtendPropertyFromDuration(
104 { value: { year: 2020, month: 1, day: 31, hours: 0, minutes: 0, seconds: 0, isUTC: true } },
114 ).toEqual({ value: { year: 2020, month: 2, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true } });
116 // Localized part day
118 getDtendPropertyFromDuration(
120 parameters: { tzid: 'Europe/Zurich' },
121 value: { year: 2020, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: false },
133 parameters: { tzid: 'Europe/Zurich' },
134 value: { year: 2020, month: 1, day: 2, hours: 1, minutes: 0, seconds: 0, isUTC: false },
137 // All day with 1 day duration
139 getDtendPropertyFromDuration(
141 parameters: { type: 'date' },
142 value: { year: 2020, month: 1, day: 1 },
155 // All day badly formatted with 1 second duration
157 getDtendPropertyFromDuration(
159 parameters: { type: 'date' },
160 value: { year: 2020, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
173 // All day badly formatted with slightly over 1 day duration
175 getDtendPropertyFromDuration(
177 parameters: { type: 'date' },
178 value: { year: 2020, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
190 parameters: { type: 'date' },
191 value: { year: 2020, month: 1, day: 3 },
194 // UTC Part day with complex dueration
196 getDtendPropertyFromDuration(
198 value: { year: 2020, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
210 value: { year: 2020, month: 1, day: 18, hours: 4, minutes: 5, seconds: 6, isUTC: true },
213 // All day badly formatted complex duration
215 getDtendPropertyFromDuration(
217 parameters: { type: 'date' },
218 value: { year: 2020, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
230 parameters: { type: 'date' },
231 value: { year: 2020, month: 2, day: 7 },
234 // All day negative duration
236 getDtendPropertyFromDuration(
238 parameters: { type: 'date' },
239 value: { year: 2020, month: 1, day: 1 },