aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shared/date.ts
blob: 583d2a6a0e6cd3f9d4bf8690bb973ac053be6e9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * Returns the end-of-day boundary for due card comparison.
 *
 * The "study day" is defined as 3:00 AM to the next day's 3:00 AM.
 * All cards with `due < boundary` are considered due for the current study day.
 *
 * - If current time >= 3:00 AM, boundary = tomorrow 3:00 AM local time
 * - If current time < 3:00 AM, boundary = today 3:00 AM local time
 */
export function getEndOfStudyDayBoundary(now: Date = new Date()): Date {
	const boundary = new Date(now);
	boundary.setMinutes(0, 0, 0);

	if (boundary.getHours() >= 3) {
		// Move to next day
		boundary.setDate(boundary.getDate() + 1);
	}

	boundary.setHours(3);
	return boundary;
}