/
Handling Days in Custom Events

Handling Days in Custom Events

When creating custom events, users can select multiple days for their event to happen on.

Days for General and Tutoring Events

When createEvents is called for events created in the General and Tutoring tabs (note Add Invite behaves differently, they get passed as eventDays, an array of strings

  • e.g. eventDays = ['Mo', 'Fri'] represents events happening on Monday and Friday

When the event actually gets created (see createNewEvent in createEvent.ts), each day in the eventDays array is transformed from a string to an integer via the below line

day: daysShort.indexOf(day) + 1

where daysShort = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'] in timetable.ts.

As such, days in the stored custom event object can be interpreted as:

  • 1 → Monday

  • 2 → Tuesday

  • 3 → Wednesday

  • 4 → Thursday

  • 5 → Friday

  • 6 → Saturday

  • 7 → Sunday

The daysLong array uses the stored integer to transform the integer back into a string to display what day an event is on in ExpandedEventView.tsx

  • i.e. daysLong[day - 1]

    • E.g. day = 1 would be transformed into the string ‘Monday’

where daysLong = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] in timetable.ts.

Days for Invite Events

Days behave slightly differently for add invite events. Instead, we get the day information from an existing stored event object. As stated above, days are already saved as integers.

As such, when we create events in this tab (see createNewInviteEvent in createEvent.ts), there is no transformation from an integer to a string, the given day integer is immediately stored as

day: day

 

Related content