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

Function nextTimeInterval

src/utils/time.ts:40–77  ·  view source on GitHub ↗
(time0: string, time1: string, date: Date = new Date())

Source from the content-addressed store, hash-verified

38}
39
40export function nextTimeInterval(time0: string, time1: string, date: Date = new Date()): number | null {
41 const a = parse24HTime(time0);
42 const b = parse24HTime(time1);
43 const t = [date.getHours(), date.getMinutes()];
44
45 // Ensure a <= b
46 if (compareTime(a, b) > 0) {
47 return nextTimeInterval(time1, time0, date);
48 }
49
50 if (compareTime(a, b) === 0) {
51 return null;
52 }
53
54 if (compareTime(t, a) < 0) {
55 // t < a <= b
56 // Schedule for todate at time a
57 date.setHours(a[0]);
58 date.setMinutes(a[1]);
59 date.setSeconds(0);
60 date.setMilliseconds(0);
61 return date.getTime();
62 }
63
64 if (compareTime(t, b) < 0) {
65 // a <= t < b
66 // Schedule for today at time b
67 date.setHours(b[0]);
68 date.setMinutes(b[1]);
69 date.setSeconds(0);
70 date.setMilliseconds(0);
71 return date.getTime();
72 }
73
74 // a <= b <= t
75 // Schedule for tomorrow at time a
76 return (new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1, a[0], a[1])).getTime();
77}
78
79export function isInTimeIntervalLocal(time0: string, time1: string, date: Date = new Date()): boolean {
80 const a = parse24HTime(time0);

Callers 2

updateAutoStateMethod · 0.90
time.tests.tsFile · 0.90

Calls 2

parse24HTimeFunction · 0.85
compareTimeFunction · 0.85

Tested by

no test coverage detected