Skip to content

Commit

Permalink
24hr->12hr + notif always on
Browse files Browse the repository at this point in the history
  • Loading branch information
jho44 committed Aug 13, 2023
1 parent 79c6c59 commit f5cdc22
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/lib/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ import { DateTime } from 'luxon';

export const toLocalTimezone = (d: Date, timeZone: string) =>
DateTime.fromJSDate(d).setZone(timeZone);

export const dateTo12Hour = (d: Date) => {
const luxonDate = DateTime.fromJSDate(d);
if (luxonDate.minute) return luxonDate.toFormat('h:mma').toLowerCase();
return luxonDate.toFormat('ha').toLowerCase();
};
24 changes: 23 additions & 1 deletion src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function generateDiffSchedule(ogRows: Row[], rows: Row[]): string[] {
return diffs;
}

export function generateFullSchedule(rows: any[]): string[] {
export function generateFullSchedule(rows: Row[]): string[] {
const schedule: string[] = [];
let lastIsBusy = false;

Expand All @@ -87,3 +87,25 @@ export function generateFullSchedule(rows: any[]): string[] {

return schedule;
}

export function timeToParts(t: string) {
// will look like either h:mma or ha
if (t.includes(':')) {
const [hStr, mmaStr] = t.split(':');
let h = parseInt(hStr);
const m = parseInt(mmaStr.slice(0, -2));
const a = mmaStr.slice(-2);
if (a === 'PM') h += 12;
return {
h,
m
};
}
const hStr = t.slice(0, -2);
let h = parseInt(hStr);
const a = t.slice(-2);
if (a === 'PM') h += 12;
return {
h
};
}
13 changes: 2 additions & 11 deletions src/routes/calendar/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { dateTo12Hour } from '$lib/date';
import type { PageServerLoad } from './$types';
import { PrismaClient, AvailabilityStatus } from '@prisma/client';

Expand Down Expand Up @@ -68,17 +69,7 @@ export const load = (async ({ parent, depends }) => {
default: {
availRange = 'AVAILABLE'; // should never actually be rendered as such
if (x.startTime && x.endTime) {
const startMins = x.startTime.getMinutes();
let startRange = `${startMins}`;
if (startMins < 10) startRange = `0${startRange}`;
startRange = `${x.startTime.getHours()}:${startRange}`;

const endMins = x.endTime.getMinutes();
let endRange = `${endMins}`;
if (endMins < 10) endRange = `0${endRange}`;
endRange = `${x.endTime.getHours()}:${endRange}`;

availRange = `${startRange} - ${endRange}`;
availRange = `${dateTo12Hour(x.startTime)} - ${dateTo12Hour(x.endTime)}`;
}
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/routes/calendar/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
availRange !== AvailabilityStatus.UNSPECIFIED &&
availRange !== AvailabilityStatus.BUSY
) {
// it's gonna be formatted like H:MM - H:MM
// it's gonna be formatted like h(:mm)a - h(:mm)a
const timeSplit = availRange.split(/[( - )|:]/);
startHr = parseInt(timeSplit[0]);
startMin = parseInt(timeSplit[1]);
Expand Down Expand Up @@ -82,12 +82,13 @@
if (status === AvailabilityStatus.UNSPECIFIED || status === AvailabilityStatus.BUSY) return {};
// validator and formatter
const regexpRange =
/\s*(?<fromhr>[0-9]+)(:(?<frommin>[0-5][0-9]))?\s*(?<fromhalf>am|pm)?\s*(-|to|until|till)\s*(?<tohr>[0-9]+)(:(?<tomin>[0-5][0-9]))?\s*(?<tohalf>am|pm)?\s*/i;
/\s*(?<fromhr>[0-9]+)(:(?<frommin>[0-5][0-9]))?\s*(?<fromhalf>am|pm|AM|PM)?\s*(-|to|until|till)\s*(?<tohr>[0-9]+)(:(?<tomin>[0-5][0-9]))?\s*(?<tohalf>am|pm|AM|PM)?\s*/i;
const t = rows[i].availRange.match(regexpRange)?.groups;
if (!t) {
return {};
}
let { fromhalf, tohalf } = t;
let fromhalf = t.fromhalf?.toLowerCase();
let tohalf = t.tohalf?.toLowerCase();
let fromhr = parseInt(t.fromhr);
let tohr = parseInt(t.tohr);
let frommin = t.frommin ? parseInt(t.frommin) : 0;
Expand All @@ -111,10 +112,10 @@
fromhalf = 'am';
}
tohalf = 'pm';
} else if (fromhalf) {
} else if (fromhalf && !tohalf) {
if (tohr * 100 + tomin > fromhr * 100 + frommin) tohalf = fromhalf;
else tohalf = fromhalf === 'am' ? 'pm' : 'am';
} else {
} else if (!fromhalf && tohalf) {
if (tohr * 100 + tomin > fromhr * 100 + frommin) fromhalf = tohalf;
else fromhalf = tohalf === 'am' ? 'pm' : 'am';
}
Expand Down Expand Up @@ -210,6 +211,10 @@
});
notified.add(phone);
notified = new Set(notified);
setTimeout(() => {
notified.delete(phone);
notified = new Set(notified);
}, 4000);
}
}
function notifyAll() {
Expand Down Expand Up @@ -668,6 +673,8 @@
}
#notif-table td {
padding: 0.4rem 0;
height: 46px;
width: 50%;
}
.tooltiptext {
left: 0;
Expand Down
4 changes: 1 addition & 3 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ test.beforeEach(async () => {
await run();
});

test.only('Redirect to login page w/ prefilled phone num on expired magic link', async ({
page
}) => {
test('Redirect to login page w/ prefilled phone num on expired magic link', async ({ page }) => {
await page.goto('http://localhost:5173/login/12015550121/3e99472f1003794c');

await page.waitForURL(`${host}?phone=12015550121`, { waitUntil: 'networkidle' });
Expand Down

0 comments on commit f5cdc22

Please sign in to comment.