1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
import { describe, expect, it } from "vitest";
import { getEndOfStudyDayBoundary, getStartOfStudyDayBoundary } from "./date";
describe("getStartOfStudyDayBoundary", () => {
it("should return today 3:00 AM when current time is after 3:00 AM", () => {
// Feb 2, 2026 10:00 AM
const now = new Date(2026, 1, 2, 10, 0, 0, 0);
const boundary = getStartOfStudyDayBoundary(now);
expect(boundary.getFullYear()).toBe(2026);
expect(boundary.getMonth()).toBe(1);
expect(boundary.getDate()).toBe(2);
expect(boundary.getHours()).toBe(3);
expect(boundary.getMinutes()).toBe(0);
expect(boundary.getSeconds()).toBe(0);
});
it("should return yesterday 3:00 AM when current time is before 3:00 AM", () => {
// Feb 2, 2026 1:30 AM
const now = new Date(2026, 1, 2, 1, 30, 0, 0);
const boundary = getStartOfStudyDayBoundary(now);
expect(boundary.getFullYear()).toBe(2026);
expect(boundary.getMonth()).toBe(1);
expect(boundary.getDate()).toBe(1);
expect(boundary.getHours()).toBe(3);
expect(boundary.getMinutes()).toBe(0);
expect(boundary.getSeconds()).toBe(0);
});
it("should return today 3:00 AM when current time is exactly 3:00 AM", () => {
// Feb 2, 2026 3:00 AM
const now = new Date(2026, 1, 2, 3, 0, 0, 0);
const boundary = getStartOfStudyDayBoundary(now);
expect(boundary.getDate()).toBe(2);
expect(boundary.getHours()).toBe(3);
});
it("should handle month boundaries correctly", () => {
// Feb 1, 2026 1:00 AM
const now = new Date(2026, 1, 1, 1, 0, 0, 0);
const boundary = getStartOfStudyDayBoundary(now);
expect(boundary.getMonth()).toBe(0); // January
expect(boundary.getDate()).toBe(31);
expect(boundary.getHours()).toBe(3);
});
});
describe("getEndOfStudyDayBoundary", () => {
it("should return next day 3:00 AM when current time is after 3:00 AM", () => {
// Feb 2, 2026 10:00 AM
const now = new Date(2026, 1, 2, 10, 0, 0, 0);
const boundary = getEndOfStudyDayBoundary(now);
expect(boundary.getFullYear()).toBe(2026);
expect(boundary.getMonth()).toBe(1);
expect(boundary.getDate()).toBe(3);
expect(boundary.getHours()).toBe(3);
expect(boundary.getMinutes()).toBe(0);
expect(boundary.getSeconds()).toBe(0);
});
it("should return today 3:00 AM when current time is before 3:00 AM", () => {
// Feb 2, 2026 1:30 AM
const now = new Date(2026, 1, 2, 1, 30, 0, 0);
const boundary = getEndOfStudyDayBoundary(now);
expect(boundary.getFullYear()).toBe(2026);
expect(boundary.getMonth()).toBe(1);
expect(boundary.getDate()).toBe(2);
expect(boundary.getHours()).toBe(3);
expect(boundary.getMinutes()).toBe(0);
expect(boundary.getSeconds()).toBe(0);
});
it("should return next day 3:00 AM when current time is exactly 3:00 AM", () => {
// Feb 2, 2026 3:00 AM
const now = new Date(2026, 1, 2, 3, 0, 0, 0);
const boundary = getEndOfStudyDayBoundary(now);
expect(boundary.getDate()).toBe(3);
expect(boundary.getHours()).toBe(3);
});
it("should return next day 3:00 AM when current time is 11:59 PM", () => {
// Feb 2, 2026 11:59 PM
const now = new Date(2026, 1, 2, 23, 59, 0, 0);
const boundary = getEndOfStudyDayBoundary(now);
expect(boundary.getDate()).toBe(3);
expect(boundary.getHours()).toBe(3);
});
it("should handle month boundaries correctly", () => {
// Jan 31, 2026 15:00
const now = new Date(2026, 0, 31, 15, 0, 0, 0);
const boundary = getEndOfStudyDayBoundary(now);
expect(boundary.getMonth()).toBe(1); // February
expect(boundary.getDate()).toBe(1);
expect(boundary.getHours()).toBe(3);
});
});
|