Skip to content

Commit

Permalink
test tz
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Jul 17, 2024
1 parent e88f942 commit 68093b5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
33 changes: 33 additions & 0 deletions client/selectors/tests/events_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,38 @@ describe('selectors', () => {

expect(ids(events['2024-07-17'])).toEqual(['event5', 'event4']);
});

it('from 2024-07-14 Toronto timezone', () => {
moment.tz.setDefault('America/Toronto');
const state = getState();

setAdvancedSearchDates(state, '2024-07-14T12:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
'2024-07-15',
'2024-07-16',
'2024-07-17',
'2024-07-18',
]);

expect(ids(events['2024-07-15'])).toEqual(['event5']);
expect(ids(events['2024-07-16'])).toEqual(['event5', 'event4']);
expect(ids(events['2024-07-17'])).toEqual(['event5', 'event4']);
expect(ids(events['2024-07-18'])).toEqual(['event5']);
});

it('from 2024-07-17 Toronto timezone', () => {
moment.tz.setDefault('America/Toronto');
const state = getState();

setAdvancedSearchDates(state, '2024-07-17T05:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
'2024-07-17',
'2024-07-18',
]);
});
});
});
5 changes: 4 additions & 1 deletion client/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ Object.assign(appConfig, {
planning_auto_assign_to_workflow: true,
});

moment.tz.setDefault('Australia/Sydney');
updateConfigAfterLoad();

beforeEach(() => {
moment.tz.setDefault('Australia/Sydney');
});

var testsContext = require.context('.', true, /_test.[j|t]sx?$/);

testsContext.keys().forEach(testsContext);
26 changes: 21 additions & 5 deletions client/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,25 +934,41 @@ function getEventsByDate(
}

sortedEvents.forEach((event) => {
const eventEndDate = event.actioned_date ? moment(event.actioned_date) : getEndDate(event);
const eventStartDate = getStartDate(event);
const eventEndDate = event.actioned_date ? moment(event.actioned_date) : getLocalEndDate(event);
const eventStartDate = getLocalStartDate(event);

console.info("EVENT", event.name, eventStartDate.toString(), eventEndDate.toString());
console.info('EVENT', event.name, eventStartDate.toString(), eventEndDate.toString());

const displayStartDate = eventStartDate.isSameOrAfter(startDate) ? eventStartDate : startDate;
const displayEndDate = eventEndDate.isSameOrBefore(endDate) ? eventEndDate : endDate;

console.info("DISPLAY", displayStartDate.toString(), displayEndDate.toString());
console.info('DISPLAY', displayStartDate.toString(), displayEndDate.toString());

for (const day = displayStartDate.clone(); day.isSameOrBefore(displayEndDate, 'day'); day.add(1, 'days')) {
console.info(" DAY", day.toString());
console.info(' DAY', day.toString());
addEventToDate(event, day, eventStartDate);
}
});

return sortBasedOnTBC(days);
}

function getLocalStartDate(event: IEventItem): moment.Moment {
if (event.dates.all_day) {
return moment(moment.utc(event.dates.start).format('YYYY-MM-DD'));
}

return moment(event.dates.start);
}

function getLocalEndDate(event: IEventItem): moment.Moment {
if (event.dates.all_day || event.dates.no_end_time) {
return moment(moment.utc(event.dates.end).format('YYYY-MM-DD')).endOf('day');
}

return moment(event.dates.end);
}

function modifyForClient(event: Partial<IEventItem>): Partial<IEventItem> {
sanitizeItemFields(event);

Expand Down

0 comments on commit 68093b5

Please sign in to comment.