@acorex/core 20.2.0-next.5 → 20.2.0-next.8
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
@@ -278,7 +278,7 @@ declare class AXTimeDurationFormatter implements AXFormatter {
|
|
278
278
|
get name(): string;
|
279
279
|
format(value: number, options?: AXTimeDurationFormatterOptions): string;
|
280
280
|
translationService: AXTranslationService;
|
281
|
-
millisecondsToMask(ms: number, startUnit?: AXTimeDurationUnit, endUnit?: AXTimeDurationUnit, label?: boolean): Promise<string>;
|
281
|
+
millisecondsToMask(ms: number, startUnit?: AXTimeDurationUnit, endUnit?: AXTimeDurationUnit, label?: boolean, maskDigits?: string, padZero?: boolean): Promise<string>;
|
282
282
|
static ɵfac: i0.ɵɵFactoryDeclaration<AXTimeDurationFormatter, never>;
|
283
283
|
static ɵprov: i0.ɵɵInjectableDeclaration<AXTimeDurationFormatter>;
|
284
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', label = false) {
|
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,37 +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
|
-
else {
|
1468
|
-
return label ? `${count} (${unit.label})` : `${count}`;
|
1469
|
-
}
|
1470
|
-
}
|
1471
|
-
else {
|
1472
|
-
// For other units, pad with one zero if less than 10
|
1473
|
-
const paddedCount = count < 10 ? `0${count}` : `${count}`;
|
1474
|
-
return label ? `${paddedCount} (${unit.label})` : `${paddedCount}`;
|
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;
|
1475
1479
|
}
|
1476
|
-
|
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 ? ' : ' : ':';
|
1477
1488
|
if (label) {
|
1478
1489
|
if (this.translationService.getActiveLang() === 'fa-IR') {
|
1479
|
-
return result.reverse().join(
|
1490
|
+
return result.reverse().join(reverseSeparator);
|
1480
1491
|
}
|
1481
1492
|
else {
|
1482
|
-
return result.join(
|
1493
|
+
return result.join(separator);
|
1483
1494
|
}
|
1484
1495
|
}
|
1485
1496
|
else {
|
1486
|
-
return result.join(
|
1497
|
+
return result.join(separator);
|
1487
1498
|
}
|
1488
1499
|
}
|
1489
1500
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXTimeDurationFormatter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|