@osimatic/helpers-js 1.4.24 → 1.4.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +2 -1
- package/chartjs.js +1 -1
- package/date_time.js +25 -16
- package/draw.js +3 -2
- package/duration.js +12 -15
- package/event_bus.js +2 -2
- package/file.js +1 -1
- package/form_helper.js +1 -1
- package/http_client.js +2 -0
- package/jwt.js +18 -6
- package/media.js +1 -1
- package/number.js +2 -3
- package/package.json +3 -2
- package/social_network.js +5 -0
- package/string.js +11 -2
- package/tests/chartjs.test.js +273 -0
- package/tests/date_time/DatePeriod.test.js +179 -0
- package/tests/date_time/DateTime.test.js +492 -0
- package/tests/date_time/SqlDate.test.js +205 -0
- package/tests/date_time/SqlDateTime.test.js +326 -0
- package/tests/date_time/SqlTime.test.js +162 -0
- package/tests/date_time/TimestampUnix.test.js +262 -0
- package/tests/draw.test.js +271 -0
- package/tests/duration.test.js +365 -0
- package/tests/event_bus.test.js +268 -0
- package/tests/file.test.js +358 -0
- package/tests/form_date.test.js +417 -0
- package/tests/form_helper.test.js +415 -0
- package/tests/http_client.test.js +570 -0
- package/tests/jwt.test.js +804 -0
- package/tests/media.test.js +458 -0
- package/tests/network.test.js +489 -0
- package/tests/number.test.js +448 -0
- package/tests/open_street_map.test.js +388 -0
- package/tests/shopping_cart.test.js +355 -0
- package/tests/social_network.test.js +333 -0
- package/tests/string.test.js +473 -0
- package/tests/user.test.js +204 -0
- package/tests/util.test.js +99 -0
- package/tests/visitor.test.js +508 -0
- package/tmpclaude-00a6-cwd +1 -0
- package/tmpclaude-0526-cwd +1 -0
- package/tmpclaude-0973-cwd +1 -0
- package/tmpclaude-0b61-cwd +1 -0
- package/tmpclaude-146f-cwd +1 -0
- package/tmpclaude-223d-cwd +1 -0
- package/tmpclaude-2330-cwd +1 -0
- package/tmpclaude-282a-cwd +1 -0
- package/tmpclaude-2846-cwd +1 -0
- package/tmpclaude-28a6-cwd +1 -0
- package/tmpclaude-2b5a-cwd +1 -0
- package/tmpclaude-2def-cwd +1 -0
- package/tmpclaude-3906-cwd +1 -0
- package/tmpclaude-3b32-cwd +1 -0
- package/tmpclaude-3da9-cwd +1 -0
- package/tmpclaude-3dc3-cwd +1 -0
- package/tmpclaude-3e3b-cwd +1 -0
- package/tmpclaude-43b6-cwd +1 -0
- package/tmpclaude-4495-cwd +1 -0
- package/tmpclaude-462f-cwd +1 -0
- package/tmpclaude-4b29-cwd +1 -0
- package/tmpclaude-4db5-cwd +1 -0
- package/tmpclaude-4e01-cwd +1 -0
- package/tmpclaude-5101-cwd +1 -0
- package/tmpclaude-524f-cwd +1 -0
- package/tmpclaude-5636-cwd +1 -0
- package/tmpclaude-5cdd-cwd +1 -0
- package/tmpclaude-5f1f-cwd +1 -0
- package/tmpclaude-6078-cwd +1 -0
- package/tmpclaude-622e-cwd +1 -0
- package/tmpclaude-6802-cwd +1 -0
- package/tmpclaude-6e36-cwd +1 -0
- package/tmpclaude-7793-cwd +1 -0
- package/tmpclaude-7f96-cwd +1 -0
- package/tmpclaude-8566-cwd +1 -0
- package/tmpclaude-8874-cwd +1 -0
- package/tmpclaude-8915-cwd +1 -0
- package/tmpclaude-8c8b-cwd +1 -0
- package/tmpclaude-94df-cwd +1 -0
- package/tmpclaude-9859-cwd +1 -0
- package/tmpclaude-9ac5-cwd +1 -0
- package/tmpclaude-9f18-cwd +1 -0
- package/tmpclaude-a202-cwd +1 -0
- package/tmpclaude-a741-cwd +1 -0
- package/tmpclaude-ab5f-cwd +1 -0
- package/tmpclaude-b008-cwd +1 -0
- package/tmpclaude-b0a1-cwd +1 -0
- package/tmpclaude-b63d-cwd +1 -0
- package/tmpclaude-b681-cwd +1 -0
- package/tmpclaude-b72d-cwd +1 -0
- package/tmpclaude-b92f-cwd +1 -0
- package/tmpclaude-bc49-cwd +1 -0
- package/tmpclaude-bc50-cwd +1 -0
- package/tmpclaude-bccf-cwd +1 -0
- package/tmpclaude-be55-cwd +1 -0
- package/tmpclaude-c228-cwd +1 -0
- package/tmpclaude-c717-cwd +1 -0
- package/tmpclaude-c7ce-cwd +1 -0
- package/tmpclaude-cf3e-cwd +1 -0
- package/tmpclaude-d142-cwd +1 -0
- package/tmpclaude-d5bc-cwd +1 -0
- package/tmpclaude-d6ae-cwd +1 -0
- package/tmpclaude-d77a-cwd +1 -0
- package/tmpclaude-d8da-cwd +1 -0
- package/tmpclaude-dbdb-cwd +1 -0
- package/tmpclaude-de61-cwd +1 -0
- package/tmpclaude-de81-cwd +1 -0
- package/tmpclaude-df9d-cwd +1 -0
- package/tmpclaude-e786-cwd +1 -0
- package/tmpclaude-f01d-cwd +1 -0
- package/tmpclaude-f2a9-cwd +1 -0
- package/tmpclaude-fc36-cwd +1 -0
- package/tmpclaude-ffef-cwd +1 -0
- package/visitor.js +2 -2
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
const { SqlDate } = require('../../date_time');
|
|
2
|
+
|
|
3
|
+
describe('SqlDate', () => {
|
|
4
|
+
describe('parse', () => {
|
|
5
|
+
test('should parse SQL date to Date object', () => {
|
|
6
|
+
const sqlDate = '2024-01-15';
|
|
7
|
+
const result = SqlDate.parse(sqlDate);
|
|
8
|
+
expect(result instanceof Date).toBe(true);
|
|
9
|
+
expect(result.getUTCFullYear()).toBe(2024);
|
|
10
|
+
expect(result.getUTCMonth()).toBe(0);
|
|
11
|
+
expect(result.getUTCDate()).toBe(15);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should return null for null input', () => {
|
|
15
|
+
expect(SqlDate.parse(null)).toBeNull();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should parse last day of month', () => {
|
|
19
|
+
const sqlDate = '2024-01-31';
|
|
20
|
+
const result = SqlDate.parse(sqlDate);
|
|
21
|
+
expect(result.getUTCDate()).toBe(31);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('should parse February 29 in leap year', () => {
|
|
25
|
+
const sqlDate = '2024-02-29';
|
|
26
|
+
const result = SqlDate.parse(sqlDate);
|
|
27
|
+
expect(result.getUTCMonth()).toBe(1);
|
|
28
|
+
expect(result.getUTCDate()).toBe(29);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('getCurrentSqlDate', () => {
|
|
33
|
+
test('should return current date in SQL format', () => {
|
|
34
|
+
const result = SqlDate.getCurrentSqlDate();
|
|
35
|
+
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('should return today\'s date', () => {
|
|
39
|
+
const result = SqlDate.getCurrentSqlDate();
|
|
40
|
+
const today = new Date();
|
|
41
|
+
const year = today.getFullYear();
|
|
42
|
+
expect(result).toContain(String(year));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('getDateDigitalDisplay', () => {
|
|
47
|
+
test('should format SQL date in digital format', () => {
|
|
48
|
+
const sqlDate = '2024-01-15';
|
|
49
|
+
const result = SqlDate.getDateDigitalDisplay(sqlDate, 'fr-FR', 'UTC');
|
|
50
|
+
expect(result).toContain('15');
|
|
51
|
+
expect(result).toContain('01');
|
|
52
|
+
expect(result).toContain('2024');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('should work with different locales', () => {
|
|
56
|
+
const sqlDate = '2024-01-15';
|
|
57
|
+
const resultFr = SqlDate.getDateDigitalDisplay(sqlDate, 'fr-FR', 'UTC');
|
|
58
|
+
const resultEn = SqlDate.getDateDigitalDisplay(sqlDate, 'en-US', 'UTC');
|
|
59
|
+
expect(resultFr).toBeTruthy();
|
|
60
|
+
expect(resultEn).toBeTruthy();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('getDateTextDisplay', () => {
|
|
65
|
+
test('should format SQL date in text format', () => {
|
|
66
|
+
const sqlDate = '2024-01-15';
|
|
67
|
+
const result = SqlDate.getDateTextDisplay(sqlDate, 'fr-FR', 'UTC');
|
|
68
|
+
expect(typeof result).toBe('string');
|
|
69
|
+
expect(result.length).toBeGreaterThan(10);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('should include month name', () => {
|
|
73
|
+
const sqlDate = '2024-01-15';
|
|
74
|
+
const result = SqlDate.getDateTextDisplay(sqlDate, 'fr-FR', 'UTC');
|
|
75
|
+
expect(result).toContain('janvier');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('getDateForInputDate', () => {
|
|
80
|
+
test('should return date in input format', () => {
|
|
81
|
+
const sqlDate = '2024-01-15';
|
|
82
|
+
const result = SqlDate.getDateForInputDate(sqlDate, 'UTC');
|
|
83
|
+
expect(result).toBe('2024-01-15');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('getTimestamp', () => {
|
|
88
|
+
test('should convert SQL date to timestamp', () => {
|
|
89
|
+
const sqlDate = '2024-01-15';
|
|
90
|
+
const result = SqlDate.getTimestamp(sqlDate);
|
|
91
|
+
expect(typeof result).toBe('number');
|
|
92
|
+
expect(result).toBeGreaterThan(0);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('should return consistent timestamp', () => {
|
|
96
|
+
const sqlDate = '2024-01-15';
|
|
97
|
+
const result1 = SqlDate.getTimestamp(sqlDate);
|
|
98
|
+
const result2 = SqlDate.getTimestamp(sqlDate);
|
|
99
|
+
expect(result1).toBe(result2);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('getYear', () => {
|
|
104
|
+
test('should return year from SQL date', () => {
|
|
105
|
+
const sqlDate = '2024-01-15';
|
|
106
|
+
expect(SqlDate.getYear(sqlDate)).toBe(2024);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('should work with different years', () => {
|
|
110
|
+
expect(SqlDate.getYear('2020-01-15')).toBe(2020);
|
|
111
|
+
expect(SqlDate.getYear('2030-12-31')).toBe(2030);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('getMonth', () => {
|
|
116
|
+
test('should return month from SQL date', () => {
|
|
117
|
+
const sqlDate = '2024-01-15';
|
|
118
|
+
expect(SqlDate.getMonth(sqlDate)).toBe(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('should return 12 for December', () => {
|
|
122
|
+
const sqlDate = '2024-12-15';
|
|
123
|
+
expect(SqlDate.getMonth(sqlDate)).toBe(12);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('getMonthName', () => {
|
|
128
|
+
test('should return month name from SQL date', () => {
|
|
129
|
+
const sqlDate = '2024-01-15';
|
|
130
|
+
expect(SqlDate.getMonthName(sqlDate, 'fr-FR')).toBe('janvier');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('should return short month name', () => {
|
|
134
|
+
const sqlDate = '2024-01-15';
|
|
135
|
+
const result = SqlDate.getMonthName(sqlDate, 'fr-FR', true);
|
|
136
|
+
expect(result).toContain('janv');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('should work with different months', () => {
|
|
140
|
+
expect(SqlDate.getMonthName('2024-06-15', 'fr-FR')).toBe('juin');
|
|
141
|
+
expect(SqlDate.getMonthName('2024-12-15', 'fr-FR')).toBe('décembre');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('getDay', () => {
|
|
146
|
+
test('should return day from SQL date', () => {
|
|
147
|
+
const sqlDate = '2024-01-15';
|
|
148
|
+
expect(SqlDate.getDay(sqlDate)).toBe(15);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('should work with first day of month', () => {
|
|
152
|
+
const sqlDate = '2024-01-01';
|
|
153
|
+
expect(SqlDate.getDay(sqlDate)).toBe(1);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('should work with last day of month', () => {
|
|
157
|
+
const sqlDate = '2024-01-31';
|
|
158
|
+
expect(SqlDate.getDay(sqlDate)).toBe(31);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('isDateInTheFuture', () => {
|
|
163
|
+
test('should return true for future date', () => {
|
|
164
|
+
const sqlDate = '2030-01-01';
|
|
165
|
+
expect(SqlDate.isDateInTheFuture(sqlDate)).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('should return false for past date', () => {
|
|
169
|
+
const sqlDate = '2020-01-01';
|
|
170
|
+
expect(SqlDate.isDateInTheFuture(sqlDate)).toBe(false);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('getNbDayBetweenTwo', () => {
|
|
175
|
+
test('should calculate days between two SQL dates', () => {
|
|
176
|
+
const sqlDate1 = '2024-01-15';
|
|
177
|
+
const sqlDate2 = '2024-01-20';
|
|
178
|
+
expect(SqlDate.getNbDayBetweenTwo(sqlDate1, sqlDate2, true)).toBe(5);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('should return 0 for same date', () => {
|
|
182
|
+
const sqlDate1 = '2024-01-15';
|
|
183
|
+
const sqlDate2 = '2024-01-15';
|
|
184
|
+
expect(SqlDate.getNbDayBetweenTwo(sqlDate1, sqlDate2, true)).toBe(0);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('should return negative for reversed dates', () => {
|
|
188
|
+
const sqlDate1 = '2024-01-20';
|
|
189
|
+
const sqlDate2 = '2024-01-15';
|
|
190
|
+
expect(SqlDate.getNbDayBetweenTwo(sqlDate1, sqlDate2, true)).toBe(-5);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('should work across months', () => {
|
|
194
|
+
const sqlDate1 = '2024-01-30';
|
|
195
|
+
const sqlDate2 = '2024-02-05';
|
|
196
|
+
expect(SqlDate.getNbDayBetweenTwo(sqlDate1, sqlDate2, true)).toBe(6);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('should work across years', () => {
|
|
200
|
+
const sqlDate1 = '2023-12-30';
|
|
201
|
+
const sqlDate2 = '2024-01-05';
|
|
202
|
+
expect(SqlDate.getNbDayBetweenTwo(sqlDate1, sqlDate2, true)).toBe(6);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
const { SqlDateTime } = require('../../date_time');
|
|
2
|
+
|
|
3
|
+
describe('SqlDateTime', () => {
|
|
4
|
+
describe('parse', () => {
|
|
5
|
+
test('should parse SQL datetime to Date object', () => {
|
|
6
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
7
|
+
const result = SqlDateTime.parse(sqlDateTime);
|
|
8
|
+
expect(result instanceof Date).toBe(true);
|
|
9
|
+
expect(result.getUTCFullYear()).toBe(2024);
|
|
10
|
+
expect(result.getUTCMonth()).toBe(0);
|
|
11
|
+
expect(result.getUTCDate()).toBe(15);
|
|
12
|
+
expect(result.getUTCHours()).toBe(10);
|
|
13
|
+
expect(result.getUTCMinutes()).toBe(30);
|
|
14
|
+
expect(result.getUTCSeconds()).toBe(45);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('should return null for null input', () => {
|
|
18
|
+
expect(SqlDateTime.parse(null)).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('should parse midnight', () => {
|
|
22
|
+
const sqlDateTime = '2024-01-15 00:00:00';
|
|
23
|
+
const result = SqlDateTime.parse(sqlDateTime);
|
|
24
|
+
expect(result.getUTCHours()).toBe(0);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('should parse end of day', () => {
|
|
28
|
+
const sqlDateTime = '2024-01-15 23:59:59';
|
|
29
|
+
const result = SqlDateTime.parse(sqlDateTime);
|
|
30
|
+
expect(result.getUTCHours()).toBe(23);
|
|
31
|
+
expect(result.getUTCMinutes()).toBe(59);
|
|
32
|
+
expect(result.getUTCSeconds()).toBe(59);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('getCurrentSqlDateTime', () => {
|
|
37
|
+
test('should return current datetime in SQL format', () => {
|
|
38
|
+
const result = SqlDateTime.getCurrentSqlDateTime();
|
|
39
|
+
expect(result).toMatch(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('should return current date and time', () => {
|
|
43
|
+
const result = SqlDateTime.getCurrentSqlDateTime();
|
|
44
|
+
const now = new Date();
|
|
45
|
+
const year = now.getFullYear();
|
|
46
|
+
expect(result).toContain(String(year));
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('getSqlDate', () => {
|
|
51
|
+
test('should extract date from SQL datetime', () => {
|
|
52
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
53
|
+
const result = SqlDateTime.getSqlDate(sqlDateTime);
|
|
54
|
+
expect(result).toBe('2024-01-15');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('should return null for null input', () => {
|
|
58
|
+
expect(SqlDateTime.getSqlDate(null)).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('getSqlTime', () => {
|
|
63
|
+
test('should extract time from SQL datetime', () => {
|
|
64
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
65
|
+
const result = SqlDateTime.getSqlTime(sqlDateTime);
|
|
66
|
+
expect(result).toBe('10:30:45');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('should return null for null input', () => {
|
|
70
|
+
expect(SqlDateTime.getSqlTime(null)).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('should handle midnight', () => {
|
|
74
|
+
const sqlDateTime = '2024-01-15 00:00:00';
|
|
75
|
+
const result = SqlDateTime.getSqlTime(sqlDateTime);
|
|
76
|
+
expect(result).toBe('00:00:00');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('getDateDigitalDisplay', () => {
|
|
81
|
+
test('should format date in digital format', () => {
|
|
82
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
83
|
+
const result = SqlDateTime.getDateDigitalDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
84
|
+
expect(result).toContain('15');
|
|
85
|
+
expect(result).toContain('01');
|
|
86
|
+
expect(result).toContain('2024');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('should work with different locales', () => {
|
|
90
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
91
|
+
const resultFr = SqlDateTime.getDateDigitalDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
92
|
+
const resultEn = SqlDateTime.getDateDigitalDisplay(sqlDateTime, 'en-US', 'UTC');
|
|
93
|
+
expect(resultFr).toBeTruthy();
|
|
94
|
+
expect(resultEn).toBeTruthy();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('getDateTextDisplay', () => {
|
|
99
|
+
test('should format date in text format', () => {
|
|
100
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
101
|
+
const result = SqlDateTime.getDateTextDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
102
|
+
expect(typeof result).toBe('string');
|
|
103
|
+
expect(result.length).toBeGreaterThan(10);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('should include month name', () => {
|
|
107
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
108
|
+
const result = SqlDateTime.getDateTextDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
109
|
+
expect(result).toContain('janvier');
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('getTimeDisplay', () => {
|
|
114
|
+
test('should format time for display', () => {
|
|
115
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
116
|
+
const result = SqlDateTime.getTimeDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
117
|
+
expect(result).toContain('10');
|
|
118
|
+
expect(result).toContain('30');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('should format midnight', () => {
|
|
122
|
+
const sqlDateTime = '2024-01-15 00:00:00';
|
|
123
|
+
const result = SqlDateTime.getTimeDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
124
|
+
expect(result).toContain('00');
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('getTimeDisplayWithNbDays', () => {
|
|
129
|
+
test('should display time without days difference', () => {
|
|
130
|
+
const sqlDateTime = '2024-01-15 10:30:00';
|
|
131
|
+
const result = SqlDateTime.getTimeDisplayWithNbDays(sqlDateTime, '2024-01-15 10:30:00', 'fr-FR', 'UTC');
|
|
132
|
+
expect(result).toContain('10');
|
|
133
|
+
expect(result).toContain('30');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('should display time with days difference', () => {
|
|
137
|
+
const sqlDateTime1 = '2024-01-15 10:30:00';
|
|
138
|
+
const sqlDateTime2 = '2024-01-18 14:30:00';
|
|
139
|
+
const result = SqlDateTime.getTimeDisplayWithNbDays(sqlDateTime2, sqlDateTime1, 'fr-FR', 'UTC');
|
|
140
|
+
expect(result).toContain('J+3');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('should not display days when difference is 0', () => {
|
|
144
|
+
const sqlDateTime1 = '2024-01-15 10:30:00';
|
|
145
|
+
const sqlDateTime2 = '2024-01-15 14:30:00';
|
|
146
|
+
const result = SqlDateTime.getTimeDisplayWithNbDays(sqlDateTime2, sqlDateTime1, 'fr-FR', 'UTC');
|
|
147
|
+
expect(result).not.toContain('J+');
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('getTimeDigitalDisplay', () => {
|
|
152
|
+
test('should format time in digital format', () => {
|
|
153
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
154
|
+
const result = SqlDateTime.getTimeDigitalDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
155
|
+
expect(result).toMatch(/\d{2}:\d{2}:\d{2}/);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('getDateTimeDigitalDisplay', () => {
|
|
160
|
+
test('should format datetime in digital format', () => {
|
|
161
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
162
|
+
const result = SqlDateTime.getDateTimeDigitalDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
163
|
+
expect(result).toContain('15');
|
|
164
|
+
expect(result).toContain('10');
|
|
165
|
+
expect(result).toContain('30');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('should include both date and time', () => {
|
|
169
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
170
|
+
const result = SqlDateTime.getDateTimeDigitalDisplay(sqlDateTime, 'fr-FR', 'UTC');
|
|
171
|
+
expect(result).toContain('2024');
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('getDateForInputDate', () => {
|
|
176
|
+
test('should return date in input format', () => {
|
|
177
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
178
|
+
const result = SqlDateTime.getDateForInputDate(sqlDateTime, 'UTC');
|
|
179
|
+
expect(result).toBe('2024-01-15');
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('getTimeForInputTime', () => {
|
|
184
|
+
test('should return time without seconds', () => {
|
|
185
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
186
|
+
const result = SqlDateTime.getTimeForInputTime(sqlDateTime, 'UTC', false);
|
|
187
|
+
expect(result).toMatch(/^\d{2}:\d{2}$/);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('should return time with seconds', () => {
|
|
191
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
192
|
+
const result = SqlDateTime.getTimeForInputTime(sqlDateTime, 'UTC', true);
|
|
193
|
+
expect(result).toMatch(/^\d{2}:\d{2}:\d{2}$/);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('getYear', () => {
|
|
198
|
+
test('should return year from SQL datetime', () => {
|
|
199
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
200
|
+
expect(SqlDateTime.getYear(sqlDateTime)).toBe(2024);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('should work with different years', () => {
|
|
204
|
+
expect(SqlDateTime.getYear('2020-01-15 10:30:45')).toBe(2020);
|
|
205
|
+
expect(SqlDateTime.getYear('2030-12-31 23:59:59')).toBe(2030);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('getMonth', () => {
|
|
210
|
+
test('should return month from SQL datetime', () => {
|
|
211
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
212
|
+
expect(SqlDateTime.getMonth(sqlDateTime)).toBe(1);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('should return 12 for December', () => {
|
|
216
|
+
const sqlDateTime = '2024-12-15 10:30:45';
|
|
217
|
+
expect(SqlDateTime.getMonth(sqlDateTime)).toBe(12);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe('getMonthName', () => {
|
|
222
|
+
test('should return month name from SQL datetime', () => {
|
|
223
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
224
|
+
expect(SqlDateTime.getMonthName(sqlDateTime, 'fr-FR')).toBe('janvier');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('should work with different months', () => {
|
|
228
|
+
expect(SqlDateTime.getMonthName('2024-06-15 10:30:45', 'fr-FR')).toBe('juin');
|
|
229
|
+
expect(SqlDateTime.getMonthName('2024-12-15 10:30:45', 'fr-FR')).toBe('décembre');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('should work with English locale', () => {
|
|
233
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
234
|
+
expect(SqlDateTime.getMonthName(sqlDateTime, 'en-US')).toBe('January');
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe('getDay', () => {
|
|
239
|
+
test('should return day from SQL datetime', () => {
|
|
240
|
+
const sqlDateTime = '2024-01-15 10:30:45';
|
|
241
|
+
expect(SqlDateTime.getDay(sqlDateTime)).toBe(15);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('should work with first day of month', () => {
|
|
245
|
+
const sqlDateTime = '2024-01-01 10:30:45';
|
|
246
|
+
expect(SqlDateTime.getDay(sqlDateTime)).toBe(1);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('should work with last day of month', () => {
|
|
250
|
+
const sqlDateTime = '2024-01-31 10:30:45';
|
|
251
|
+
expect(SqlDateTime.getDay(sqlDateTime)).toBe(31);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe('getTimestamp', () => {
|
|
256
|
+
test('should convert SQL datetime to Unix timestamp', () => {
|
|
257
|
+
const sqlDateTime = '2024-01-15 10:30:00';
|
|
258
|
+
const result = SqlDateTime.getTimestamp(sqlDateTime);
|
|
259
|
+
expect(typeof result).toBe('number');
|
|
260
|
+
expect(result).toBeGreaterThan(0);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('should return consistent timestamp', () => {
|
|
264
|
+
const sqlDateTime = '2024-01-15 10:30:00';
|
|
265
|
+
const result1 = SqlDateTime.getTimestamp(sqlDateTime);
|
|
266
|
+
const result2 = SqlDateTime.getTimestamp(sqlDateTime);
|
|
267
|
+
expect(result1).toBe(result2);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('isDateInTheFuture', () => {
|
|
272
|
+
test('should return true for future date', () => {
|
|
273
|
+
const sqlDateTime = '2030-01-01 10:30:00';
|
|
274
|
+
expect(SqlDateTime.isDateInTheFuture(sqlDateTime)).toBe(true);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test('should return false for past date', () => {
|
|
278
|
+
const sqlDateTime = '2020-01-01 10:30:00';
|
|
279
|
+
expect(SqlDateTime.isDateInTheFuture(sqlDateTime)).toBe(false);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
describe('isDateTimeInTheFuture', () => {
|
|
284
|
+
test('should return true for future datetime', () => {
|
|
285
|
+
const sqlDateTime = '2030-01-01 10:30:00';
|
|
286
|
+
expect(SqlDateTime.isDateTimeInTheFuture(sqlDateTime)).toBe(true);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('should return false for past datetime', () => {
|
|
290
|
+
const sqlDateTime = '2020-01-01 10:30:00';
|
|
291
|
+
expect(SqlDateTime.isDateTimeInTheFuture(sqlDateTime)).toBe(false);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
describe('getNbDayBetweenTwo', () => {
|
|
296
|
+
test('should calculate days between two SQL datetimes', () => {
|
|
297
|
+
const sqlDateTime1 = '2024-01-15 10:30:00';
|
|
298
|
+
const sqlDateTime2 = '2024-01-20 14:45:00';
|
|
299
|
+
expect(SqlDateTime.getNbDayBetweenTwo(sqlDateTime1, sqlDateTime2, true)).toBe(5);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test('should return 0 for same day', () => {
|
|
303
|
+
const sqlDateTime1 = '2024-01-15 10:30:00';
|
|
304
|
+
const sqlDateTime2 = '2024-01-15 14:45:00';
|
|
305
|
+
expect(SqlDateTime.getNbDayBetweenTwo(sqlDateTime1, sqlDateTime2, false)).toBe(0);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test('should return negative for reversed dates', () => {
|
|
309
|
+
const sqlDateTime1 = '2024-01-20 10:30:00';
|
|
310
|
+
const sqlDateTime2 = '2024-01-15 14:45:00';
|
|
311
|
+
expect(SqlDateTime.getNbDayBetweenTwo(sqlDateTime1, sqlDateTime2, true)).toBe(-5);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test('should work across months', () => {
|
|
315
|
+
const sqlDateTime1 = '2024-01-30 10:00:00';
|
|
316
|
+
const sqlDateTime2 = '2024-02-05 14:00:00';
|
|
317
|
+
expect(SqlDateTime.getNbDayBetweenTwo(sqlDateTime1, sqlDateTime2, true)).toBe(6);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test('should work across years', () => {
|
|
321
|
+
const sqlDateTime1 = '2023-12-30 10:00:00';
|
|
322
|
+
const sqlDateTime2 = '2024-01-05 14:00:00';
|
|
323
|
+
expect(SqlDateTime.getNbDayBetweenTwo(sqlDateTime1, sqlDateTime2, true)).toBe(6);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
const { SqlTime } = require('../../date_time');
|
|
2
|
+
|
|
3
|
+
describe('SqlTime', () => {
|
|
4
|
+
describe('parse', () => {
|
|
5
|
+
test('should parse SQL time with seconds to Date object', () => {
|
|
6
|
+
const sqlTime = '10:30:45';
|
|
7
|
+
const result = SqlTime.parse(sqlTime);
|
|
8
|
+
expect(result instanceof Date).toBe(true);
|
|
9
|
+
expect(result.getUTCHours()).toBe(10);
|
|
10
|
+
expect(result.getUTCMinutes()).toBe(30);
|
|
11
|
+
expect(result.getUTCSeconds()).toBe(45);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should parse SQL time without seconds', () => {
|
|
15
|
+
const sqlTime = '10:30';
|
|
16
|
+
const result = SqlTime.parse(sqlTime);
|
|
17
|
+
expect(result instanceof Date).toBe(true);
|
|
18
|
+
expect(result.getUTCHours()).toBe(10);
|
|
19
|
+
expect(result.getUTCMinutes()).toBe(30);
|
|
20
|
+
expect(result.getUTCSeconds()).toBe(0);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('should return null for null input', () => {
|
|
24
|
+
expect(SqlTime.parse(null)).toBeNull();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('should parse midnight', () => {
|
|
28
|
+
const sqlTime = '00:00:00';
|
|
29
|
+
const result = SqlTime.parse(sqlTime);
|
|
30
|
+
expect(result.getUTCHours()).toBe(0);
|
|
31
|
+
expect(result.getUTCMinutes()).toBe(0);
|
|
32
|
+
expect(result.getUTCSeconds()).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should parse noon', () => {
|
|
36
|
+
const sqlTime = '12:00:00';
|
|
37
|
+
const result = SqlTime.parse(sqlTime);
|
|
38
|
+
expect(result.getUTCHours()).toBe(12);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should parse end of day', () => {
|
|
42
|
+
const sqlTime = '23:59:59';
|
|
43
|
+
const result = SqlTime.parse(sqlTime);
|
|
44
|
+
expect(result.getUTCHours()).toBe(23);
|
|
45
|
+
expect(result.getUTCMinutes()).toBe(59);
|
|
46
|
+
expect(result.getUTCSeconds()).toBe(59);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('getCurrentSqlTime', () => {
|
|
51
|
+
test('should return current time in SQL format', () => {
|
|
52
|
+
const result = SqlTime.getCurrentSqlTime();
|
|
53
|
+
expect(result).toMatch(/^\d{2}:\d{2}:\d{2}$/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should return time within valid range', () => {
|
|
57
|
+
const result = SqlTime.getCurrentSqlTime();
|
|
58
|
+
const parts = result.split(':');
|
|
59
|
+
const hours = parseInt(parts[0]);
|
|
60
|
+
const minutes = parseInt(parts[1]);
|
|
61
|
+
const seconds = parseInt(parts[2]);
|
|
62
|
+
|
|
63
|
+
expect(hours).toBeGreaterThanOrEqual(0);
|
|
64
|
+
expect(hours).toBeLessThanOrEqual(23);
|
|
65
|
+
expect(minutes).toBeGreaterThanOrEqual(0);
|
|
66
|
+
expect(minutes).toBeLessThanOrEqual(59);
|
|
67
|
+
expect(seconds).toBeGreaterThanOrEqual(0);
|
|
68
|
+
expect(seconds).toBeLessThanOrEqual(59);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('getTimeDisplay', () => {
|
|
73
|
+
test('should format SQL time for display', () => {
|
|
74
|
+
const sqlTime = '10:30:45';
|
|
75
|
+
const result = SqlTime.getTimeDisplay(sqlTime, 'fr-FR', 'UTC');
|
|
76
|
+
expect(result).toContain('10');
|
|
77
|
+
expect(result).toContain('30');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('should format midnight', () => {
|
|
81
|
+
const sqlTime = '00:00:00';
|
|
82
|
+
const result = SqlTime.getTimeDisplay(sqlTime, 'fr-FR', 'UTC');
|
|
83
|
+
expect(result).toContain('00');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('getTimeDigitalDisplay', () => {
|
|
88
|
+
test('should format SQL time in digital format', () => {
|
|
89
|
+
const sqlTime = '10:30:45';
|
|
90
|
+
const result = SqlTime.getTimeDigitalDisplay(sqlTime, 'fr-FR', 'UTC');
|
|
91
|
+
expect(result).toMatch(/\d{2}:\d{2}:\d{2}/);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('should format time without seconds', () => {
|
|
95
|
+
const sqlTime = '10:30';
|
|
96
|
+
const result = SqlTime.getTimeDigitalDisplay(sqlTime, 'fr-FR', 'UTC');
|
|
97
|
+
expect(result).toMatch(/\d{2}:\d{2}:\d{2}/);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('getTimeDisplayWithNbDays', () => {
|
|
102
|
+
test('should display time without days difference', () => {
|
|
103
|
+
const sqlTime = '10:30:00';
|
|
104
|
+
const result = SqlTime.getTimeDisplayWithNbDays(sqlTime, '10:30:00', 'fr-FR', 'UTC');
|
|
105
|
+
expect(result).toContain('10');
|
|
106
|
+
expect(result).toContain('30');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('should not show days for same time', () => {
|
|
110
|
+
const sqlTime = '10:30:00';
|
|
111
|
+
const result = SqlTime.getTimeDisplayWithNbDays(sqlTime, '10:30:00', 'fr-FR', 'UTC');
|
|
112
|
+
expect(result).not.toContain('J+');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('getTimeForInputTime', () => {
|
|
117
|
+
test('should return time for input field without seconds', () => {
|
|
118
|
+
const sqlTime = '10:30:45';
|
|
119
|
+
const result = SqlTime.getTimeForInputTime(sqlTime, 'UTC', false);
|
|
120
|
+
expect(result).toMatch(/^\d{2}:\d{2}$/);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('should return time for input field with seconds', () => {
|
|
124
|
+
const sqlTime = '10:30:45';
|
|
125
|
+
const result = SqlTime.getTimeForInputTime(sqlTime, 'UTC', true);
|
|
126
|
+
expect(result).toMatch(/^\d{2}:\d{2}:\d{2}$/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('should handle time without seconds', () => {
|
|
130
|
+
const sqlTime = '10:30';
|
|
131
|
+
const result = SqlTime.getTimeForInputTime(sqlTime, 'UTC', true);
|
|
132
|
+
expect(result).toMatch(/^\d{2}:\d{2}:\d{2}$/);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('getTimestamp', () => {
|
|
137
|
+
test('should convert SQL time to timestamp', () => {
|
|
138
|
+
const sqlTime = '10:30:45';
|
|
139
|
+
const result = SqlTime.getTimestamp(sqlTime);
|
|
140
|
+
expect(typeof result).toBe('number');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('should return consistent timestamp', () => {
|
|
144
|
+
const sqlTime = '10:30:45';
|
|
145
|
+
const result1 = SqlTime.getTimestamp(sqlTime);
|
|
146
|
+
const result2 = SqlTime.getTimestamp(sqlTime);
|
|
147
|
+
expect(result1).toBe(result2);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('should handle midnight', () => {
|
|
151
|
+
const sqlTime = '00:00:00';
|
|
152
|
+
const result = SqlTime.getTimestamp(sqlTime);
|
|
153
|
+
expect(typeof result).toBe('number');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('should handle time without seconds', () => {
|
|
157
|
+
const sqlTime = '10:30';
|
|
158
|
+
const result = SqlTime.getTimestamp(sqlTime);
|
|
159
|
+
expect(typeof result).toBe('number');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|