-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: initial full cleanup #157
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Heads up while still in draft. Some logic in dealing with schedule strings was moved to various locations. Merge interval logic has caused failures on edge cases before. Therefore, please use a version of this block of logic (its complexity is needed for edge cases) rather than moving its logic or keep most of it in one area in this PR, so easier to review and don't accidentally break API. Can refactor in new PR after. More specifically, this logic is very important:
|
This comment was marked as outdated.
This comment was marked as outdated.
Thanks for pointing that out! I believe that the above functionality has all been shifted to the following two code snippets: export function sortAndMergeTimeRanges(timeRanges: ITimeRange[]) {
timeRanges.sort((range1, range2) =>
compareTimeMoments(range1.start, range2.start)
);
const mergedRanges: ITimeRange[] = [];
for (const timeRange of timeRanges) {
const lastTimeRange = mergedRanges.length
? mergedRanges[mergedRanges.length - 1]
: undefined;
if (
lastTimeRange &&
compareTimeMoments(lastTimeRange.end, timeRange.start) >= 0
) {
if (compareTimeMoments(timeRange.end, lastTimeRange.end) > 0) {
lastTimeRange.end = timeRange.end; // join current range with last range
}
} else {
mergedRanges.push(timeRange);
}
}
console.log(timeRanges, mergedRanges);
return mergedRanges;
} and function getTimeRangesFromTimeRow(time: ITimeRowAttributes) {
if (time.day === undefined) {
throw new Error("Cannot convert when day is not set");
}
const allRanges: ITimeRange[] = [];
for (const range of time.times ?? []) {
if (range.end.hour === 0 && range.end.minute === 0) {
range.end.hour = 23;
range.end.minute = 59; // roll back from 12AM to 11:59 previous day <- specifically this
}
const spillToNextDay =
range.start.hour * 60 + range.start.minute >
range.end.hour * 60 + range.end.minute;
allRanges.push({
start: {
day: time.day,
hour: range.start.hour,
minute: range.start.minute,
},
end: {
day: spillToNextDay ? getNextDay(time.day) : time.day,
hour: range.end.hour,
minute: range.end.minute,
},
});
}
return allRanges;
} so rather than filtering by type and sorting before time parsing, we just do it afterwards with the parsed This code also passes all edge cases mentioned in a previous issue (the tests are in the other PR - not this one) |
Description
No change in functionality, just a lot of moving code around for a hopefully more readable/debuggable codebase.
Conveniently closes #150 (tests aren't in this PR but I ran them here to make sure)

Type of change
How Has This Been Tested?
Test Configuration:
Checklist: