@osovitny/anatoly 3.17.7 → 3.17.9
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/esm2022/lib/core/consts/settings.mjs +3 -1
- package/esm2022/lib/core/converts/dateConvert.mjs +28 -1
- package/esm2022/lib/core/converts/tz/tzParseTimezone.mjs +122 -0
- package/esm2022/lib/core/converts/tz/tzTokenizeDate.mjs +101 -0
- package/esm2022/lib/core/localization/localization.service.mjs +2 -11
- package/esm2022/lib/ui/components/base/components/component.mjs +4 -4
- package/fesm2022/osovitny-anatoly.mjs +254 -268
- package/fesm2022/osovitny-anatoly.mjs.map +1 -1
- package/lib/core/consts/settings.d.ts +1 -0
- package/lib/core/converts/dateConvert.d.ts +1 -0
- package/package.json +1 -1
- package/esm2022/lib/core/localization/tz/tzParseTimezone.mjs +0 -122
- package/esm2022/lib/core/localization/tz/tzTokenizeDate.mjs +0 -101
- package/esm2022/lib/core/localization/tz/utcToLocal.mjs +0 -36
- package/lib/core/localization/tz/utcToLocal.d.ts +0 -1
- /package/lib/core/{localization → converts}/tz/tzParseTimezone.d.ts +0 -0
- /package/lib/core/{localization → converts}/tz/tzTokenizeDate.d.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import js_beautify from 'js-beautify';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { Injectable, Inject, EventEmitter, Output, Pipe, APP_INITIALIZER, Injector, NgModule,
|
|
3
|
+
import { Injectable, Inject, EventEmitter, Output, Pipe, APP_INITIALIZER, Injector, NgModule, Component, Input, ViewEncapsulation, Directive, ViewChild, HostBinding, HostListener, Optional, SkipSelf } from '@angular/core';
|
|
4
4
|
import * as i1 from '@angular/router';
|
|
5
5
|
import { NavigationEnd, NavigationStart, NavigationCancel, NavigationError, RouterModule } from '@angular/router';
|
|
6
6
|
import * as i1$1 from '@angular/common/http';
|
|
@@ -88,7 +88,9 @@ function getAppSettingsByName(name) {
|
|
|
88
88
|
const AppCoreSettings = JSON.parse((document.getElementById('appCoreSettings')).getAttribute('data-appcoresettings'));
|
|
89
89
|
const L10NUrl = `${AppCoreSettings?.l10nUrl}`;
|
|
90
90
|
//WebApp
|
|
91
|
+
let isDevMode = `${AppCoreSettings?.isDevMode}`;
|
|
91
92
|
const AppVersion = `${AppCoreSettings?.version}`;
|
|
93
|
+
const IsDevMode = (isDevMode && (isDevMode == 'True' || isDevMode == 'true'));
|
|
92
94
|
const ApiUrl = `${AppCoreSettings?.apiUrl}`;
|
|
93
95
|
const ClientApps = AppCoreSettings?.clientApps;
|
|
94
96
|
//ClientApp
|
|
@@ -204,6 +206,228 @@ class Convert {
|
|
|
204
206
|
}
|
|
205
207
|
}
|
|
206
208
|
|
|
209
|
+
/*
|
|
210
|
+
<file>
|
|
211
|
+
Project:
|
|
212
|
+
@osovitny/anatoly
|
|
213
|
+
|
|
214
|
+
Authors:
|
|
215
|
+
Vadim Osovitny vadim@osovitny.com
|
|
216
|
+
Anatoly Osovitny anatoly@osovitny.com
|
|
217
|
+
|
|
218
|
+
Created:
|
|
219
|
+
10 Feb 2024
|
|
220
|
+
|
|
221
|
+
Copyright (c) 2016-2022 Osovitny Inc. All rights reserved.
|
|
222
|
+
</file>
|
|
223
|
+
*/
|
|
224
|
+
/**
|
|
225
|
+
* Returns the [year, month, day, hour, minute, seconds] tokens of the provided
|
|
226
|
+
* `date` as it will be rendered in the `timeZone`.
|
|
227
|
+
*/
|
|
228
|
+
function tzTokenizeDate(date, timeZone) {
|
|
229
|
+
var dtf = getDateTimeFormat(timeZone);
|
|
230
|
+
return dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date);
|
|
231
|
+
}
|
|
232
|
+
var typeToPos = {
|
|
233
|
+
year: 0,
|
|
234
|
+
month: 1,
|
|
235
|
+
day: 2,
|
|
236
|
+
hour: 3,
|
|
237
|
+
minute: 4,
|
|
238
|
+
second: 5,
|
|
239
|
+
};
|
|
240
|
+
function partsOffset(dtf, date) {
|
|
241
|
+
try {
|
|
242
|
+
var formatted = dtf.formatToParts(date);
|
|
243
|
+
var filled = [];
|
|
244
|
+
for (var i = 0; i < formatted.length; i++) {
|
|
245
|
+
var pos = typeToPos[formatted[i].type];
|
|
246
|
+
if (pos >= 0) {
|
|
247
|
+
filled[pos] = parseInt(formatted[i].value, 10);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return filled;
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
if (error instanceof RangeError) {
|
|
254
|
+
return [NaN];
|
|
255
|
+
}
|
|
256
|
+
throw error;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function hackyOffset(dtf, date) {
|
|
260
|
+
var formatted = dtf.format(date).replace(/\u200E/g, '');
|
|
261
|
+
var parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted);
|
|
262
|
+
// var [, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed
|
|
263
|
+
// return [fYear, fMonth, fDay, fHour, fMinute, fSecond]
|
|
264
|
+
return [parsed[3], parsed[1], parsed[2], parsed[4], parsed[5], parsed[6]];
|
|
265
|
+
}
|
|
266
|
+
// Get a cached Intl.DateTimeFormat instance for the IANA `timeZone`. This can be used
|
|
267
|
+
// to get deterministic local date/time output according to the `en-US` locale which
|
|
268
|
+
// can be used to extract local time parts as necessary.
|
|
269
|
+
var dtfCache = {};
|
|
270
|
+
function getDateTimeFormat(timeZone) {
|
|
271
|
+
if (!dtfCache[timeZone]) {
|
|
272
|
+
// New browsers use `hourCycle`, IE and Chrome <73 does not support it and uses `hour12`
|
|
273
|
+
var testDateFormatted = new Intl.DateTimeFormat('en-US', {
|
|
274
|
+
hour12: false,
|
|
275
|
+
timeZone: 'America/New_York',
|
|
276
|
+
year: 'numeric',
|
|
277
|
+
month: 'numeric',
|
|
278
|
+
day: '2-digit',
|
|
279
|
+
hour: '2-digit',
|
|
280
|
+
minute: '2-digit',
|
|
281
|
+
second: '2-digit',
|
|
282
|
+
}).format(new Date('2014-06-25T04:00:00.123Z'));
|
|
283
|
+
var hourCycleSupported = testDateFormatted === '06/25/2014, 00:00:00' ||
|
|
284
|
+
testDateFormatted === '06/25/2014 00:00:00';
|
|
285
|
+
dtfCache[timeZone] = hourCycleSupported
|
|
286
|
+
? new Intl.DateTimeFormat('en-US', {
|
|
287
|
+
hour12: false,
|
|
288
|
+
timeZone: timeZone,
|
|
289
|
+
year: 'numeric',
|
|
290
|
+
month: 'numeric',
|
|
291
|
+
day: '2-digit',
|
|
292
|
+
hour: '2-digit',
|
|
293
|
+
minute: '2-digit',
|
|
294
|
+
second: '2-digit',
|
|
295
|
+
})
|
|
296
|
+
: new Intl.DateTimeFormat('en-US', {
|
|
297
|
+
hourCycle: 'h23',
|
|
298
|
+
timeZone: timeZone,
|
|
299
|
+
year: 'numeric',
|
|
300
|
+
month: 'numeric',
|
|
301
|
+
day: '2-digit',
|
|
302
|
+
hour: '2-digit',
|
|
303
|
+
minute: '2-digit',
|
|
304
|
+
second: '2-digit',
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return dtfCache[timeZone];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/*
|
|
311
|
+
<file>
|
|
312
|
+
Project:
|
|
313
|
+
@osovitny/anatoly
|
|
314
|
+
|
|
315
|
+
Authors:
|
|
316
|
+
Vadim Osovitny vadim@osovitny.com
|
|
317
|
+
Anatoly Osovitny anatoly@osovitny.com
|
|
318
|
+
|
|
319
|
+
Created:
|
|
320
|
+
10 Feb 2024
|
|
321
|
+
|
|
322
|
+
Copyright (c) 2016-2022 Osovitny Inc. All rights reserved.
|
|
323
|
+
</file>
|
|
324
|
+
*/
|
|
325
|
+
function tzParseTimezone(timezoneString, date, isUtcDate) {
|
|
326
|
+
var token;
|
|
327
|
+
var absoluteOffset;
|
|
328
|
+
// Empty string
|
|
329
|
+
if (!timezoneString) {
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
332
|
+
// Z
|
|
333
|
+
token = patterns.timezoneZ.exec(timezoneString);
|
|
334
|
+
if (token) {
|
|
335
|
+
return 0;
|
|
336
|
+
}
|
|
337
|
+
var hours;
|
|
338
|
+
// ±hh
|
|
339
|
+
token = patterns.timezoneHH.exec(timezoneString);
|
|
340
|
+
if (token) {
|
|
341
|
+
hours = parseInt(token[1], 10);
|
|
342
|
+
if (!validateTimezone(hours)) {
|
|
343
|
+
return NaN;
|
|
344
|
+
}
|
|
345
|
+
return -(hours * MILLISECONDS_IN_HOUR);
|
|
346
|
+
}
|
|
347
|
+
// ±hh:mm or ±hhmm
|
|
348
|
+
token = patterns.timezoneHHMM.exec(timezoneString);
|
|
349
|
+
if (token) {
|
|
350
|
+
hours = parseInt(token[1], 10);
|
|
351
|
+
var minutes = parseInt(token[2], 10);
|
|
352
|
+
if (!validateTimezone(hours, minutes)) {
|
|
353
|
+
return NaN;
|
|
354
|
+
}
|
|
355
|
+
absoluteOffset = Math.abs(hours) * MILLISECONDS_IN_HOUR + minutes * MILLISECONDS_IN_MINUTE;
|
|
356
|
+
return hours > 0 ? -absoluteOffset : absoluteOffset;
|
|
357
|
+
}
|
|
358
|
+
// IANA time zone
|
|
359
|
+
if (isValidTimezoneIANAString(timezoneString)) {
|
|
360
|
+
date = new Date(date || Date.now());
|
|
361
|
+
var utcDate = isUtcDate ? date : toUtcDate(date);
|
|
362
|
+
var offset = calcOffset(utcDate, timezoneString);
|
|
363
|
+
var fixedOffset = isUtcDate ? offset : fixOffset(date, offset, timezoneString);
|
|
364
|
+
return -fixedOffset;
|
|
365
|
+
}
|
|
366
|
+
return NaN;
|
|
367
|
+
}
|
|
368
|
+
var MILLISECONDS_IN_HOUR = 3600000;
|
|
369
|
+
var MILLISECONDS_IN_MINUTE = 60000;
|
|
370
|
+
var patterns = {
|
|
371
|
+
timezone: /([Z+-].*)$/,
|
|
372
|
+
timezoneZ: /^(Z)$/,
|
|
373
|
+
timezoneHH: /^([+-]\d{2})$/,
|
|
374
|
+
timezoneHHMM: /^([+-]\d{2}):?(\d{2})$/,
|
|
375
|
+
};
|
|
376
|
+
function newDateUTC(fullYear, month, day, hour, minute, second, millisecond) {
|
|
377
|
+
var utcDate = new Date(0);
|
|
378
|
+
utcDate.setUTCFullYear(fullYear, month, day);
|
|
379
|
+
utcDate.setUTCHours(hour, minute, second, millisecond);
|
|
380
|
+
return utcDate;
|
|
381
|
+
}
|
|
382
|
+
function toUtcDate(date) {
|
|
383
|
+
return newDateUTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
|
|
384
|
+
}
|
|
385
|
+
function calcOffset(date, timezoneString) {
|
|
386
|
+
var tokens = tzTokenizeDate(date, timezoneString);
|
|
387
|
+
// ms dropped because it's not provided by tzTokenizeDate
|
|
388
|
+
var asUTC = newDateUTC(tokens[0], tokens[1] - 1, tokens[2], tokens[3] % 24, tokens[4], tokens[5], 0).getTime();
|
|
389
|
+
var asTS = date.getTime();
|
|
390
|
+
var over = asTS % 1000;
|
|
391
|
+
asTS -= over >= 0 ? over : 1000 + over;
|
|
392
|
+
return asUTC - asTS;
|
|
393
|
+
}
|
|
394
|
+
function fixOffset(date, offset, timezoneString) {
|
|
395
|
+
var localTS = date.getTime();
|
|
396
|
+
// Our UTC time is just a guess because our offset is just a guess
|
|
397
|
+
var utcGuess = localTS - offset;
|
|
398
|
+
// Test whether the zone matches the offset for this ts
|
|
399
|
+
var o2 = calcOffset(new Date(utcGuess), timezoneString);
|
|
400
|
+
// If so, offset didn't change, and we're done
|
|
401
|
+
if (offset === o2) {
|
|
402
|
+
return offset;
|
|
403
|
+
}
|
|
404
|
+
// If not, change the ts by the difference in the offset
|
|
405
|
+
utcGuess -= o2 - offset;
|
|
406
|
+
// If that gives us the local time we want, we're done
|
|
407
|
+
var o3 = calcOffset(new Date(utcGuess), timezoneString);
|
|
408
|
+
if (o2 === o3) {
|
|
409
|
+
return o2;
|
|
410
|
+
}
|
|
411
|
+
// If it's different, we're in a hole time. The offset has changed, but we don't adjust the time
|
|
412
|
+
return Math.max(o2, o3);
|
|
413
|
+
}
|
|
414
|
+
function validateTimezone(hours, minutes = null) {
|
|
415
|
+
return -23 <= hours && hours <= 23 && (minutes == null || (0 <= minutes && minutes <= 59));
|
|
416
|
+
}
|
|
417
|
+
var validIANATimezoneCache = {};
|
|
418
|
+
function isValidTimezoneIANAString(timeZoneString) {
|
|
419
|
+
if (validIANATimezoneCache[timeZoneString])
|
|
420
|
+
return true;
|
|
421
|
+
try {
|
|
422
|
+
new Intl.DateTimeFormat(undefined, { timeZone: timeZoneString });
|
|
423
|
+
validIANATimezoneCache[timeZoneString] = true;
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
207
431
|
/*
|
|
208
432
|
<file>
|
|
209
433
|
Project:
|
|
@@ -219,6 +443,11 @@ class Convert {
|
|
|
219
443
|
Source:
|
|
220
444
|
https://github.com/date-fns/date-fns/blob/main/src/toDate/index.ts
|
|
221
445
|
|
|
446
|
+
tz:
|
|
447
|
+
https://www.npmjs.com/package/date-fns-tz
|
|
448
|
+
https://github.com/marnusw/date-fns-tz/blob/master/src/utcToZonedTime/index.js
|
|
449
|
+
https://github.com/marnusw/date-fns-tz/blob/master/src/_lib/tzParseTimezone/index.js
|
|
450
|
+
|
|
222
451
|
Copyright (c) 2016-2022 Osovitny Inc. All rights reserved.
|
|
223
452
|
</file>
|
|
224
453
|
*/
|
|
@@ -236,6 +465,27 @@ class DateConvert {
|
|
|
236
465
|
return new Date(NaN);
|
|
237
466
|
}
|
|
238
467
|
}
|
|
468
|
+
static utcToLocal(dirtyDate) {
|
|
469
|
+
if (typeof dirtyDate === 'string') {
|
|
470
|
+
if (dirtyDate.indexOf("T") > -1) {
|
|
471
|
+
dirtyDate = dirtyDate.replace("T", " ");
|
|
472
|
+
}
|
|
473
|
+
if (dirtyDate.indexOf("Z") == -1) {
|
|
474
|
+
dirtyDate = dirtyDate + "Z";
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
let browserTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
478
|
+
if (browserTimeZone) {
|
|
479
|
+
let date = DateConvert.toDate(dirtyDate);
|
|
480
|
+
let offsetMilliseconds = tzParseTimezone(browserTimeZone, date, true);
|
|
481
|
+
let d = new Date(date.getTime() - offsetMilliseconds);
|
|
482
|
+
let resultDate = new Date(0);
|
|
483
|
+
resultDate.setFullYear(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
484
|
+
resultDate.setHours(d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
|
|
485
|
+
return resultDate;
|
|
486
|
+
}
|
|
487
|
+
return new Date(dirtyDate);
|
|
488
|
+
}
|
|
239
489
|
}
|
|
240
490
|
|
|
241
491
|
/*
|
|
@@ -1716,262 +1966,6 @@ is = {
|
|
|
1716
1966
|
};
|
|
1717
1967
|
*/
|
|
1718
1968
|
|
|
1719
|
-
/*
|
|
1720
|
-
<file>
|
|
1721
|
-
Project:
|
|
1722
|
-
@osovitny/anatoly
|
|
1723
|
-
|
|
1724
|
-
Authors:
|
|
1725
|
-
Vadim Osovitny vadim@osovitny.com
|
|
1726
|
-
Anatoly Osovitny anatoly@osovitny.com
|
|
1727
|
-
|
|
1728
|
-
Created:
|
|
1729
|
-
10 Feb 2024
|
|
1730
|
-
|
|
1731
|
-
Copyright (c) 2016-2022 Osovitny Inc. All rights reserved.
|
|
1732
|
-
</file>
|
|
1733
|
-
*/
|
|
1734
|
-
/**
|
|
1735
|
-
* Returns the [year, month, day, hour, minute, seconds] tokens of the provided
|
|
1736
|
-
* `date` as it will be rendered in the `timeZone`.
|
|
1737
|
-
*/
|
|
1738
|
-
function tzTokenizeDate(date, timeZone) {
|
|
1739
|
-
var dtf = getDateTimeFormat(timeZone);
|
|
1740
|
-
return dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date);
|
|
1741
|
-
}
|
|
1742
|
-
var typeToPos = {
|
|
1743
|
-
year: 0,
|
|
1744
|
-
month: 1,
|
|
1745
|
-
day: 2,
|
|
1746
|
-
hour: 3,
|
|
1747
|
-
minute: 4,
|
|
1748
|
-
second: 5,
|
|
1749
|
-
};
|
|
1750
|
-
function partsOffset(dtf, date) {
|
|
1751
|
-
try {
|
|
1752
|
-
var formatted = dtf.formatToParts(date);
|
|
1753
|
-
var filled = [];
|
|
1754
|
-
for (var i = 0; i < formatted.length; i++) {
|
|
1755
|
-
var pos = typeToPos[formatted[i].type];
|
|
1756
|
-
if (pos >= 0) {
|
|
1757
|
-
filled[pos] = parseInt(formatted[i].value, 10);
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
return filled;
|
|
1761
|
-
}
|
|
1762
|
-
catch (error) {
|
|
1763
|
-
if (error instanceof RangeError) {
|
|
1764
|
-
return [NaN];
|
|
1765
|
-
}
|
|
1766
|
-
throw error;
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
function hackyOffset(dtf, date) {
|
|
1770
|
-
var formatted = dtf.format(date).replace(/\u200E/g, '');
|
|
1771
|
-
var parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted);
|
|
1772
|
-
// var [, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed
|
|
1773
|
-
// return [fYear, fMonth, fDay, fHour, fMinute, fSecond]
|
|
1774
|
-
return [parsed[3], parsed[1], parsed[2], parsed[4], parsed[5], parsed[6]];
|
|
1775
|
-
}
|
|
1776
|
-
// Get a cached Intl.DateTimeFormat instance for the IANA `timeZone`. This can be used
|
|
1777
|
-
// to get deterministic local date/time output according to the `en-US` locale which
|
|
1778
|
-
// can be used to extract local time parts as necessary.
|
|
1779
|
-
var dtfCache = {};
|
|
1780
|
-
function getDateTimeFormat(timeZone) {
|
|
1781
|
-
if (!dtfCache[timeZone]) {
|
|
1782
|
-
// New browsers use `hourCycle`, IE and Chrome <73 does not support it and uses `hour12`
|
|
1783
|
-
var testDateFormatted = new Intl.DateTimeFormat('en-US', {
|
|
1784
|
-
hour12: false,
|
|
1785
|
-
timeZone: 'America/New_York',
|
|
1786
|
-
year: 'numeric',
|
|
1787
|
-
month: 'numeric',
|
|
1788
|
-
day: '2-digit',
|
|
1789
|
-
hour: '2-digit',
|
|
1790
|
-
minute: '2-digit',
|
|
1791
|
-
second: '2-digit',
|
|
1792
|
-
}).format(new Date('2014-06-25T04:00:00.123Z'));
|
|
1793
|
-
var hourCycleSupported = testDateFormatted === '06/25/2014, 00:00:00' ||
|
|
1794
|
-
testDateFormatted === '06/25/2014 00:00:00';
|
|
1795
|
-
dtfCache[timeZone] = hourCycleSupported
|
|
1796
|
-
? new Intl.DateTimeFormat('en-US', {
|
|
1797
|
-
hour12: false,
|
|
1798
|
-
timeZone: timeZone,
|
|
1799
|
-
year: 'numeric',
|
|
1800
|
-
month: 'numeric',
|
|
1801
|
-
day: '2-digit',
|
|
1802
|
-
hour: '2-digit',
|
|
1803
|
-
minute: '2-digit',
|
|
1804
|
-
second: '2-digit',
|
|
1805
|
-
})
|
|
1806
|
-
: new Intl.DateTimeFormat('en-US', {
|
|
1807
|
-
hourCycle: 'h23',
|
|
1808
|
-
timeZone: timeZone,
|
|
1809
|
-
year: 'numeric',
|
|
1810
|
-
month: 'numeric',
|
|
1811
|
-
day: '2-digit',
|
|
1812
|
-
hour: '2-digit',
|
|
1813
|
-
minute: '2-digit',
|
|
1814
|
-
second: '2-digit',
|
|
1815
|
-
});
|
|
1816
|
-
}
|
|
1817
|
-
return dtfCache[timeZone];
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
/*
|
|
1821
|
-
<file>
|
|
1822
|
-
Project:
|
|
1823
|
-
@osovitny/anatoly
|
|
1824
|
-
|
|
1825
|
-
Authors:
|
|
1826
|
-
Vadim Osovitny vadim@osovitny.com
|
|
1827
|
-
Anatoly Osovitny anatoly@osovitny.com
|
|
1828
|
-
|
|
1829
|
-
Created:
|
|
1830
|
-
10 Feb 2024
|
|
1831
|
-
|
|
1832
|
-
Copyright (c) 2016-2022 Osovitny Inc. All rights reserved.
|
|
1833
|
-
</file>
|
|
1834
|
-
*/
|
|
1835
|
-
function tzParseTimezone(timezoneString, date, isUtcDate) {
|
|
1836
|
-
var token;
|
|
1837
|
-
var absoluteOffset;
|
|
1838
|
-
// Empty string
|
|
1839
|
-
if (!timezoneString) {
|
|
1840
|
-
return 0;
|
|
1841
|
-
}
|
|
1842
|
-
// Z
|
|
1843
|
-
token = patterns.timezoneZ.exec(timezoneString);
|
|
1844
|
-
if (token) {
|
|
1845
|
-
return 0;
|
|
1846
|
-
}
|
|
1847
|
-
var hours;
|
|
1848
|
-
// ±hh
|
|
1849
|
-
token = patterns.timezoneHH.exec(timezoneString);
|
|
1850
|
-
if (token) {
|
|
1851
|
-
hours = parseInt(token[1], 10);
|
|
1852
|
-
if (!validateTimezone(hours)) {
|
|
1853
|
-
return NaN;
|
|
1854
|
-
}
|
|
1855
|
-
return -(hours * MILLISECONDS_IN_HOUR);
|
|
1856
|
-
}
|
|
1857
|
-
// ±hh:mm or ±hhmm
|
|
1858
|
-
token = patterns.timezoneHHMM.exec(timezoneString);
|
|
1859
|
-
if (token) {
|
|
1860
|
-
hours = parseInt(token[1], 10);
|
|
1861
|
-
var minutes = parseInt(token[2], 10);
|
|
1862
|
-
if (!validateTimezone(hours, minutes)) {
|
|
1863
|
-
return NaN;
|
|
1864
|
-
}
|
|
1865
|
-
absoluteOffset = Math.abs(hours) * MILLISECONDS_IN_HOUR + minutes * MILLISECONDS_IN_MINUTE;
|
|
1866
|
-
return hours > 0 ? -absoluteOffset : absoluteOffset;
|
|
1867
|
-
}
|
|
1868
|
-
// IANA time zone
|
|
1869
|
-
if (isValidTimezoneIANAString(timezoneString)) {
|
|
1870
|
-
date = new Date(date || Date.now());
|
|
1871
|
-
var utcDate = isUtcDate ? date : toUtcDate(date);
|
|
1872
|
-
var offset = calcOffset(utcDate, timezoneString);
|
|
1873
|
-
var fixedOffset = isUtcDate ? offset : fixOffset(date, offset, timezoneString);
|
|
1874
|
-
return -fixedOffset;
|
|
1875
|
-
}
|
|
1876
|
-
return NaN;
|
|
1877
|
-
}
|
|
1878
|
-
var MILLISECONDS_IN_HOUR = 3600000;
|
|
1879
|
-
var MILLISECONDS_IN_MINUTE = 60000;
|
|
1880
|
-
var patterns = {
|
|
1881
|
-
timezone: /([Z+-].*)$/,
|
|
1882
|
-
timezoneZ: /^(Z)$/,
|
|
1883
|
-
timezoneHH: /^([+-]\d{2})$/,
|
|
1884
|
-
timezoneHHMM: /^([+-]\d{2}):?(\d{2})$/,
|
|
1885
|
-
};
|
|
1886
|
-
function newDateUTC(fullYear, month, day, hour, minute, second, millisecond) {
|
|
1887
|
-
var utcDate = new Date(0);
|
|
1888
|
-
utcDate.setUTCFullYear(fullYear, month, day);
|
|
1889
|
-
utcDate.setUTCHours(hour, minute, second, millisecond);
|
|
1890
|
-
return utcDate;
|
|
1891
|
-
}
|
|
1892
|
-
function toUtcDate(date) {
|
|
1893
|
-
return newDateUTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
|
|
1894
|
-
}
|
|
1895
|
-
function calcOffset(date, timezoneString) {
|
|
1896
|
-
var tokens = tzTokenizeDate(date, timezoneString);
|
|
1897
|
-
// ms dropped because it's not provided by tzTokenizeDate
|
|
1898
|
-
var asUTC = newDateUTC(tokens[0], tokens[1] - 1, tokens[2], tokens[3] % 24, tokens[4], tokens[5], 0).getTime();
|
|
1899
|
-
var asTS = date.getTime();
|
|
1900
|
-
var over = asTS % 1000;
|
|
1901
|
-
asTS -= over >= 0 ? over : 1000 + over;
|
|
1902
|
-
return asUTC - asTS;
|
|
1903
|
-
}
|
|
1904
|
-
function fixOffset(date, offset, timezoneString) {
|
|
1905
|
-
var localTS = date.getTime();
|
|
1906
|
-
// Our UTC time is just a guess because our offset is just a guess
|
|
1907
|
-
var utcGuess = localTS - offset;
|
|
1908
|
-
// Test whether the zone matches the offset for this ts
|
|
1909
|
-
var o2 = calcOffset(new Date(utcGuess), timezoneString);
|
|
1910
|
-
// If so, offset didn't change, and we're done
|
|
1911
|
-
if (offset === o2) {
|
|
1912
|
-
return offset;
|
|
1913
|
-
}
|
|
1914
|
-
// If not, change the ts by the difference in the offset
|
|
1915
|
-
utcGuess -= o2 - offset;
|
|
1916
|
-
// If that gives us the local time we want, we're done
|
|
1917
|
-
var o3 = calcOffset(new Date(utcGuess), timezoneString);
|
|
1918
|
-
if (o2 === o3) {
|
|
1919
|
-
return o2;
|
|
1920
|
-
}
|
|
1921
|
-
// If it's different, we're in a hole time. The offset has changed, but we don't adjust the time
|
|
1922
|
-
return Math.max(o2, o3);
|
|
1923
|
-
}
|
|
1924
|
-
function validateTimezone(hours, minutes = null) {
|
|
1925
|
-
return -23 <= hours && hours <= 23 && (minutes == null || (0 <= minutes && minutes <= 59));
|
|
1926
|
-
}
|
|
1927
|
-
var validIANATimezoneCache = {};
|
|
1928
|
-
function isValidTimezoneIANAString(timeZoneString) {
|
|
1929
|
-
if (validIANATimezoneCache[timeZoneString])
|
|
1930
|
-
return true;
|
|
1931
|
-
try {
|
|
1932
|
-
new Intl.DateTimeFormat(undefined, { timeZone: timeZoneString });
|
|
1933
|
-
validIANATimezoneCache[timeZoneString] = true;
|
|
1934
|
-
return true;
|
|
1935
|
-
}
|
|
1936
|
-
catch (error) {
|
|
1937
|
-
return false;
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
/*
|
|
1942
|
-
<file>
|
|
1943
|
-
Project:
|
|
1944
|
-
@osovitny/anatoly
|
|
1945
|
-
|
|
1946
|
-
Authors:
|
|
1947
|
-
Vadim Osovitny vadim@osovitny.com
|
|
1948
|
-
Anatoly Osovitny anatoly@osovitny.com
|
|
1949
|
-
|
|
1950
|
-
Created:
|
|
1951
|
-
10 Feb 2024
|
|
1952
|
-
|
|
1953
|
-
Source:
|
|
1954
|
-
https://www.npmjs.com/package/date-fns-tz
|
|
1955
|
-
https://github.com/marnusw/date-fns-tz/blob/master/src/utcToZonedTime/index.js
|
|
1956
|
-
https://github.com/marnusw/date-fns-tz/blob/master/src/_lib/tzParseTimezone/index.js
|
|
1957
|
-
|
|
1958
|
-
Copyright (c) 2016-2022 Osovitny Inc. All rights reserved.
|
|
1959
|
-
</file>
|
|
1960
|
-
*/
|
|
1961
|
-
function utcToLocal(dirtyDate) {
|
|
1962
|
-
let browserTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1963
|
-
if (browserTimeZone) {
|
|
1964
|
-
let date = DateConvert.toDate(dirtyDate);
|
|
1965
|
-
let offsetMilliseconds = tzParseTimezone(browserTimeZone, date, true);
|
|
1966
|
-
let d = new Date(date.getTime() - offsetMilliseconds);
|
|
1967
|
-
let resultDate = new Date(0);
|
|
1968
|
-
resultDate.setFullYear(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
1969
|
-
resultDate.setHours(d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
|
|
1970
|
-
return resultDate;
|
|
1971
|
-
}
|
|
1972
|
-
return new Date(dirtyDate);
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
1969
|
/*
|
|
1976
1970
|
<file>
|
|
1977
1971
|
Project:
|
|
@@ -2087,15 +2081,7 @@ class LocalizationService {
|
|
|
2087
2081
|
}
|
|
2088
2082
|
let result = date;
|
|
2089
2083
|
try {
|
|
2090
|
-
|
|
2091
|
-
if (date.indexOf("T") > -1) {
|
|
2092
|
-
date = date.replace("T", " ");
|
|
2093
|
-
}
|
|
2094
|
-
if (date.indexOf("Z") == -1) {
|
|
2095
|
-
date = date + "Z";
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
let d = utcToLocal(date);
|
|
2084
|
+
let d = DateConvert.utcToLocal(date);
|
|
2099
2085
|
if (conversionFormat) {
|
|
2100
2086
|
result = format(d, conversionFormat, this.dateFnsLocale);
|
|
2101
2087
|
}
|
|
@@ -3532,7 +3518,7 @@ class ComponentBase {
|
|
|
3532
3518
|
this.title = '';
|
|
3533
3519
|
this.isTitleVisible = true;
|
|
3534
3520
|
this.isRequired = false;
|
|
3535
|
-
this.isDevMode =
|
|
3521
|
+
this.isDevMode = IsDevMode;
|
|
3536
3522
|
}
|
|
3537
3523
|
ngOnInit() {
|
|
3538
3524
|
}
|
|
@@ -7679,5 +7665,5 @@ class AnatolyModule {
|
|
|
7679
7665
|
* Generated bundle index. Do not edit.
|
|
7680
7666
|
*/
|
|
7681
7667
|
|
|
7682
|
-
export { AddressComponent, AdminGuard, Alerts, AnatolyCoreModule, AnatolyDataModule, AnatolyHttpInterceptor, AnatolyIAMModule, AnatolyIAMPagesModule, AnatolyModule, AnatolyUIModule, ApiServiceBase, ApiUrl, AppContextService, AppCoreSettings, AppName, AppSettings, AppVersion, AuthService, AuthenticationGuard, BaseGoService, Browser, BuyAccessButtonComponent, CardBodyComponent, CardComponent, CardFooterComponent, CardHeaderComponent, CheckIconComponent, ClientApps, CompanyComponent, ComponentBase, ContactUsDialog, ContactUsForm, Convert, Copy2ClipboardComponent, CoreApiService, CountryDropdownlist, DOM, DataPagerComponent, DateConvert, DefaultEditorOptions, DialogBase, DigitalMarketingService, EditComponentBase, EditPageBase, EmailsApiService, EnumEditComponentBase, FileSizePipe, FormValidationSummaryComponent, FormsHtmlEditorComponent, GlobalErrorHandler, GoogleAnalyticsService, GridEditServiceBase, GridReadServiceBase, Guid, HoveringDirective, HtmlEditorComponent, HtmlEditorComponentBase, IdleService, InjectorInstance, ItemValidationSummaryComponent, L10NUrl, ListBase, LoadingComponent, LoadingService, LocalStorageService, LocalizationInjectorInstance, LocalizationModule, LocalizationService, LocalizationSettingsModule, LocalizePipe, LoggingService, MSALUtils, NativeElementDirective, NodataComponent, NotificationService, PageBase, PageSpinnerComponent, PagedPageBase, ReplaceTextPipe, SafeHtmlPipe, SessionStorageService, SignInButtonComponent, SignOutButtonComponent, SignUpButtonComponent, StarterServiceBase, Stopwatch, Subs, SubscribePlanButtonComponent, TimezoneDropdownlist, UrlSlugComponent, Utils, ValidationSummaryComponent, XmlFormatter, dateFormats, dateTimeFormats, getAppSettingsById, getAppSettingsByName, is, localizationInitializerFactory, throwIfAlreadyLoaded, timeFormats, translateLoaderFactory };
|
|
7668
|
+
export { AddressComponent, AdminGuard, Alerts, AnatolyCoreModule, AnatolyDataModule, AnatolyHttpInterceptor, AnatolyIAMModule, AnatolyIAMPagesModule, AnatolyModule, AnatolyUIModule, ApiServiceBase, ApiUrl, AppContextService, AppCoreSettings, AppName, AppSettings, AppVersion, AuthService, AuthenticationGuard, BaseGoService, Browser, BuyAccessButtonComponent, CardBodyComponent, CardComponent, CardFooterComponent, CardHeaderComponent, CheckIconComponent, ClientApps, CompanyComponent, ComponentBase, ContactUsDialog, ContactUsForm, Convert, Copy2ClipboardComponent, CoreApiService, CountryDropdownlist, DOM, DataPagerComponent, DateConvert, DefaultEditorOptions, DialogBase, DigitalMarketingService, EditComponentBase, EditPageBase, EmailsApiService, EnumEditComponentBase, FileSizePipe, FormValidationSummaryComponent, FormsHtmlEditorComponent, GlobalErrorHandler, GoogleAnalyticsService, GridEditServiceBase, GridReadServiceBase, Guid, HoveringDirective, HtmlEditorComponent, HtmlEditorComponentBase, IdleService, InjectorInstance, IsDevMode, ItemValidationSummaryComponent, L10NUrl, ListBase, LoadingComponent, LoadingService, LocalStorageService, LocalizationInjectorInstance, LocalizationModule, LocalizationService, LocalizationSettingsModule, LocalizePipe, LoggingService, MSALUtils, NativeElementDirective, NodataComponent, NotificationService, PageBase, PageSpinnerComponent, PagedPageBase, ReplaceTextPipe, SafeHtmlPipe, SessionStorageService, SignInButtonComponent, SignOutButtonComponent, SignUpButtonComponent, StarterServiceBase, Stopwatch, Subs, SubscribePlanButtonComponent, TimezoneDropdownlist, UrlSlugComponent, Utils, ValidationSummaryComponent, XmlFormatter, dateFormats, dateTimeFormats, getAppSettingsById, getAppSettingsByName, is, localizationInitializerFactory, throwIfAlreadyLoaded, timeFormats, translateLoaderFactory };
|
|
7683
7669
|
//# sourceMappingURL=osovitny-anatoly.mjs.map
|