|
| 1 | +/** |
| 2 | + * @timezone Europe/Belgrade |
| 3 | + */ |
| 4 | + |
| 5 | +import { |
| 6 | + describe, expect, it, |
| 7 | +} from '@jest/globals'; |
| 8 | + |
| 9 | +import { createScheduler } from './__mock__/create_scheduler'; |
| 10 | +import { setupSchedulerTestEnvironment } from './__mock__/m_mock_scheduler'; |
| 11 | +import type { AppointmentModel } from './__mock__/model/appointment'; |
| 12 | + |
| 13 | +const ChicagoDST = [new Date('2025-03-08T00:00:00.000Z'), new Date('2025-11-01T00:00:00.000Z')]; // +1, -1 |
| 14 | +const SydneyDST = [new Date('2025-04-07T00:00:00.000Z'), new Date('2025-10-04T00:00:00.000Z')]; // -1, +1 |
| 15 | +const BelgradeDST = [new Date('2025-03-29T00:00:00.000Z'), new Date('2025-10-25T00:00:00.000Z')]; // +1, -1 |
| 16 | +const dailyAppointment = { |
| 17 | + startDate: new Date('2025-01-07T13:00:00.000Z'), |
| 18 | + endDate: new Date('2025-01-07T14:00:00.000Z'), |
| 19 | + startDateTimeZone: 'America/Chicago', |
| 20 | + endDateTimeZone: 'America/Chicago', |
| 21 | + recurrenceRule: 'FREQ=DAILY', |
| 22 | +}; |
| 23 | +const views = [{ type: 'week', intervalCount: 2 }]; |
| 24 | + |
| 25 | +const getDisplayDates = (appointments: AppointmentModel[]): string[] => appointments |
| 26 | + .map((appointment) => appointment.getDisplayDate()); |
| 27 | +const reduceDates = (texts: string[]): string[] => texts |
| 28 | + .reduce<string[]>((result, time) => { |
| 29 | + if (result.at(-1) !== time) { |
| 30 | + result.push(time); |
| 31 | + } |
| 32 | + |
| 33 | + return result; |
| 34 | + }, []); |
| 35 | + |
| 36 | +/* |
| 37 | + * NOTE: |
| 38 | + * display date = source date - source time zone offset + target time zone offset |
| 39 | + * |
| 40 | + * Chicago: UTC-6h, UTC-5h, UTC-6h |
| 41 | + * Sydney: UTC+11h, UTC+10h, UTC+11h |
| 42 | + * Belgrade: UTC+1h, UTC+2h, UTC+1h |
| 43 | + * |
| 44 | + * Chicago to Chicago: should keep the same display date |
| 45 | + * Chicago to Sydney: +17h, +16h, +15h, +16h, +17h |
| 46 | + * Chicago to Belgrade: +7h, +6h, +7h, +6h, +7h |
| 47 | + */ |
| 48 | +describe('Recurrence appointments', () => { |
| 49 | + it('should change dates according to DST in target (Chicago) and appointment timezones (T1305659)', async () => { |
| 50 | + setupSchedulerTestEnvironment(); |
| 51 | + const { POM, scheduler } = await createScheduler({ |
| 52 | + timeZone: 'America/Chicago', |
| 53 | + dataSource: [dailyAppointment], |
| 54 | + views, |
| 55 | + currentView: 'week', |
| 56 | + currentDate: ChicagoDST[0], |
| 57 | + firstDayOfWeek: 3, |
| 58 | + }); |
| 59 | + |
| 60 | + const getDates = () => getDisplayDates(POM.getAppointments()); |
| 61 | + |
| 62 | + const dates = getDates(); |
| 63 | + scheduler.option('currentDate', ChicagoDST[1]); |
| 64 | + dates.push(...getDates()); |
| 65 | + |
| 66 | + expect(reduceDates(dates)).toEqual([ |
| 67 | + '7:00 AM - 8:00 AM', |
| 68 | + ]); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should change dates according to DST in target (Sydney) and appointment timezones (T1305659)', async () => { |
| 72 | + setupSchedulerTestEnvironment(); |
| 73 | + const { POM, scheduler } = await createScheduler({ |
| 74 | + timeZone: 'Australia/Sydney', |
| 75 | + dataSource: [dailyAppointment], |
| 76 | + views, |
| 77 | + currentView: 'week', |
| 78 | + currentDate: ChicagoDST[0], |
| 79 | + firstDayOfWeek: 3, |
| 80 | + }); |
| 81 | + |
| 82 | + const getDates = () => getDisplayDates(POM.getAppointments()); |
| 83 | + |
| 84 | + const dates = getDates(); |
| 85 | + scheduler.option('currentDate', SydneyDST[0]); |
| 86 | + dates.push(...getDates()); |
| 87 | + scheduler.option('currentDate', SydneyDST[1]); |
| 88 | + dates.push(...getDates()); |
| 89 | + scheduler.option('currentDate', ChicagoDST[1]); |
| 90 | + dates.push(...getDates()); |
| 91 | + |
| 92 | + expect(reduceDates(dates)).toEqual([ |
| 93 | + '12:00 AM - 1:00 AM', |
| 94 | + '11:00 PM - 12:00 AM', |
| 95 | + '10:00 PM - 11:00 PM', |
| 96 | + '11:00 PM - 12:00 AM', |
| 97 | + '12:00 AM - 1:00 AM', |
| 98 | + ]); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should change dates according to DST in target (Belgrade) and appointment timezones (T1305659)', async () => { |
| 102 | + setupSchedulerTestEnvironment(); |
| 103 | + const { POM, scheduler } = await createScheduler({ |
| 104 | + timeZone: 'Europe/Belgrade', |
| 105 | + dataSource: [dailyAppointment], |
| 106 | + views, |
| 107 | + currentView: 'week', |
| 108 | + currentDate: ChicagoDST[0], |
| 109 | + firstDayOfWeek: 3, |
| 110 | + }); |
| 111 | + |
| 112 | + const getDates = () => getDisplayDates(POM.getAppointments()); |
| 113 | + |
| 114 | + const dates = getDates(); |
| 115 | + scheduler.option('currentDate', BelgradeDST[0]); |
| 116 | + dates.push(...getDates()); |
| 117 | + scheduler.option('currentDate', BelgradeDST[1]); |
| 118 | + dates.push(...getDates()); |
| 119 | + scheduler.option('currentDate', ChicagoDST[1]); |
| 120 | + dates.push(...getDates()); |
| 121 | + |
| 122 | + expect(reduceDates(dates)).toEqual([ |
| 123 | + '2:00 PM - 3:00 PM', |
| 124 | + '1:00 PM - 2:00 PM', |
| 125 | + '2:00 PM - 3:00 PM', |
| 126 | + '1:00 PM - 2:00 PM', |
| 127 | + '2:00 PM - 3:00 PM', |
| 128 | + ]); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should change dates according to DST in target (Local Belgrade) and appointment timezones (T1305659)', async () => { |
| 132 | + setupSchedulerTestEnvironment(); |
| 133 | + const { POM, scheduler } = await createScheduler({ |
| 134 | + dataSource: [dailyAppointment], |
| 135 | + views, |
| 136 | + currentView: 'week', |
| 137 | + currentDate: ChicagoDST[0], |
| 138 | + firstDayOfWeek: 3, |
| 139 | + }); |
| 140 | + |
| 141 | + const getDates = () => getDisplayDates(POM.getAppointments()); |
| 142 | + |
| 143 | + const dates = getDates(); |
| 144 | + scheduler.option('currentDate', BelgradeDST[0]); |
| 145 | + dates.push(...getDates()); |
| 146 | + scheduler.option('currentDate', BelgradeDST[1]); |
| 147 | + dates.push(...getDates()); |
| 148 | + scheduler.option('currentDate', ChicagoDST[1]); |
| 149 | + dates.push(...getDates()); |
| 150 | + |
| 151 | + expect(reduceDates(dates)).toEqual([ |
| 152 | + '2:00 PM - 3:00 PM', |
| 153 | + '1:00 PM - 2:00 PM', |
| 154 | + '2:00 PM - 3:00 PM', |
| 155 | + '1:00 PM - 2:00 PM', |
| 156 | + '2:00 PM - 3:00 PM', |
| 157 | + ]); |
| 158 | + }); |
| 159 | +}); |
0 commit comments