MCPcopy Index your code
hub / github.com/MALSync/MALSync / getWeektime

Function getWeektime

src/utils/time.ts:13–35  ·  view source on GitHub ↗
(weekDay: string, time: string)

Source from the content-addressed store, hash-verified

11}
12
13export function getWeektime(weekDay: string, time: string): Date | null {
14 const daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
15 const dayIndex = daysOfWeek.findIndex(
16 day =>
17 day.toLowerCase() === weekDay.toLowerCase() ||
18 weekDay.toLowerCase().startsWith(day.toLowerCase()),
19 );
20
21 if (dayIndex === -1) return null;
22
23 // time has format 'hh:mm' or 'hh:mm am/pm'
24 const [timeStr, modifier] = time.split(' ');
25 const [hours, minutes] = timeStr.split(':').map(Number);
26
27 let hoursUTC = hours;
28 if (modifier?.toLowerCase() === 'pm' && hours !== 12) {
29 hoursUTC += 12;
30 } else if (modifier?.toLowerCase() === 'am' && hours === 12) {
31 hoursUTC = 0;
32 }
33
34 return new Date(Date.UTC(2017, 0, dayIndex + 1, hoursUTC, minutes, 0, 0));
35}

Callers 3

infoMethod · 0.90
infoMethod · 0.90
infoMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected