Fixes collective availability for teams with overlapping day timezones (#3898)
* WIP
* Fix for team availability with time offsets
* Prevent empty schedule from opening up everything
* When no utcOffset or timeZone's are given, default to 0 utcOffset (UTC)
* timeZone should not be part of getUserAvailability
* Prevents {days:[X],startTime:0,endTime:0} error entry
* Added getAggregateWorkingHours() (#3913)
* Added test for getAggregateWorkingHours
* Timezone isn't used here anymore
* fix: developer docs url (#3914)
* fix: developer docs url added
* chore : remove /
* chore : import url
Co-authored-by: Zach Waterfield <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
* Test fixes
* Reinstate prisma (generate only) and few comments
* Test fixes
* Skipping getSchedule again
* Added await to expect() as it involves async logic causing the promise to timeout
* Test cleanup
* Update jest.config.ts
Co-authored-by: Alan <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Zach Waterfield <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
15 files changed
+317
-181
No files matched your search
@@ -65,21 +65,15 @@ export function getWorkingHours(
|
||||
},
|
||||
availability: { days: number[]; startTime: ConfigType; endTime: ConfigType }[]
|
||||
) {
|
||||
// clearly bail when availability is not set, set everything available.
|
||||
if (!availability.length) {
|
||||
return [
|
||||
{
|
||||
days: [0, 1, 2, 3, 4, 5, 6],
|
||||
// shorthand for: dayjs().startOf("day").tz(timeZone).diff(dayjs.utc().startOf("day"), "minutes")
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: MINUTES_DAY_END,
|
||||
},
|
||||
];
|
||||
return [];
|
||||
}
|
||||
|
||||
const utcOffset = relativeTimeUnit.utcOffset ?? dayjs().tz(relativeTimeUnit.timeZone).utcOffset();
|
||||
const utcOffset =
|
||||
relativeTimeUnit.utcOffset ??
|
||||
(relativeTimeUnit.timeZone ? dayjs().tz(relativeTimeUnit.timeZone).utcOffset() : 0);
|
||||
|
||||
const workingHours = availability.reduce((workingHours: WorkingHours[], schedule) => {
|
||||
const workingHours = availability.reduce((currentWorkingHours: WorkingHours[], schedule) => {
|
||||
// Get times localised to the given utcOffset/timeZone
|
||||
const startTime =
|
||||
dayjs.utc(schedule.startTime).get("hour") * 60 +
|
||||
@@ -90,9 +84,11 @@ export function getWorkingHours(
|
||||
// add to working hours, keeping startTime and endTimes between bounds (0-1439)
|
||||
const sameDayStartTime = Math.max(MINUTES_DAY_START, Math.min(MINUTES_DAY_END, startTime));
|
||||
const sameDayEndTime = Math.max(MINUTES_DAY_START, Math.min(MINUTES_DAY_END, endTime));
|
||||
|
||||
if (sameDayEndTime < sameDayStartTime) {
|
||||
return currentWorkingHours;
|
||||
}
|
||||
if (sameDayStartTime !== sameDayEndTime) {
|
||||
workingHours.push({
|
||||
currentWorkingHours.push({
|
||||
days: schedule.days,
|
||||
startTime: sameDayStartTime,
|
||||
endTime: sameDayEndTime,
|
||||
@@ -101,22 +97,22 @@ export function getWorkingHours(
|
||||
// check for overflow to the previous day
|
||||
// overflowing days constraint to 0-6 day range (Sunday-Saturday)
|
||||
if (startTime < MINUTES_DAY_START || endTime < MINUTES_DAY_START) {
|
||||
workingHours.push({
|
||||
currentWorkingHours.push({
|
||||
days: schedule.days.map((day) => (day - 1 >= 0 ? day - 1 : 6)),
|
||||
startTime: startTime + MINUTES_IN_DAY,
|
||||
endTime: Math.min(endTime + MINUTES_IN_DAY, MINUTES_DAY_END),
|
||||
});
|
||||
}
|
||||
// else, check for overflow in the next day
|
||||
else if (startTime > MINUTES_DAY_END || endTime > MINUTES_DAY_END) {
|
||||
workingHours.push({
|
||||
else if (startTime > MINUTES_DAY_END || endTime > MINUTES_IN_DAY) {
|
||||
currentWorkingHours.push({
|
||||
days: schedule.days.map((day) => (day + 1) % 7),
|
||||
startTime: Math.max(startTime - MINUTES_IN_DAY, MINUTES_DAY_START),
|
||||
endTime: endTime - MINUTES_IN_DAY,
|
||||
});
|
||||
}
|
||||
|
||||
return workingHours;
|
||||
return currentWorkingHours;
|
||||
}, []);
|
||||
|
||||
workingHours.sort((a, b) => a.startTime - b.startTime);
|
||||
|
||||
Reference in new issue
Block a user