MCPcopy Index your code
hub / github.com/darkreader/darkreader / parseTime

Function parseTime

src/utils/time.ts:1–24  ·  view source on GitHub ↗
($time: string)

Source from the content-addressed store, hash-verified

1export function parseTime($time: string): [number, number] {
2 const parts = $time.split(':').slice(0, 2);
3 const lowercased = $time.trim().toLowerCase();
4 const isAM = lowercased.endsWith('am') || lowercased.endsWith('a.m.');
5 const isPM = lowercased.endsWith('pm') || lowercased.endsWith('p.m.');
6
7 let hours = parts.length > 0 ? parseInt(parts[0]) : 0;
8 if (isNaN(hours) || hours > 23) {
9 hours = 0;
10 }
11 if (isAM && hours === 12) {
12 hours = 0;
13 }
14 if (isPM && hours < 12) {
15 hours += 12;
16 }
17
18 let minutes = parts.length > 1 ? parseInt(parts[1]) : 0;
19 if (isNaN(minutes) || minutes > 59) {
20 minutes = 0;
21 }
22
23 return [hours, minutes];
24}
25
26function parse24HTime(time: string): number[] {
27 return time.split(':').map((x) => parseInt(x));

Callers 3

toLong24HTimeFunction · 0.90
to24HTimeFunction · 0.90
time.tests.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected