|
1 | 1 | import { h } from 'preact';
|
2 | 2 |
|
| 3 | +import moment from 'moment-timezone'; |
| 4 | + |
3 | 5 | import { mockWeekViewEvents } from '@stories/mocks/mockWeekViewEvents';
|
4 | 6 | import type { CalendarExampleStory } from '@stories/util/calendarExample';
|
5 | 7 | import { CalendarExample } from '@stories/util/calendarExample';
|
6 | 8 |
|
| 9 | +import type { EventObject } from '@t/events'; |
| 10 | + |
7 | 11 | export default { title: 'E2E/Week View' };
|
8 | 12 |
|
9 | 13 | const Template: CalendarExampleStory = (args) => <CalendarExample {...args} />;
|
@@ -170,6 +174,86 @@ DaylightSavingTimeTransitionSouthern.args = {
|
170 | 174 | },
|
171 | 175 | };
|
172 | 176 |
|
| 177 | +// NOTE: For manual testing purposes |
| 178 | +const timezoneNameForSystemTimezoneTest = 'US/Pacific'; |
| 179 | +// const timezoneNameForSystemTimezoneTest = 'Asia/Seoul'; |
| 180 | +export const SystemTimezoneTest = Template.bind({}); |
| 181 | +SystemTimezoneTest.args = { |
| 182 | + ...Template.args, |
| 183 | + options: { |
| 184 | + ...Template.args.options, |
| 185 | + useFormPopup: false, |
| 186 | + timezone: { |
| 187 | + zones: [ |
| 188 | + { |
| 189 | + timezoneName: timezoneNameForSystemTimezoneTest, |
| 190 | + }, |
| 191 | + ], |
| 192 | + }, |
| 193 | + }, |
| 194 | + onInit: (cal) => { |
| 195 | + const convert = (d: Date) => |
| 196 | + moment |
| 197 | + .tz( |
| 198 | + moment([ |
| 199 | + d.getFullYear(), |
| 200 | + d.getMonth(), |
| 201 | + d.getDate(), |
| 202 | + d.getHours(), |
| 203 | + d.getMinutes(), |
| 204 | + d.getSeconds(), |
| 205 | + ]).format('YYYY-MM-DD HH:mm:ss'), |
| 206 | + timezoneNameForSystemTimezoneTest |
| 207 | + ) |
| 208 | + .toISOString(); |
| 209 | + |
| 210 | + cal.setDate('2022-03-09T00:00:00Z'); |
| 211 | + |
| 212 | + cal.createEvents([ |
| 213 | + { |
| 214 | + id: 'pst', |
| 215 | + title: 'PST', |
| 216 | + start: '2022-03-09T09:00:00Z', // 01:00 UTC-08, 18:00 UTC+09 |
| 217 | + end: '2022-03-09T10:00:00Z', // 02:00 UTC-08, 19:00 UTC+09 |
| 218 | + }, |
| 219 | + { |
| 220 | + id: 'pdt', |
| 221 | + title: 'PDT', |
| 222 | + start: '2022-03-16T08:00:00Z', // 01:00 UTC-07, 17:00 UTC+09 |
| 223 | + end: '2022-03-16T09:00:00Z', // 02:00 UTC-07, 18:00 UTC+09 |
| 224 | + }, |
| 225 | + ]); |
| 226 | + |
| 227 | + cal.on('selectDateTime', (info) => { |
| 228 | + const startDate = info.start; |
| 229 | + const endDate = info.end; |
| 230 | + |
| 231 | + cal.createEvents([ |
| 232 | + { |
| 233 | + id: Date.now().toString(32).slice(0, 8), |
| 234 | + title: 'New Event', |
| 235 | + start: convert(startDate), |
| 236 | + end: convert(endDate), |
| 237 | + category: 'time', |
| 238 | + }, |
| 239 | + ]); |
| 240 | + |
| 241 | + cal.clearGridSelections(); |
| 242 | + }); |
| 243 | + |
| 244 | + cal.on('beforeUpdateEvent', ({ event, changes }) => { |
| 245 | + const zonedChanges = Object.keys(changes).reduce<EventObject>((acc, _k) => { |
| 246 | + const key = _k as keyof EventObject; |
| 247 | + acc[key] = convert(changes[key]); |
| 248 | + |
| 249 | + return acc; |
| 250 | + }, {}); |
| 251 | + |
| 252 | + cal.updateEvent(event.id, event.calendarId, zonedChanges); |
| 253 | + }); |
| 254 | + }, |
| 255 | +}; |
| 256 | + |
173 | 257 | export const CustomTemplate = Template.bind({});
|
174 | 258 | CustomTemplate.args = {
|
175 | 259 | ...Template.args,
|
|
0 commit comments