@osimatic/helpers-js 1.1.77 → 1.1.78
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/CHANGELOG +76 -76
- package/array.js +93 -90
- package/bank.js +20 -20
- package/contact_details.js +194 -194
- package/count_down.js +102 -102
- package/data_table.js +416 -416
- package/date_time.js +592 -592
- package/details_sub_array.js +123 -123
- package/draw.js +52 -52
- package/duration.js +198 -198
- package/event_bus.js +38 -38
- package/file.js +146 -146
- package/flash_message.js +35 -35
- package/form_date.js +610 -610
- package/form_helper.js +410 -410
- package/google_charts.js +347 -347
- package/google_maps.js +169 -169
- package/google_recaptcha.js +87 -87
- package/http_client.js +469 -469
- package/import_from_csv.js +273 -273
- package/index.js +55 -55
- package/jwt.js +288 -288
- package/list_box.js +112 -112
- package/location.js +431 -431
- package/media.js +218 -218
- package/multiple_action_in_table.js +336 -336
- package/network.js +756 -756
- package/number.js +99 -99
- package/open_street_map.js +142 -142
- package/package.json +15 -15
- package/paging.js +278 -278
- package/php.min.js +5 -5
- package/revolut.js +22 -22
- package/select_all.js +121 -121
- package/shopping_cart.js +31 -31
- package/social_network.js +109 -109
- package/sortable_list.js +37 -37
- package/string.js +162 -162
- package/util.js +16 -16
- package/visitor.js +77 -77
- package/web_rtc.js +114 -114
- package/web_socket.js +97 -97
package/date_time.js
CHANGED
|
@@ -1,593 +1,593 @@
|
|
|
1
|
-
|
|
2
|
-
class DateTimeFormatter {
|
|
3
|
-
static getDateDigitalFormatter(locale, timeZone) {
|
|
4
|
-
this.dateDigitalFormatter = this.dateDigitalFormatter || {};
|
|
5
|
-
if (typeof this.dateDigitalFormatter[timeZone+locale] == 'undefined') {
|
|
6
|
-
this.dateDigitalFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone });
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return this.dateDigitalFormatter[timeZone+locale];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static getDateTextFormatter(locale, timeZone) {
|
|
13
|
-
this.dateTextFormatter = this.dateTextFormatter || {};
|
|
14
|
-
if (typeof this.dateTextFormatter[timeZone+locale] == 'undefined') {
|
|
15
|
-
this.dateTextFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return this.dateTextFormatter[timeZone+locale];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static getDateTimeFormatter(locale, timeZone) {
|
|
22
|
-
this.dateTimeFormatter = this.dateTimeFormatter || {};
|
|
23
|
-
if (typeof this.dateTimeFormatter[timeZone+locale] == 'undefined') {
|
|
24
|
-
this.dateTimeFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return this.dateTimeFormatter[timeZone+locale];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static getDateSqlFormatter(timeZone) {
|
|
31
|
-
this.dateSqlFormatter = this.dateSqlFormatter || {};
|
|
32
|
-
if (typeof this.dateSqlFormatter[timeZone] == 'undefined') {
|
|
33
|
-
this.dateSqlFormatter[timeZone] = new Intl.DateTimeFormat('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: timeZone });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return this.dateSqlFormatter[timeZone];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static getTimeSqlFormatter(timeZone) {
|
|
40
|
-
this.timeSqlFormatter = this.timeSqlFormatter || {};
|
|
41
|
-
if (typeof this.timeSqlFormatter[timeZone] == 'undefined') {
|
|
42
|
-
//console.log('init getTimeSqlFormatter avec timezone', timeZone);
|
|
43
|
-
this.timeSqlFormatter[timeZone] = new Intl.DateTimeFormat('en-GB', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: timeZone }); //hour12: false = 24h format
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return this.timeSqlFormatter[timeZone];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static getTimeFormatter(locale, timeZone) {
|
|
50
|
-
this.timeFormatter = this.timeFormatter || {};
|
|
51
|
-
if (typeof this.timeFormatter[timeZone+locale] == 'undefined') {
|
|
52
|
-
this.timeFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: 'numeric', timeZone: timeZone });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return this.timeFormatter[timeZone+locale];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static getTimeDigitalFormatter(locale, timeZone) {
|
|
59
|
-
this.timeDigitalFormatter = this.timeDigitalFormatter || {};
|
|
60
|
-
if (typeof this.timeDigitalFormatter[timeZone+locale] == 'undefined') {
|
|
61
|
-
this.timeDigitalFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return this.timeDigitalFormatter[timeZone+locale];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
class DateTime {
|
|
69
|
-
static getSqlDate(jsDate, timeZone="Europe/Paris") {
|
|
70
|
-
return DateTimeFormatter.getDateSqlFormatter(timeZone).format(jsDate).replace(/\//g,'-').replace(',','');
|
|
71
|
-
/*let pad = function(num) { return ('00'+num).slice(-2) };
|
|
72
|
-
// return jsDate.getUTCFullYear() + '-' + pad(jsDate.getUTCMonth() + 1) + '-' + pad(jsDate.getUTCDate());
|
|
73
|
-
//return jsDate.getFullYear() + '-' + pad(jsDate.getMonth() + 1) + '-' + pad(jsDate.getDate());
|
|
74
|
-
return jsDate.toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {month: '2-digit', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {day: '2-digit', timeZone: timeZone});
|
|
75
|
-
*/
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
static getSqlTime(jsDate, timeZone="Europe/Paris") {
|
|
79
|
-
return DateTimeFormatter.getTimeSqlFormatter(timeZone).format(jsDate);
|
|
80
|
-
/*let pad = function(num) { return ('00'+num).slice(-2) };
|
|
81
|
-
// return pad(jsDate.getUTCHours()) + ':' + pad(jsDate.getUTCMinutes()) + ':' + pad(jsDate.getUTCSeconds());
|
|
82
|
-
//return pad(jsDate.getHours()) + ':' + pad(jsDate.getMinutes()) + ':' + pad(jsDate.getSeconds());
|
|
83
|
-
return pad(jsDate.toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone}));
|
|
84
|
-
*/
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static getSqlDateTime(jsDate, timeZone="Europe/Paris") {
|
|
88
|
-
return this.getSqlDate(jsDate, timeZone)+' '+this.getSqlTime(jsDate, timeZone);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
static getDateForInputDate(jsDate, timeZone="Europe/Paris") {
|
|
92
|
-
return this.getSqlDate(jsDate, timeZone);
|
|
93
|
-
}
|
|
94
|
-
static getTimeForInputTime(jsDate, timeZone="Europe/Paris", withSeconds=false) {
|
|
95
|
-
return jsDate.toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone, hour12: false}).padStart(2, '0')+':'+jsDate.toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone, hour12: false}).padStart(2, '0')+(withSeconds?':'+jsDate.toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone, hour12: false}).padStart(2, '0'):'');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
static getTimestamp(jsDate) {
|
|
99
|
-
return Math.trunc(jsDate.getTime()/1000);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
static getDateDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
103
|
-
return DateTimeFormatter.getDateDigitalFormatter(locale, timeZone).format(jsDate);
|
|
104
|
-
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
static getDateTextDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
108
|
-
return DateTimeFormatter.getDateTextFormatter(locale, timeZone).format(jsDate);
|
|
109
|
-
//return jsDate.toLocaleDateString(locale, {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static getTimeDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
113
|
-
return DateTimeFormatter.getTimeFormatter(locale, timeZone).format(jsDate);
|
|
114
|
-
//return jsDate.toLocaleTimeString(locale, {hour: 'numeric', minute: 'numeric', timeZone: timeZone});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
static getTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
118
|
-
return DateTimeFormatter.getTimeDigitalFormatter(locale, timeZone).format(jsDate);
|
|
119
|
-
//return jsDate.toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
static getTimeDisplayWithNbDays(jsDate, jsPreviousDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
123
|
-
let str = this.getTimeDisplay(jsDate, locale, timeZone);
|
|
124
|
-
if (jsPreviousDate != 0 && jsPreviousDate != null) {
|
|
125
|
-
let nbDaysDiff = this.getNbDayBetweenTwo(jsPreviousDate, jsDate, false);
|
|
126
|
-
if (nbDaysDiff > 0) {
|
|
127
|
-
str += ' (J+'+nbDaysDiff+')';
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return str;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
static getDateTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
134
|
-
return DateTimeFormatter.getDateTimeFormatter(locale, timeZone).format(jsDate);
|
|
135
|
-
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
static getYear(jsDate) {
|
|
139
|
-
return jsDate.getUTCFullYear();
|
|
140
|
-
}
|
|
141
|
-
static getMonth(jsDate) {
|
|
142
|
-
return jsDate.getUTCMonth()+1;
|
|
143
|
-
}
|
|
144
|
-
static getMonthName(jsDate, locale="fr-FR", isShort=false) {
|
|
145
|
-
return jsDate.toLocaleDateString(locale, {month: (isShort?'short':'long')});
|
|
146
|
-
}
|
|
147
|
-
static getDay(jsDate) {
|
|
148
|
-
return jsDate.getUTCDate();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
static getDayOfMonth(jsDate) {
|
|
152
|
-
return jsDate.getUTCDate();
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
static getDayOfWeek(jsDate) {
|
|
156
|
-
return jsDate.getUTCDay();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
static getDayName(jsDate, locale="fr-FR", isShort=false) {
|
|
160
|
-
return jsDate.toLocaleDateString(locale, {weekday: (isShort?'short':'long')});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
static getNbDaysInMonth(year, month) {
|
|
164
|
-
return new Date(Date.UTC(year, month, 0)).getDate();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
static getMonthNameByMonth(month, locale="fr-FR", isShort=false) {
|
|
168
|
-
let d = new Date();
|
|
169
|
-
d.setDate(1);
|
|
170
|
-
d.setMonth(month-1);
|
|
171
|
-
return this.getMonthName(d, locale, isShort);
|
|
172
|
-
}
|
|
173
|
-
static getDayNameByDayOfWeek(dayOfWeek, locale="fr-FR", isShort=false) {
|
|
174
|
-
let d = new Date();
|
|
175
|
-
// d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
|
|
176
|
-
d.setDate(d.getDate() + (dayOfWeek - d.getDay()) % 7);
|
|
177
|
-
return this.getDayName(d, locale, isShort);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
static getFirstDayOfWeek(date) {
|
|
182
|
-
let firstDayOfWeek = new Date(date);
|
|
183
|
-
const day = date.getUTCDay();
|
|
184
|
-
firstDayOfWeek.setUTCDate(date.getUTCDate() - day + (0 === day ? -6:1)); // First day is the day of the month - the day of the week
|
|
185
|
-
return firstDayOfWeek;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
static getLastDayOfWeek(date) {
|
|
189
|
-
let lastDayOfWeek = this.getFirstDayOfWeek(date);
|
|
190
|
-
lastDayOfWeek.setUTCDate(lastDayOfWeek.getUTCDate() + 6); // last day is the first day + 6
|
|
191
|
-
return lastDayOfWeek;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
static getFirstDayOfMonth(date) {
|
|
195
|
-
return this.getFirstDayOfMonthAndYear(date.getUTCFullYear(), date.getUTCMonth()+1);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
static getLastDayOfMonth(date) {
|
|
199
|
-
return this.getLastDayOfMonthAndYear(date.getUTCFullYear(), date.getUTCMonth()+1);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
static getFirstDayOfYear(date) {
|
|
203
|
-
date.setUTCDate(1);
|
|
204
|
-
date.setUTCMonth(0);
|
|
205
|
-
return new Date(date);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
static getLastDayOfYear(date) {
|
|
209
|
-
date.setUTCDate(31);
|
|
210
|
-
date.setUTCMonth(11);
|
|
211
|
-
return new Date(date);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
static getFirstDayOfWeekAndYear(year, week) {
|
|
215
|
-
let simple = new Date(Date.UTC(year, 0, 1 + (week - 1) * 7));
|
|
216
|
-
let dow = simple.getDay();
|
|
217
|
-
let ISOweekStart = simple;
|
|
218
|
-
if (dow <= 4) {
|
|
219
|
-
ISOweekStart.setUTCDate(simple.getUTCDate() - simple.getUTCDay() + 1);
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
ISOweekStart.setUTCDate(simple.getUTCDate() + 8 - simple.getUTCDay());
|
|
223
|
-
}
|
|
224
|
-
return ISOweekStart;
|
|
225
|
-
}
|
|
226
|
-
static getLastDayOfWeekAndYear(year, week) {
|
|
227
|
-
let firstDayOfWeek = this.getFirstDayOfWeekAndYear(year, week);
|
|
228
|
-
firstDayOfWeek.setUTCDate(firstDayOfWeek.getUTCDate()+6);
|
|
229
|
-
return firstDayOfWeek;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
static getFirstDayOfMonthAndYear(year, month) {
|
|
233
|
-
return new Date(Date.UTC(year, month-1, 1));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
static getLastDayOfMonthAndYear(year, month) {
|
|
237
|
-
return new Date(Date.UTC(year, month, 0));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
static isDateEqual(jsDate1, jsDate2) {
|
|
241
|
-
return (jsDate1.getFullYear() == jsDate2.getFullYear() && jsDate1.getMonth() == jsDate2.getMonth() && jsDate1.getDate() == jsDate2.getDate());
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
static isDateInThePast(jsDate) {
|
|
245
|
-
jsDate.setHours(0);
|
|
246
|
-
jsDate.setMinutes(0);
|
|
247
|
-
jsDate.setSeconds(0);
|
|
248
|
-
jsDate.setMilliseconds(0);
|
|
249
|
-
let today = new Date();
|
|
250
|
-
today.setHours(0);
|
|
251
|
-
today.setMinutes(0);
|
|
252
|
-
today.setSeconds(0);
|
|
253
|
-
today.setMilliseconds(0);
|
|
254
|
-
return jsDate.getTime() < today.getTime();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
static isDateInTheFuture(jsDate) {
|
|
258
|
-
jsDate.setHours(0);
|
|
259
|
-
jsDate.setMinutes(0);
|
|
260
|
-
jsDate.setSeconds(0);
|
|
261
|
-
jsDate.setMilliseconds(0);
|
|
262
|
-
let today = new Date();
|
|
263
|
-
today.setHours(0);
|
|
264
|
-
today.setMinutes(0);
|
|
265
|
-
today.setSeconds(0);
|
|
266
|
-
today.setMilliseconds(0);
|
|
267
|
-
return jsDate.getTime() > today.getTime();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
static isDateTimeInThePast(jsDateTime) {
|
|
271
|
-
let today = new Date();
|
|
272
|
-
return jsDateTime < today;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
static isDateTimeInTheFuture(jsDateTime) {
|
|
276
|
-
let today = new Date();
|
|
277
|
-
return jsDateTime > today;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
static getNbDayBetweenTwo(jsDate1, jsDate2, asPeriod=false, timeZone="Europe/Paris") {
|
|
281
|
-
//jsDate1.set
|
|
282
|
-
if (jsDate1 == null || jsDate2 == null) {
|
|
283
|
-
return 0;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
let timestamp1 = jsDate1.getTime() / 1000;
|
|
287
|
-
let timestamp2 = jsDate2.getTime() / 1000;
|
|
288
|
-
|
|
289
|
-
if (!asPeriod) {
|
|
290
|
-
let jsMidnightDate1 = new Date(jsDate1.toLocaleDateString('en-US', {timeZone: timeZone})+' 00:00:00');
|
|
291
|
-
let jsMidnightDate2 = new Date(jsDate2.toLocaleDateString('en-US', {timeZone: timeZone})+' 00:00:00');
|
|
292
|
-
timestamp1 = jsMidnightDate1.getTime() / 1000;
|
|
293
|
-
timestamp2 = jsMidnightDate2.getTime() / 1000;
|
|
294
|
-
//jsDate1.setHours(0, 0, 0);
|
|
295
|
-
//jsDate2.setHours(0, 0, 0);
|
|
296
|
-
//jsDate1.setUTCHours(0, 0, 0);
|
|
297
|
-
//jsDate2.setUTCHours(0, 0, 0);
|
|
298
|
-
}
|
|
299
|
-
return parseInt(Math.round((timestamp2-timestamp1)/86400));
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
static addDays(date, days) {
|
|
303
|
-
date.setUTCDate(date.getUTCDate() + days);
|
|
304
|
-
return date;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
static addMonths(date, months) {
|
|
308
|
-
let d = date.getDate();
|
|
309
|
-
date.setMonth(date.getMonth() + +months);
|
|
310
|
-
if (date.getDate() !== d) {
|
|
311
|
-
date.setDate(0);
|
|
312
|
-
}
|
|
313
|
-
return date;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
class TimestampUnix {
|
|
318
|
-
static parse(timestamp) {
|
|
319
|
-
if (timestamp == null) {
|
|
320
|
-
return null;
|
|
321
|
-
}
|
|
322
|
-
return new Date(parseInt(timestamp+'000'));
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
static getCurrent() {
|
|
326
|
-
let today = new Date();
|
|
327
|
-
return parseInt(today.getTime() / 1000);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
static getDateDigitalDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
331
|
-
return DateTime.getDateDigitalDisplay(this.parse(timestamp), locale, timeZone);
|
|
332
|
-
}
|
|
333
|
-
static getDateTextDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
334
|
-
return DateTime.getDateTextDisplay(this.parse(timestamp), locale, timeZone);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
static getTimeDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
338
|
-
return DateTime.getTimeDisplay(this.parse(timestamp), locale, timeZone);
|
|
339
|
-
}
|
|
340
|
-
static getTimeDisplayWithNbDays(timestamp, previousTimestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
341
|
-
return DateTime.getTimeDisplayWithNbDays(this.parse(timestamp), this.parse(previousTimestamp), locale, timeZone);
|
|
342
|
-
}
|
|
343
|
-
static getTimeDigitalDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
344
|
-
return DateTime.getTimeDigitalDisplay(this.parse(timestamp), locale, timeZone);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
static getYear(timestamp, timeZone="Europe/Paris") {
|
|
348
|
-
return this.parse(timestamp).toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone});
|
|
349
|
-
}
|
|
350
|
-
static getMonth(timestamp, timeZone="Europe/Paris") {
|
|
351
|
-
return this.parse(timestamp).toLocaleDateString('fr-FR', {month: 'numeric', timeZone: timeZone});
|
|
352
|
-
}
|
|
353
|
-
static getDayOfMonth(timestamp, timeZone="Europe/Paris") {
|
|
354
|
-
return this.parse(timestamp).toLocaleDateString('fr-FR', {day: 'numeric', timeZone: timeZone});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
static getHour(timestamp, timeZone="Europe/Paris") {
|
|
358
|
-
return this.parse(timestamp).toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone});
|
|
359
|
-
}
|
|
360
|
-
static getMinute(timestamp, timeZone="Europe/Paris") {
|
|
361
|
-
return this.parse(timestamp).toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone});
|
|
362
|
-
}
|
|
363
|
-
static getSecond(timestamp, timeZone="Europe/Paris") {
|
|
364
|
-
return this.parse(timestamp).toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
static getSqlDateTime(timestamp, timeZone="Europe/Paris") {
|
|
368
|
-
return this.getSqlDate(timestamp, timeZone)+' '+this.getSqlTime(timestamp, timeZone);
|
|
369
|
-
}
|
|
370
|
-
static getSqlDate(timestamp, timeZone="Europe/Paris") {
|
|
371
|
-
return DateTime.getSqlDate(this.parse(timestamp), timeZone);
|
|
372
|
-
}
|
|
373
|
-
static getSqlTime(timestamp, timeZone="Europe/Paris") {
|
|
374
|
-
return DateTime.getSqlTime(this.parse(timestamp), timeZone);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
static getDateForInputDate(timestamp, timeZone="Europe/Paris") {
|
|
378
|
-
return DateTime.getDateForInputDate(this.parse(timestamp), timeZone);
|
|
379
|
-
}
|
|
380
|
-
static getTimeForInputTime(timestamp, timeZone="Europe/Paris", withSeconds=false) {
|
|
381
|
-
return DateTime.getTimeForInputTime(this.parse(timestamp), timeZone, withSeconds);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
static isDateEqual(timestamp1, timestamp2) {
|
|
385
|
-
return DateTime.isDateEqual(this.parse(timestamp1), this.parse(timestamp2));
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
static getNbDayBetweenTwo(timestamp1, timestamp2, asPeriod=false, timeZone="Europe/Paris") {
|
|
389
|
-
return DateTime.getNbDayBetweenTwo(this.parse(timestamp1), this.parse(timestamp2), asPeriod, timeZone);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
static isDateInThePast(timestamp) {
|
|
393
|
-
return DateTime.isDateInThePast(this.parse(timestamp));
|
|
394
|
-
}
|
|
395
|
-
static isDateTimeInThePast(timestamp) {
|
|
396
|
-
return DateTime.isDateTimeInThePast(this.parse(timestamp));
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
static isDateInTheFuture(timestamp) {
|
|
400
|
-
return DateTime.isDateInTheFuture(this.parse(timestamp));
|
|
401
|
-
}
|
|
402
|
-
static isDateTimeInTheFuture(timestamp) {
|
|
403
|
-
return DateTime.isDateTimeInTheFuture(this.parse(timestamp));
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Les dates SQL fournies en paramètre doivent être en UTC.
|
|
410
|
-
*/
|
|
411
|
-
class SqlDate {
|
|
412
|
-
static parse(sqlDate) {
|
|
413
|
-
if (sqlDate == null) {
|
|
414
|
-
return null;
|
|
415
|
-
}
|
|
416
|
-
return new Date(Date.UTC(sqlDate.substring(0, 4), sqlDate.substring(5, 7)-1, sqlDate.substring(8, 10), 0, 0, 0));
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
static getCurrentSqlDate() {
|
|
420
|
-
return DateTime.getSqlDate(new Date());
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
static getDateDigitalDisplay(sqlDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
424
|
-
return SqlDateTime.getDateDigitalDisplay(sqlDate+" 00:00:00", locale, timeZone);
|
|
425
|
-
}
|
|
426
|
-
static getDateTextDisplay(sqlDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
427
|
-
return SqlDateTime.getDateTextDisplay(sqlDate+" 00:00:00", locale, timeZone);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
static getDateForInputDate(sqlDate, timeZone="Europe/Paris") {
|
|
431
|
-
return SqlDateTime.getDateForInputDate(sqlDate+" 00:00:00", timeZone);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
static getTimestamp(sqlDate) {
|
|
435
|
-
return SqlDateTime.getTimestamp(sqlDate+" 00:00:00");
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
static getYear(sqlDate) {
|
|
439
|
-
return SqlDateTime.getYear(sqlDate+" 00:00:00");
|
|
440
|
-
}
|
|
441
|
-
static getMonth(sqlDate) {
|
|
442
|
-
return SqlDateTime.getMonth(sqlDate+" 00:00:00");
|
|
443
|
-
}
|
|
444
|
-
static getMonthName(sqlDate, locale="fr-FR", isShort=false) {
|
|
445
|
-
return SqlDateTime.getMonthName(sqlDate+" 00:00:00", locale, isShort);
|
|
446
|
-
}
|
|
447
|
-
static getDay(sqlDate) {
|
|
448
|
-
return SqlDateTime.getDay(sqlDate+" 00:00:00");
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
static isDateInTheFuture(sqlDate) {
|
|
452
|
-
return DateTime.isDateInTheFuture(SqlDateTime.parse(sqlDate + " 00:00:00"));
|
|
453
|
-
}
|
|
454
|
-
static getNbDayBetweenTwo(sqlDate1, sqlDate2, asPeriod=false) {
|
|
455
|
-
return DateTime.getNbDayBetweenTwo(SqlDateTime.parse(sqlDate1 + " 00:00:00"), SqlDateTime.parse(sqlDate2 + " 00:00:00"), asPeriod);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Les heures SQL fournies en paramètre doivent être en UTC.
|
|
461
|
-
*/
|
|
462
|
-
class SqlTime {
|
|
463
|
-
static parse(sqlTime) {
|
|
464
|
-
if (sqlTime == null) {
|
|
465
|
-
return null;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
if ((sqlTime.match(/\:/g) || []).length == 1) {
|
|
469
|
-
sqlTime += ':00';
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
let arrayTime = sqlTime.split(':');
|
|
473
|
-
return new Date(Date.UTC(1970, 0, 1, arrayTime[0], arrayTime[1], arrayTime[2]));
|
|
474
|
-
|
|
475
|
-
/*let jsDate = new Date();
|
|
476
|
-
jsDate.setUTCFullYear(1970, 0, 1);
|
|
477
|
-
jsDate.setUTCHours(arrayTime[0], arrayTime[1], arrayTime[2], 0);
|
|
478
|
-
return jsDate;*/
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
static getCurrentSqlTime() {
|
|
482
|
-
return DateTime.getSqlTime(new Date());
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
static getTimeDisplay(sqlTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
486
|
-
return SqlDateTime.getTimeDisplay('1970-01-01 '+sqlTime, locale, timeZone);
|
|
487
|
-
}
|
|
488
|
-
static getTimeDigitalDisplay(sqlTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
489
|
-
return SqlDateTime.getTimeDigitalDisplay('1970-01-01 '+sqlTime, locale, timeZone);
|
|
490
|
-
}
|
|
491
|
-
static getTimeDisplayWithNbDays(sqlTime, previousSqlTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
492
|
-
return SqlDateTime.getTimeDisplayWithNbDays('1970-01-01 '+sqlTime, '1970-01-01 '+previousSqlTime, locale, timeZone);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
static getTimeForInputTime(sqlTime, timeZone="Europe/Paris", withSeconds=false) {
|
|
496
|
-
return SqlDateTime.getTimeForInputTime('1970-01-01 '+sqlTime, timeZone, withSeconds);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
static getTimestamp(sqlTime) {
|
|
500
|
-
return SqlDateTime.getTimestamp('1970-01-01 '+sqlTime);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Les dates/heures SQL fournies en paramètre doivent être en UTC.
|
|
506
|
-
*/
|
|
507
|
-
class SqlDateTime {
|
|
508
|
-
static getCurrentSqlDateTime() {
|
|
509
|
-
return DateTime.getSqlDateTime(new Date());
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
static getSqlDate(sqlDateTime) {
|
|
513
|
-
if (sqlDateTime == null) {
|
|
514
|
-
return null;
|
|
515
|
-
}
|
|
516
|
-
return DateTime.getSqlDate(this.parse(sqlDateTime));
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
static getSqlTime(sqlDateTime) {
|
|
520
|
-
if (sqlDateTime == null) {
|
|
521
|
-
return null;
|
|
522
|
-
}
|
|
523
|
-
return DateTime.getSqlTime(this.parse(sqlDateTime));
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
static parse(sqlDateTime) {
|
|
527
|
-
if (sqlDateTime == null) {
|
|
528
|
-
return null;
|
|
529
|
-
}
|
|
530
|
-
//return new Date(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19));
|
|
531
|
-
return new Date(Date.UTC(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19)));
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
static getDateDigitalDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
535
|
-
return DateTime.getDateDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
536
|
-
}
|
|
537
|
-
static getDateTextDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
538
|
-
return DateTime.getDateTextDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
static getTimeDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
542
|
-
return DateTime.getTimeDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
543
|
-
}
|
|
544
|
-
static getTimeDisplayWithNbDays(sqlDateTime, previousSqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
545
|
-
return DateTime.getTimeDisplayWithNbDays(this.parse(sqlDateTime), this.parse(previousSqlDateTime), locale, timeZone);
|
|
546
|
-
}
|
|
547
|
-
static getTimeDigitalDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
548
|
-
return DateTime.getTimeDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
static getDateTimeDigitalDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
552
|
-
return DateTime.getDateTimeDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
static getDateForInputDate(sqlDateTime, timeZone="Europe/Paris") {
|
|
556
|
-
return DateTime.getDateForInputDate(this.parse(sqlDateTime), timeZone);
|
|
557
|
-
}
|
|
558
|
-
static getTimeForInputTime(sqlDateTime, timeZone="Europe/Paris", withSeconds=false) {
|
|
559
|
-
return DateTime.getTimeForInputTime(this.parse(sqlDateTime), timeZone, withSeconds);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
static getYear(sqlDateTime) {
|
|
563
|
-
return DateTime.getYear(this.parse(sqlDateTime));
|
|
564
|
-
}
|
|
565
|
-
static getMonth(sqlDateTime) {
|
|
566
|
-
return DateTime.getMonth(this.parse(sqlDateTime));
|
|
567
|
-
}
|
|
568
|
-
static getMonthName(sqlDateTime, locale="fr-FR", isShort=false) {
|
|
569
|
-
return DateTime.getMonthName(this.parse(sqlDateTime), locale);
|
|
570
|
-
}
|
|
571
|
-
static getDay(sqlDateTime) {
|
|
572
|
-
return DateTime.getDay(this.parse(sqlDateTime));
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
static getTimestamp(sqlDateTime) {
|
|
576
|
-
return DateTime.getTimestamp(this.parse(sqlDateTime));
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
static isDateInTheFuture(sqlDateTime) {
|
|
580
|
-
return DateTime.isDateInTheFuture(this.parse(sqlDateTime));
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
static isDateTimeInTheFuture(sqlDateTime) {
|
|
584
|
-
return DateTime.isDateTimeInTheFuture(this.parse(sqlDateTime));
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
static getNbDayBetweenTwo(sqlDateTime1, sqlDateTime2, asPeriod=false) {
|
|
588
|
-
return DateTime.getNbDayBetweenTwo(this.parse(sqlDateTime1), this.parse(sqlDateTime2), asPeriod);
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
|
|
1
|
+
|
|
2
|
+
class DateTimeFormatter {
|
|
3
|
+
static getDateDigitalFormatter(locale, timeZone) {
|
|
4
|
+
this.dateDigitalFormatter = this.dateDigitalFormatter || {};
|
|
5
|
+
if (typeof this.dateDigitalFormatter[timeZone+locale] == 'undefined') {
|
|
6
|
+
this.dateDigitalFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return this.dateDigitalFormatter[timeZone+locale];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static getDateTextFormatter(locale, timeZone) {
|
|
13
|
+
this.dateTextFormatter = this.dateTextFormatter || {};
|
|
14
|
+
if (typeof this.dateTextFormatter[timeZone+locale] == 'undefined') {
|
|
15
|
+
this.dateTextFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return this.dateTextFormatter[timeZone+locale];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static getDateTimeFormatter(locale, timeZone) {
|
|
22
|
+
this.dateTimeFormatter = this.dateTimeFormatter || {};
|
|
23
|
+
if (typeof this.dateTimeFormatter[timeZone+locale] == 'undefined') {
|
|
24
|
+
this.dateTimeFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return this.dateTimeFormatter[timeZone+locale];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static getDateSqlFormatter(timeZone) {
|
|
31
|
+
this.dateSqlFormatter = this.dateSqlFormatter || {};
|
|
32
|
+
if (typeof this.dateSqlFormatter[timeZone] == 'undefined') {
|
|
33
|
+
this.dateSqlFormatter[timeZone] = new Intl.DateTimeFormat('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: timeZone });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this.dateSqlFormatter[timeZone];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static getTimeSqlFormatter(timeZone) {
|
|
40
|
+
this.timeSqlFormatter = this.timeSqlFormatter || {};
|
|
41
|
+
if (typeof this.timeSqlFormatter[timeZone] == 'undefined') {
|
|
42
|
+
//console.log('init getTimeSqlFormatter avec timezone', timeZone);
|
|
43
|
+
this.timeSqlFormatter[timeZone] = new Intl.DateTimeFormat('en-GB', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: timeZone }); //hour12: false = 24h format
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return this.timeSqlFormatter[timeZone];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static getTimeFormatter(locale, timeZone) {
|
|
50
|
+
this.timeFormatter = this.timeFormatter || {};
|
|
51
|
+
if (typeof this.timeFormatter[timeZone+locale] == 'undefined') {
|
|
52
|
+
this.timeFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: 'numeric', timeZone: timeZone });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return this.timeFormatter[timeZone+locale];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static getTimeDigitalFormatter(locale, timeZone) {
|
|
59
|
+
this.timeDigitalFormatter = this.timeDigitalFormatter || {};
|
|
60
|
+
if (typeof this.timeDigitalFormatter[timeZone+locale] == 'undefined') {
|
|
61
|
+
this.timeDigitalFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return this.timeDigitalFormatter[timeZone+locale];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class DateTime {
|
|
69
|
+
static getSqlDate(jsDate, timeZone="Europe/Paris") {
|
|
70
|
+
return DateTimeFormatter.getDateSqlFormatter(timeZone).format(jsDate).replace(/\//g,'-').replace(',','');
|
|
71
|
+
/*let pad = function(num) { return ('00'+num).slice(-2) };
|
|
72
|
+
// return jsDate.getUTCFullYear() + '-' + pad(jsDate.getUTCMonth() + 1) + '-' + pad(jsDate.getUTCDate());
|
|
73
|
+
//return jsDate.getFullYear() + '-' + pad(jsDate.getMonth() + 1) + '-' + pad(jsDate.getDate());
|
|
74
|
+
return jsDate.toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {month: '2-digit', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {day: '2-digit', timeZone: timeZone});
|
|
75
|
+
*/
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static getSqlTime(jsDate, timeZone="Europe/Paris") {
|
|
79
|
+
return DateTimeFormatter.getTimeSqlFormatter(timeZone).format(jsDate);
|
|
80
|
+
/*let pad = function(num) { return ('00'+num).slice(-2) };
|
|
81
|
+
// return pad(jsDate.getUTCHours()) + ':' + pad(jsDate.getUTCMinutes()) + ':' + pad(jsDate.getUTCSeconds());
|
|
82
|
+
//return pad(jsDate.getHours()) + ':' + pad(jsDate.getMinutes()) + ':' + pad(jsDate.getSeconds());
|
|
83
|
+
return pad(jsDate.toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone}));
|
|
84
|
+
*/
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static getSqlDateTime(jsDate, timeZone="Europe/Paris") {
|
|
88
|
+
return this.getSqlDate(jsDate, timeZone)+' '+this.getSqlTime(jsDate, timeZone);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static getDateForInputDate(jsDate, timeZone="Europe/Paris") {
|
|
92
|
+
return this.getSqlDate(jsDate, timeZone);
|
|
93
|
+
}
|
|
94
|
+
static getTimeForInputTime(jsDate, timeZone="Europe/Paris", withSeconds=false) {
|
|
95
|
+
return jsDate.toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone, hour12: false}).padStart(2, '0')+':'+jsDate.toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone, hour12: false}).padStart(2, '0')+(withSeconds?':'+jsDate.toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone, hour12: false}).padStart(2, '0'):'');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static getTimestamp(jsDate) {
|
|
99
|
+
return Math.trunc(jsDate.getTime()/1000);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static getDateDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
103
|
+
return DateTimeFormatter.getDateDigitalFormatter(locale, timeZone).format(jsDate);
|
|
104
|
+
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static getDateTextDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
108
|
+
return DateTimeFormatter.getDateTextFormatter(locale, timeZone).format(jsDate);
|
|
109
|
+
//return jsDate.toLocaleDateString(locale, {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static getTimeDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
113
|
+
return DateTimeFormatter.getTimeFormatter(locale, timeZone).format(jsDate);
|
|
114
|
+
//return jsDate.toLocaleTimeString(locale, {hour: 'numeric', minute: 'numeric', timeZone: timeZone});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static getTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
118
|
+
return DateTimeFormatter.getTimeDigitalFormatter(locale, timeZone).format(jsDate);
|
|
119
|
+
//return jsDate.toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static getTimeDisplayWithNbDays(jsDate, jsPreviousDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
123
|
+
let str = this.getTimeDisplay(jsDate, locale, timeZone);
|
|
124
|
+
if (jsPreviousDate != 0 && jsPreviousDate != null) {
|
|
125
|
+
let nbDaysDiff = this.getNbDayBetweenTwo(jsPreviousDate, jsDate, false);
|
|
126
|
+
if (nbDaysDiff > 0) {
|
|
127
|
+
str += ' (J+'+nbDaysDiff+')';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return str;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static getDateTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
134
|
+
return DateTimeFormatter.getDateTimeFormatter(locale, timeZone).format(jsDate);
|
|
135
|
+
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static getYear(jsDate) {
|
|
139
|
+
return jsDate.getUTCFullYear();
|
|
140
|
+
}
|
|
141
|
+
static getMonth(jsDate) {
|
|
142
|
+
return jsDate.getUTCMonth()+1;
|
|
143
|
+
}
|
|
144
|
+
static getMonthName(jsDate, locale="fr-FR", isShort=false) {
|
|
145
|
+
return jsDate.toLocaleDateString(locale, {month: (isShort?'short':'long')});
|
|
146
|
+
}
|
|
147
|
+
static getDay(jsDate) {
|
|
148
|
+
return jsDate.getUTCDate();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static getDayOfMonth(jsDate) {
|
|
152
|
+
return jsDate.getUTCDate();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static getDayOfWeek(jsDate) {
|
|
156
|
+
return jsDate.getUTCDay();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static getDayName(jsDate, locale="fr-FR", isShort=false) {
|
|
160
|
+
return jsDate.toLocaleDateString(locale, {weekday: (isShort?'short':'long')});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static getNbDaysInMonth(year, month) {
|
|
164
|
+
return new Date(Date.UTC(year, month, 0)).getDate();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
static getMonthNameByMonth(month, locale="fr-FR", isShort=false) {
|
|
168
|
+
let d = new Date();
|
|
169
|
+
d.setDate(1);
|
|
170
|
+
d.setMonth(month-1);
|
|
171
|
+
return this.getMonthName(d, locale, isShort);
|
|
172
|
+
}
|
|
173
|
+
static getDayNameByDayOfWeek(dayOfWeek, locale="fr-FR", isShort=false) {
|
|
174
|
+
let d = new Date();
|
|
175
|
+
// d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
|
|
176
|
+
d.setDate(d.getDate() + (dayOfWeek - d.getDay()) % 7);
|
|
177
|
+
return this.getDayName(d, locale, isShort);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
static getFirstDayOfWeek(date) {
|
|
182
|
+
let firstDayOfWeek = new Date(date);
|
|
183
|
+
const day = date.getUTCDay();
|
|
184
|
+
firstDayOfWeek.setUTCDate(date.getUTCDate() - day + (0 === day ? -6:1)); // First day is the day of the month - the day of the week
|
|
185
|
+
return firstDayOfWeek;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static getLastDayOfWeek(date) {
|
|
189
|
+
let lastDayOfWeek = this.getFirstDayOfWeek(date);
|
|
190
|
+
lastDayOfWeek.setUTCDate(lastDayOfWeek.getUTCDate() + 6); // last day is the first day + 6
|
|
191
|
+
return lastDayOfWeek;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static getFirstDayOfMonth(date) {
|
|
195
|
+
return this.getFirstDayOfMonthAndYear(date.getUTCFullYear(), date.getUTCMonth()+1);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
static getLastDayOfMonth(date) {
|
|
199
|
+
return this.getLastDayOfMonthAndYear(date.getUTCFullYear(), date.getUTCMonth()+1);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
static getFirstDayOfYear(date) {
|
|
203
|
+
date.setUTCDate(1);
|
|
204
|
+
date.setUTCMonth(0);
|
|
205
|
+
return new Date(date);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
static getLastDayOfYear(date) {
|
|
209
|
+
date.setUTCDate(31);
|
|
210
|
+
date.setUTCMonth(11);
|
|
211
|
+
return new Date(date);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static getFirstDayOfWeekAndYear(year, week) {
|
|
215
|
+
let simple = new Date(Date.UTC(year, 0, 1 + (week - 1) * 7));
|
|
216
|
+
let dow = simple.getDay();
|
|
217
|
+
let ISOweekStart = simple;
|
|
218
|
+
if (dow <= 4) {
|
|
219
|
+
ISOweekStart.setUTCDate(simple.getUTCDate() - simple.getUTCDay() + 1);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
ISOweekStart.setUTCDate(simple.getUTCDate() + 8 - simple.getUTCDay());
|
|
223
|
+
}
|
|
224
|
+
return ISOweekStart;
|
|
225
|
+
}
|
|
226
|
+
static getLastDayOfWeekAndYear(year, week) {
|
|
227
|
+
let firstDayOfWeek = this.getFirstDayOfWeekAndYear(year, week);
|
|
228
|
+
firstDayOfWeek.setUTCDate(firstDayOfWeek.getUTCDate()+6);
|
|
229
|
+
return firstDayOfWeek;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
static getFirstDayOfMonthAndYear(year, month) {
|
|
233
|
+
return new Date(Date.UTC(year, month-1, 1));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
static getLastDayOfMonthAndYear(year, month) {
|
|
237
|
+
return new Date(Date.UTC(year, month, 0));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static isDateEqual(jsDate1, jsDate2) {
|
|
241
|
+
return (jsDate1.getFullYear() == jsDate2.getFullYear() && jsDate1.getMonth() == jsDate2.getMonth() && jsDate1.getDate() == jsDate2.getDate());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static isDateInThePast(jsDate) {
|
|
245
|
+
jsDate.setHours(0);
|
|
246
|
+
jsDate.setMinutes(0);
|
|
247
|
+
jsDate.setSeconds(0);
|
|
248
|
+
jsDate.setMilliseconds(0);
|
|
249
|
+
let today = new Date();
|
|
250
|
+
today.setHours(0);
|
|
251
|
+
today.setMinutes(0);
|
|
252
|
+
today.setSeconds(0);
|
|
253
|
+
today.setMilliseconds(0);
|
|
254
|
+
return jsDate.getTime() < today.getTime();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
static isDateInTheFuture(jsDate) {
|
|
258
|
+
jsDate.setHours(0);
|
|
259
|
+
jsDate.setMinutes(0);
|
|
260
|
+
jsDate.setSeconds(0);
|
|
261
|
+
jsDate.setMilliseconds(0);
|
|
262
|
+
let today = new Date();
|
|
263
|
+
today.setHours(0);
|
|
264
|
+
today.setMinutes(0);
|
|
265
|
+
today.setSeconds(0);
|
|
266
|
+
today.setMilliseconds(0);
|
|
267
|
+
return jsDate.getTime() > today.getTime();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
static isDateTimeInThePast(jsDateTime) {
|
|
271
|
+
let today = new Date();
|
|
272
|
+
return jsDateTime < today;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
static isDateTimeInTheFuture(jsDateTime) {
|
|
276
|
+
let today = new Date();
|
|
277
|
+
return jsDateTime > today;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static getNbDayBetweenTwo(jsDate1, jsDate2, asPeriod=false, timeZone="Europe/Paris") {
|
|
281
|
+
//jsDate1.set
|
|
282
|
+
if (jsDate1 == null || jsDate2 == null) {
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
let timestamp1 = jsDate1.getTime() / 1000;
|
|
287
|
+
let timestamp2 = jsDate2.getTime() / 1000;
|
|
288
|
+
|
|
289
|
+
if (!asPeriod) {
|
|
290
|
+
let jsMidnightDate1 = new Date(jsDate1.toLocaleDateString('en-US', {timeZone: timeZone})+' 00:00:00');
|
|
291
|
+
let jsMidnightDate2 = new Date(jsDate2.toLocaleDateString('en-US', {timeZone: timeZone})+' 00:00:00');
|
|
292
|
+
timestamp1 = jsMidnightDate1.getTime() / 1000;
|
|
293
|
+
timestamp2 = jsMidnightDate2.getTime() / 1000;
|
|
294
|
+
//jsDate1.setHours(0, 0, 0);
|
|
295
|
+
//jsDate2.setHours(0, 0, 0);
|
|
296
|
+
//jsDate1.setUTCHours(0, 0, 0);
|
|
297
|
+
//jsDate2.setUTCHours(0, 0, 0);
|
|
298
|
+
}
|
|
299
|
+
return parseInt(Math.round((timestamp2-timestamp1)/86400));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
static addDays(date, days) {
|
|
303
|
+
date.setUTCDate(date.getUTCDate() + days);
|
|
304
|
+
return date;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
static addMonths(date, months) {
|
|
308
|
+
let d = date.getDate();
|
|
309
|
+
date.setMonth(date.getMonth() + +months);
|
|
310
|
+
if (date.getDate() !== d) {
|
|
311
|
+
date.setDate(0);
|
|
312
|
+
}
|
|
313
|
+
return date;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
class TimestampUnix {
|
|
318
|
+
static parse(timestamp) {
|
|
319
|
+
if (timestamp == null) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
return new Date(parseInt(timestamp+'000'));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
static getCurrent() {
|
|
326
|
+
let today = new Date();
|
|
327
|
+
return parseInt(today.getTime() / 1000);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
static getDateDigitalDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
331
|
+
return DateTime.getDateDigitalDisplay(this.parse(timestamp), locale, timeZone);
|
|
332
|
+
}
|
|
333
|
+
static getDateTextDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
334
|
+
return DateTime.getDateTextDisplay(this.parse(timestamp), locale, timeZone);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
static getTimeDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
338
|
+
return DateTime.getTimeDisplay(this.parse(timestamp), locale, timeZone);
|
|
339
|
+
}
|
|
340
|
+
static getTimeDisplayWithNbDays(timestamp, previousTimestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
341
|
+
return DateTime.getTimeDisplayWithNbDays(this.parse(timestamp), this.parse(previousTimestamp), locale, timeZone);
|
|
342
|
+
}
|
|
343
|
+
static getTimeDigitalDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
344
|
+
return DateTime.getTimeDigitalDisplay(this.parse(timestamp), locale, timeZone);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
static getYear(timestamp, timeZone="Europe/Paris") {
|
|
348
|
+
return this.parse(timestamp).toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone});
|
|
349
|
+
}
|
|
350
|
+
static getMonth(timestamp, timeZone="Europe/Paris") {
|
|
351
|
+
return this.parse(timestamp).toLocaleDateString('fr-FR', {month: 'numeric', timeZone: timeZone});
|
|
352
|
+
}
|
|
353
|
+
static getDayOfMonth(timestamp, timeZone="Europe/Paris") {
|
|
354
|
+
return this.parse(timestamp).toLocaleDateString('fr-FR', {day: 'numeric', timeZone: timeZone});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
static getHour(timestamp, timeZone="Europe/Paris") {
|
|
358
|
+
return this.parse(timestamp).toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone});
|
|
359
|
+
}
|
|
360
|
+
static getMinute(timestamp, timeZone="Europe/Paris") {
|
|
361
|
+
return this.parse(timestamp).toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone});
|
|
362
|
+
}
|
|
363
|
+
static getSecond(timestamp, timeZone="Europe/Paris") {
|
|
364
|
+
return this.parse(timestamp).toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
static getSqlDateTime(timestamp, timeZone="Europe/Paris") {
|
|
368
|
+
return this.getSqlDate(timestamp, timeZone)+' '+this.getSqlTime(timestamp, timeZone);
|
|
369
|
+
}
|
|
370
|
+
static getSqlDate(timestamp, timeZone="Europe/Paris") {
|
|
371
|
+
return DateTime.getSqlDate(this.parse(timestamp), timeZone);
|
|
372
|
+
}
|
|
373
|
+
static getSqlTime(timestamp, timeZone="Europe/Paris") {
|
|
374
|
+
return DateTime.getSqlTime(this.parse(timestamp), timeZone);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
static getDateForInputDate(timestamp, timeZone="Europe/Paris") {
|
|
378
|
+
return DateTime.getDateForInputDate(this.parse(timestamp), timeZone);
|
|
379
|
+
}
|
|
380
|
+
static getTimeForInputTime(timestamp, timeZone="Europe/Paris", withSeconds=false) {
|
|
381
|
+
return DateTime.getTimeForInputTime(this.parse(timestamp), timeZone, withSeconds);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
static isDateEqual(timestamp1, timestamp2) {
|
|
385
|
+
return DateTime.isDateEqual(this.parse(timestamp1), this.parse(timestamp2));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
static getNbDayBetweenTwo(timestamp1, timestamp2, asPeriod=false, timeZone="Europe/Paris") {
|
|
389
|
+
return DateTime.getNbDayBetweenTwo(this.parse(timestamp1), this.parse(timestamp2), asPeriod, timeZone);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
static isDateInThePast(timestamp) {
|
|
393
|
+
return DateTime.isDateInThePast(this.parse(timestamp));
|
|
394
|
+
}
|
|
395
|
+
static isDateTimeInThePast(timestamp) {
|
|
396
|
+
return DateTime.isDateTimeInThePast(this.parse(timestamp));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
static isDateInTheFuture(timestamp) {
|
|
400
|
+
return DateTime.isDateInTheFuture(this.parse(timestamp));
|
|
401
|
+
}
|
|
402
|
+
static isDateTimeInTheFuture(timestamp) {
|
|
403
|
+
return DateTime.isDateTimeInTheFuture(this.parse(timestamp));
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Les dates SQL fournies en paramètre doivent être en UTC.
|
|
410
|
+
*/
|
|
411
|
+
class SqlDate {
|
|
412
|
+
static parse(sqlDate) {
|
|
413
|
+
if (sqlDate == null) {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
return new Date(Date.UTC(sqlDate.substring(0, 4), sqlDate.substring(5, 7)-1, sqlDate.substring(8, 10), 0, 0, 0));
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
static getCurrentSqlDate() {
|
|
420
|
+
return DateTime.getSqlDate(new Date());
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
static getDateDigitalDisplay(sqlDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
424
|
+
return SqlDateTime.getDateDigitalDisplay(sqlDate+" 00:00:00", locale, timeZone);
|
|
425
|
+
}
|
|
426
|
+
static getDateTextDisplay(sqlDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
427
|
+
return SqlDateTime.getDateTextDisplay(sqlDate+" 00:00:00", locale, timeZone);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
static getDateForInputDate(sqlDate, timeZone="Europe/Paris") {
|
|
431
|
+
return SqlDateTime.getDateForInputDate(sqlDate+" 00:00:00", timeZone);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
static getTimestamp(sqlDate) {
|
|
435
|
+
return SqlDateTime.getTimestamp(sqlDate+" 00:00:00");
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
static getYear(sqlDate) {
|
|
439
|
+
return SqlDateTime.getYear(sqlDate+" 00:00:00");
|
|
440
|
+
}
|
|
441
|
+
static getMonth(sqlDate) {
|
|
442
|
+
return SqlDateTime.getMonth(sqlDate+" 00:00:00");
|
|
443
|
+
}
|
|
444
|
+
static getMonthName(sqlDate, locale="fr-FR", isShort=false) {
|
|
445
|
+
return SqlDateTime.getMonthName(sqlDate+" 00:00:00", locale, isShort);
|
|
446
|
+
}
|
|
447
|
+
static getDay(sqlDate) {
|
|
448
|
+
return SqlDateTime.getDay(sqlDate+" 00:00:00");
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
static isDateInTheFuture(sqlDate) {
|
|
452
|
+
return DateTime.isDateInTheFuture(SqlDateTime.parse(sqlDate + " 00:00:00"));
|
|
453
|
+
}
|
|
454
|
+
static getNbDayBetweenTwo(sqlDate1, sqlDate2, asPeriod=false) {
|
|
455
|
+
return DateTime.getNbDayBetweenTwo(SqlDateTime.parse(sqlDate1 + " 00:00:00"), SqlDateTime.parse(sqlDate2 + " 00:00:00"), asPeriod);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Les heures SQL fournies en paramètre doivent être en UTC.
|
|
461
|
+
*/
|
|
462
|
+
class SqlTime {
|
|
463
|
+
static parse(sqlTime) {
|
|
464
|
+
if (sqlTime == null) {
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if ((sqlTime.match(/\:/g) || []).length == 1) {
|
|
469
|
+
sqlTime += ':00';
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
let arrayTime = sqlTime.split(':');
|
|
473
|
+
return new Date(Date.UTC(1970, 0, 1, arrayTime[0], arrayTime[1], arrayTime[2]));
|
|
474
|
+
|
|
475
|
+
/*let jsDate = new Date();
|
|
476
|
+
jsDate.setUTCFullYear(1970, 0, 1);
|
|
477
|
+
jsDate.setUTCHours(arrayTime[0], arrayTime[1], arrayTime[2], 0);
|
|
478
|
+
return jsDate;*/
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
static getCurrentSqlTime() {
|
|
482
|
+
return DateTime.getSqlTime(new Date());
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
static getTimeDisplay(sqlTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
486
|
+
return SqlDateTime.getTimeDisplay('1970-01-01 '+sqlTime, locale, timeZone);
|
|
487
|
+
}
|
|
488
|
+
static getTimeDigitalDisplay(sqlTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
489
|
+
return SqlDateTime.getTimeDigitalDisplay('1970-01-01 '+sqlTime, locale, timeZone);
|
|
490
|
+
}
|
|
491
|
+
static getTimeDisplayWithNbDays(sqlTime, previousSqlTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
492
|
+
return SqlDateTime.getTimeDisplayWithNbDays('1970-01-01 '+sqlTime, '1970-01-01 '+previousSqlTime, locale, timeZone);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
static getTimeForInputTime(sqlTime, timeZone="Europe/Paris", withSeconds=false) {
|
|
496
|
+
return SqlDateTime.getTimeForInputTime('1970-01-01 '+sqlTime, timeZone, withSeconds);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
static getTimestamp(sqlTime) {
|
|
500
|
+
return SqlDateTime.getTimestamp('1970-01-01 '+sqlTime);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Les dates/heures SQL fournies en paramètre doivent être en UTC.
|
|
506
|
+
*/
|
|
507
|
+
class SqlDateTime {
|
|
508
|
+
static getCurrentSqlDateTime() {
|
|
509
|
+
return DateTime.getSqlDateTime(new Date());
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
static getSqlDate(sqlDateTime) {
|
|
513
|
+
if (sqlDateTime == null) {
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
return DateTime.getSqlDate(this.parse(sqlDateTime));
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
static getSqlTime(sqlDateTime) {
|
|
520
|
+
if (sqlDateTime == null) {
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
return DateTime.getSqlTime(this.parse(sqlDateTime));
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
static parse(sqlDateTime) {
|
|
527
|
+
if (sqlDateTime == null) {
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
//return new Date(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19));
|
|
531
|
+
return new Date(Date.UTC(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19)));
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
static getDateDigitalDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
535
|
+
return DateTime.getDateDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
536
|
+
}
|
|
537
|
+
static getDateTextDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
538
|
+
return DateTime.getDateTextDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
static getTimeDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
542
|
+
return DateTime.getTimeDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
543
|
+
}
|
|
544
|
+
static getTimeDisplayWithNbDays(sqlDateTime, previousSqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
545
|
+
return DateTime.getTimeDisplayWithNbDays(this.parse(sqlDateTime), this.parse(previousSqlDateTime), locale, timeZone);
|
|
546
|
+
}
|
|
547
|
+
static getTimeDigitalDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
548
|
+
return DateTime.getTimeDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
static getDateTimeDigitalDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
|
|
552
|
+
return DateTime.getDateTimeDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
static getDateForInputDate(sqlDateTime, timeZone="Europe/Paris") {
|
|
556
|
+
return DateTime.getDateForInputDate(this.parse(sqlDateTime), timeZone);
|
|
557
|
+
}
|
|
558
|
+
static getTimeForInputTime(sqlDateTime, timeZone="Europe/Paris", withSeconds=false) {
|
|
559
|
+
return DateTime.getTimeForInputTime(this.parse(sqlDateTime), timeZone, withSeconds);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
static getYear(sqlDateTime) {
|
|
563
|
+
return DateTime.getYear(this.parse(sqlDateTime));
|
|
564
|
+
}
|
|
565
|
+
static getMonth(sqlDateTime) {
|
|
566
|
+
return DateTime.getMonth(this.parse(sqlDateTime));
|
|
567
|
+
}
|
|
568
|
+
static getMonthName(sqlDateTime, locale="fr-FR", isShort=false) {
|
|
569
|
+
return DateTime.getMonthName(this.parse(sqlDateTime), locale);
|
|
570
|
+
}
|
|
571
|
+
static getDay(sqlDateTime) {
|
|
572
|
+
return DateTime.getDay(this.parse(sqlDateTime));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
static getTimestamp(sqlDateTime) {
|
|
576
|
+
return DateTime.getTimestamp(this.parse(sqlDateTime));
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
static isDateInTheFuture(sqlDateTime) {
|
|
580
|
+
return DateTime.isDateInTheFuture(this.parse(sqlDateTime));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
static isDateTimeInTheFuture(sqlDateTime) {
|
|
584
|
+
return DateTime.isDateTimeInTheFuture(this.parse(sqlDateTime));
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
static getNbDayBetweenTwo(sqlDateTime1, sqlDateTime2, asPeriod=false) {
|
|
588
|
+
return DateTime.getNbDayBetweenTwo(this.parse(sqlDateTime1), this.parse(sqlDateTime2), asPeriod);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
}
|
|
592
|
+
|
|
593
593
|
module.exports = { DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime };
|