@acorex/core 20.2.0-next.0 → 20.2.0-next.10
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/date-time/index.d.ts
CHANGED
@@ -188,6 +188,7 @@ declare class AXDateTimeFormatter implements AXFormatter {
|
|
188
188
|
interface AXHolidayDate {
|
189
189
|
date: Date;
|
190
190
|
title: string;
|
191
|
+
cssClass?: string;
|
191
192
|
description?: string;
|
192
193
|
[key: string]: unknown;
|
193
194
|
}
|
@@ -277,7 +278,7 @@ declare class AXTimeDurationFormatter implements AXFormatter {
|
|
277
278
|
get name(): string;
|
278
279
|
format(value: number, options?: AXTimeDurationFormatterOptions): string;
|
279
280
|
translationService: AXTranslationService;
|
280
|
-
millisecondsToMask(ms: number, startUnit?: AXTimeDurationUnit, endUnit?: AXTimeDurationUnit): Promise<string>;
|
281
|
+
millisecondsToMask(ms: number, startUnit?: AXTimeDurationUnit, endUnit?: AXTimeDurationUnit, label?: boolean, maskDigits?: string, padZero?: boolean): Promise<string>;
|
281
282
|
static ɵfac: i0.ɵɵFactoryDeclaration<AXTimeDurationFormatter, never>;
|
282
283
|
static ɵprov: i0.ɵɵInjectableDeclaration<AXTimeDurationFormatter>;
|
283
284
|
}
|
@@ -1424,9 +1424,17 @@ class AXTimeDurationFormatter {
|
|
1424
1424
|
// Join the parts according to the format
|
1425
1425
|
return formattedTime.join(format.includes('ms') || format.includes('MS') ? ':' : ':');
|
1426
1426
|
}
|
1427
|
-
async millisecondsToMask(ms, startUnit = 'YEAR', endUnit = 'MILLISECOND') {
|
1427
|
+
async millisecondsToMask(ms, startUnit = 'YEAR', endUnit = 'MILLISECOND', label = false, maskDigits = '00:00:00:00:00:00:00:000', padZero = false) {
|
1428
1428
|
if (ms <= 0)
|
1429
1429
|
return '';
|
1430
|
+
const yearDigits = maskDigits.split(':')[0];
|
1431
|
+
const monthDigits = maskDigits.split(':')[1];
|
1432
|
+
const weekDigits = maskDigits.split(':')[2];
|
1433
|
+
const dayDigits = maskDigits.split(':')[3];
|
1434
|
+
const hourDigits = maskDigits.split(':')[4];
|
1435
|
+
const minuteDigits = maskDigits.split(':')[5];
|
1436
|
+
const secondDigits = maskDigits.split(':')[6];
|
1437
|
+
const millisecondDigits = maskDigits.split(':')[7];
|
1430
1438
|
const translations = await Promise.all([
|
1431
1439
|
this.translationService.translateAsync('@acorex:dateTime.units.year'),
|
1432
1440
|
this.translationService.translateAsync('@acorex:dateTime.units.month'),
|
@@ -1438,14 +1446,19 @@ class AXTimeDurationFormatter {
|
|
1438
1446
|
this.translationService.translateAsync('@acorex:dateTime.units.millisecond'),
|
1439
1447
|
]);
|
1440
1448
|
const units = [
|
1441
|
-
{ key: 'YEAR', label: translations[0].toLocaleUpperCase(), value: 1000 * 60 * 60 * 24 * 365 },
|
1442
|
-
{
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
{ key: '
|
1449
|
+
{ key: 'YEAR', label: translations[0].toLocaleUpperCase(), value: 1000 * 60 * 60 * 24 * 365, digits: yearDigits },
|
1450
|
+
{
|
1451
|
+
key: 'MONTH',
|
1452
|
+
label: translations[1].toLocaleUpperCase(),
|
1453
|
+
value: 1000 * 60 * 60 * 24 * 30,
|
1454
|
+
digits: monthDigits,
|
1455
|
+
},
|
1456
|
+
{ key: 'WEEK', label: translations[2].toLocaleUpperCase(), value: 1000 * 60 * 60 * 24 * 7, digits: weekDigits },
|
1457
|
+
{ key: 'DAY', label: translations[3].toLocaleUpperCase(), value: 1000 * 60 * 60 * 24, digits: dayDigits },
|
1458
|
+
{ key: 'HOUR', label: translations[4].toLocaleUpperCase(), value: 1000 * 60 * 60, digits: hourDigits },
|
1459
|
+
{ key: 'MINUTE', label: translations[5].toLocaleUpperCase(), value: 1000 * 60, digits: minuteDigits },
|
1460
|
+
{ key: 'SECOND', label: translations[6].toLocaleUpperCase(), value: 1000, digits: secondDigits },
|
1461
|
+
{ key: 'MILLISECOND', label: translations[7].toLocaleUpperCase(), value: 1, digits: millisecondDigits },
|
1449
1462
|
];
|
1450
1463
|
const startIndex = units.findIndex((u) => u.key === startUnit.toUpperCase());
|
1451
1464
|
const endIndex = units.findIndex((u) => u.key === endUnit.toUpperCase());
|
@@ -1453,32 +1466,35 @@ class AXTimeDurationFormatter {
|
|
1453
1466
|
throw new Error('Invalid time unit range');
|
1454
1467
|
}
|
1455
1468
|
const limitedUnits = units.slice(startIndex, endIndex + 1);
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
}
|
1469
|
+
let remainingMs = ms;
|
1470
|
+
const result = [];
|
1471
|
+
for (let i = 0; i < limitedUnits.length; i++) {
|
1472
|
+
const unit = limitedUnits[i];
|
1473
|
+
const maxValue = Math.pow(10, unit.digits.length) - 1;
|
1474
|
+
let unitValue = 0;
|
1475
|
+
if (remainingMs >= unit.value) {
|
1476
|
+
// Calculate how much of this unit we can fill
|
1477
|
+
unitValue = Math.min(Math.floor(remainingMs / unit.value), maxValue);
|
1478
|
+
remainingMs -= unitValue * unit.value;
|
1479
|
+
}
|
1480
|
+
// Always add all units to result, even if value is zero
|
1481
|
+
const displayValue = label
|
1482
|
+
? `${padZero ? unitValue.toString().padStart(unit.digits.length, '0') : unitValue} (${unit.label})`
|
1483
|
+
: `${padZero ? unitValue.toString().padStart(unit.digits.length, '0') : unitValue}`;
|
1484
|
+
result.push(displayValue);
|
1485
|
+
}
|
1486
|
+
const separator = label ? ' : ' : ':';
|
1487
|
+
const reverseSeparator = label ? ' : ' : ':';
|
1488
|
+
if (label) {
|
1489
|
+
if (this.translationService.getActiveLang() === 'fa-IR') {
|
1490
|
+
return result.reverse().join(reverseSeparator);
|
1470
1491
|
}
|
1471
1492
|
else {
|
1472
|
-
|
1473
|
-
const paddedCount = count < 10 ? `0${count}` : `${count}`;
|
1474
|
-
return `${paddedCount} (${unit.label})`;
|
1493
|
+
return result.join(separator);
|
1475
1494
|
}
|
1476
|
-
});
|
1477
|
-
if (this.translationService.getActiveLang() === 'fa-IR') {
|
1478
|
-
return result.reverse().join(' : ');
|
1479
1495
|
}
|
1480
1496
|
else {
|
1481
|
-
return result.join(
|
1497
|
+
return result.join(separator);
|
1482
1498
|
}
|
1483
1499
|
}
|
1484
1500
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXTimeDurationFormatter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|