@@ -19,6 +19,7 @@ describe("timeAgo()", () => {
19
19
beforeEach ( mockDate ) ;
20
20
afterEach ( unMockDate ) ;
21
21
22
+ // Year tests (past and future)
22
23
test ( "timeAgo() handles year " , ( ) => {
23
24
const yearAgo = new Date ( "2022-09-15:00:00" ) ;
24
25
expect ( timeAgo ( yearAgo ) ) . toBe ( "1 jaar geleden" ) ;
@@ -27,8 +28,17 @@ describe("timeAgo()", () => {
27
28
const yearsAgo = new Date ( "2021-09-15:00:00" ) ;
28
29
expect ( timeAgo ( yearsAgo ) ) . toBe ( "2 jaren geleden" ) ;
29
30
expect ( timeAgo ( yearsAgo , { shortFormat : true } ) ) . toBe ( "2j" ) ;
31
+
32
+ const yearAhead = new Date ( "2024-09-15:00:00" ) ;
33
+ expect ( timeAgo ( yearAhead ) ) . toBe ( "over 1 jaar" ) ;
34
+ expect ( timeAgo ( yearAhead , { shortFormat : true } ) ) . toBe ( "over 1j" ) ;
35
+
36
+ const yearsAhead = new Date ( "2025-09-15:00:00" ) ;
37
+ expect ( timeAgo ( yearsAhead ) ) . toBe ( "over 2 jaren" ) ;
38
+ expect ( timeAgo ( yearsAhead , { shortFormat : true } ) ) . toBe ( "over 2j" ) ;
30
39
} ) ;
31
40
41
+ // Month tests (past and future)
32
42
test ( "timeAgo() handles month " , ( ) => {
33
43
const monthAgo = new Date ( "2023-08-15:00:00" ) ;
34
44
expect ( timeAgo ( monthAgo ) ) . toBe ( "1 maand geleden" ) ;
@@ -37,8 +47,17 @@ describe("timeAgo()", () => {
37
47
const monthsAgo = new Date ( "2023-07-15:00:00" ) ;
38
48
expect ( timeAgo ( monthsAgo ) ) . toBe ( "2 maanden geleden" ) ;
39
49
expect ( timeAgo ( monthsAgo , { shortFormat : true } ) ) . toBe ( "2ma" ) ;
50
+
51
+ const monthAhead = new Date ( "2023-10-15:00:00" ) ;
52
+ expect ( timeAgo ( monthAhead ) ) . toBe ( "over 1 maand" ) ;
53
+ expect ( timeAgo ( monthAhead , { shortFormat : true } ) ) . toBe ( "over 1ma" ) ;
54
+
55
+ const monthsAhead = new Date ( "2023-11-15:00:00" ) ;
56
+ expect ( timeAgo ( monthsAhead ) ) . toBe ( "over 2 maanden" ) ;
57
+ expect ( timeAgo ( monthsAhead , { shortFormat : true } ) ) . toBe ( "over 2ma" ) ;
40
58
} ) ;
41
59
60
+ // Day tests (past and future)
42
61
test ( "timeAgo() handles day " , ( ) => {
43
62
const dayAgo = new Date ( "2023-09-14:00:00" ) ;
44
63
expect ( timeAgo ( dayAgo ) ) . toBe ( "1 dag geleden" ) ;
@@ -47,8 +66,17 @@ describe("timeAgo()", () => {
47
66
const daysAgo = new Date ( "2023-09-13:00:00" ) ;
48
67
expect ( timeAgo ( daysAgo ) ) . toBe ( "2 dagen geleden" ) ;
49
68
expect ( timeAgo ( daysAgo , { shortFormat : true } ) ) . toBe ( "2d" ) ;
69
+
70
+ const dayAhead = new Date ( "2023-09-16:00:00" ) ;
71
+ expect ( timeAgo ( dayAhead ) ) . toBe ( "over 1 dag" ) ;
72
+ expect ( timeAgo ( dayAhead , { shortFormat : true } ) ) . toBe ( "over 1d" ) ;
73
+
74
+ const daysAhead = new Date ( "2023-09-17:00:00" ) ;
75
+ expect ( timeAgo ( daysAhead ) ) . toBe ( "over 2 dagen" ) ;
76
+ expect ( timeAgo ( daysAhead , { shortFormat : true } ) ) . toBe ( "over 2d" ) ;
50
77
} ) ;
51
78
79
+ // Hour tests (past and future)
52
80
test ( "timeAgo() handles hour " , ( ) => {
53
81
const hourAgo = new Date ( "2023-09-14:23:00" ) ;
54
82
expect ( timeAgo ( hourAgo ) ) . toBe ( "1 uur geleden" ) ;
@@ -57,8 +85,17 @@ describe("timeAgo()", () => {
57
85
const hoursAgo = new Date ( "2023-09-14:22:00" ) ;
58
86
expect ( timeAgo ( hoursAgo ) ) . toBe ( "2 uur geleden" ) ;
59
87
expect ( timeAgo ( hoursAgo , { shortFormat : true } ) ) . toBe ( "2u" ) ;
88
+
89
+ const hourAhead = new Date ( "2023-09-15:01:00" ) ;
90
+ expect ( timeAgo ( hourAhead ) ) . toBe ( "over 1 uur" ) ;
91
+ expect ( timeAgo ( hourAhead , { shortFormat : true } ) ) . toBe ( "over 1u" ) ;
92
+
93
+ const hoursAhead = new Date ( "2023-09-15:02:00" ) ;
94
+ expect ( timeAgo ( hoursAhead ) ) . toBe ( "over 2 uur" ) ;
95
+ expect ( timeAgo ( hoursAhead , { shortFormat : true } ) ) . toBe ( "over 2u" ) ;
60
96
} ) ;
61
97
98
+ // Minute tests (past and future)
62
99
test ( "timeAgo() handles minute " , ( ) => {
63
100
const minuteAgo = new Date ( "2023-09-14:23:59" ) ;
64
101
expect ( timeAgo ( minuteAgo ) ) . toBe ( "1 minuut geleden" ) ;
@@ -67,8 +104,17 @@ describe("timeAgo()", () => {
67
104
const minutesAgo = new Date ( "2023-09-14:23:58" ) ;
68
105
expect ( timeAgo ( minutesAgo ) ) . toBe ( "2 minuten geleden" ) ;
69
106
expect ( timeAgo ( minutesAgo , { shortFormat : true } ) ) . toBe ( "2m" ) ;
107
+
108
+ const minuteAhead = new Date ( "2023-09-15:00:01" ) ;
109
+ expect ( timeAgo ( minuteAhead ) ) . toBe ( "over 1 minuut" ) ;
110
+ expect ( timeAgo ( minuteAhead , { shortFormat : true } ) ) . toBe ( "over 1m" ) ;
111
+
112
+ const minutesAhead = new Date ( "2023-09-15:00:02" ) ;
113
+ expect ( timeAgo ( minutesAhead ) ) . toBe ( "over 2 minuten" ) ;
114
+ expect ( timeAgo ( minutesAhead , { shortFormat : true } ) ) . toBe ( "over 2m" ) ;
70
115
} ) ;
71
116
117
+ // Less than a minute tests (past and future)
72
118
test ( "timeAgo() handles less than a minute " , ( ) => {
73
119
const secondAgo = new Date ( "2023-09-14:23:59:59" ) ;
74
120
expect ( timeAgo ( secondAgo ) ) . toBe ( "Nu" ) ;
@@ -77,14 +123,17 @@ describe("timeAgo()", () => {
77
123
const secondsAgo = new Date ( "2023-09-14:23:59:59" ) ;
78
124
expect ( timeAgo ( secondsAgo ) ) . toBe ( "Nu" ) ;
79
125
expect ( timeAgo ( secondsAgo , { shortFormat : true } ) ) . toBe ( "0m" ) ;
80
- } ) ;
81
126
82
- test ( "timeAgo() interprets future data as now " , ( ) => {
83
- const yearFromNow = new Date ( "2024-09-15:00:00" ) ;
84
- expect ( timeAgo ( yearFromNow ) ) . toBe ( "Nu" ) ;
85
- expect ( timeAgo ( yearFromNow , { shortFormat : true } ) ) . toBe ( "0m" ) ;
127
+ const secondAhead = new Date ( "2023-09-15:00:00:01" ) ;
128
+ expect ( timeAgo ( secondAhead ) ) . toBe ( "zo meteen" ) ;
129
+ expect ( timeAgo ( secondAhead , { shortFormat : true } ) ) . toBe ( "0m" ) ;
130
+
131
+ const secondsAhead = new Date ( "2023-09-15:00:00:02" ) ;
132
+ expect ( timeAgo ( secondsAhead ) ) . toBe ( "zo meteen" ) ;
133
+ expect ( timeAgo ( secondsAhead , { shortFormat : true } ) ) . toBe ( "0m" ) ;
86
134
} ) ;
87
135
136
+ // Combined scenarios (past and future)
88
137
test ( "timeAgo() handles combined scenario " , ( ) => {
89
138
const yearAgo = new Date ( "2022-08-14:23:59:59" ) ;
90
139
expect ( timeAgo ( yearAgo ) ) . toBe ( "1 jaar geleden" ) ;
@@ -93,6 +142,14 @@ describe("timeAgo()", () => {
93
142
const monthsAgo = new Date ( "2023-07-13:22:58:58" ) ;
94
143
expect ( timeAgo ( monthsAgo ) ) . toBe ( "2 maanden geleden" ) ;
95
144
expect ( timeAgo ( monthsAgo , { shortFormat : true } ) ) . toBe ( "2ma" ) ;
145
+
146
+ const yearAhead = new Date ( "2025-08-14:23:59:59" ) ;
147
+ expect ( timeAgo ( yearAhead ) ) . toBe ( "over 1 jaar" ) ;
148
+ expect ( timeAgo ( yearAhead , { shortFormat : true } ) ) . toBe ( "over 1j" ) ;
149
+
150
+ const monthsAhead = new Date ( "2023-11-13:22:58:58" ) ;
151
+ expect ( timeAgo ( monthsAhead ) ) . toBe ( "over 1 maand" ) ;
152
+ expect ( timeAgo ( monthsAhead , { shortFormat : true } ) ) . toBe ( "over 1ma" ) ;
96
153
} ) ;
97
154
} ) ;
98
155
0 commit comments