@shival99/z-ui 2.0.27 → 2.0.28
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.
|
@@ -1563,19 +1563,51 @@ class ZCalendarComponent {
|
|
|
1563
1563
|
if (this.isRangeMode()) {
|
|
1564
1564
|
if (typeof value === 'object' && 'start' in value && 'end' in value) {
|
|
1565
1565
|
const range = value;
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1566
|
+
let start = null;
|
|
1567
|
+
let end = null;
|
|
1568
|
+
const valStart = range['start'];
|
|
1569
|
+
const valEnd = range['end'];
|
|
1570
|
+
// Tự động phân tích giá trị start nếu là chuỗi ISO hoặc định dạng thông thường
|
|
1571
|
+
if (valStart instanceof Date) {
|
|
1572
|
+
start = valStart;
|
|
1573
|
+
}
|
|
1574
|
+
if (typeof valStart === 'string') {
|
|
1575
|
+
const isIsoLike = /^\d{4}-\d{2}-\d{2}/.test(valStart);
|
|
1576
|
+
start =
|
|
1577
|
+
valueType === 'iso' || isIsoLike
|
|
1578
|
+
? fromISOString(valStart)
|
|
1579
|
+
: parseDate(valStart, this.zFormat(), this.zLocale());
|
|
1580
|
+
if (isIsoLike && (!start || isNaN(start.getTime()))) {
|
|
1581
|
+
start = parseDate(valStart, this.zFormat(), this.zLocale());
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
// Tự động phân tích giá trị end nếu là chuỗi ISO hoặc định dạng thông thường
|
|
1585
|
+
if (valEnd instanceof Date) {
|
|
1586
|
+
end = valEnd;
|
|
1587
|
+
}
|
|
1588
|
+
if (typeof valEnd === 'string') {
|
|
1589
|
+
const isIsoLike = /^\d{4}-\d{2}-\d{2}/.test(valEnd);
|
|
1590
|
+
end =
|
|
1591
|
+
valueType === 'iso' || isIsoLike
|
|
1592
|
+
? fromISOString(valEnd)
|
|
1593
|
+
: parseDate(valEnd, this.zFormat(), this.zLocale());
|
|
1594
|
+
if (isIsoLike && (!end || isNaN(end.getTime()))) {
|
|
1595
|
+
end = parseDate(valEnd, this.zFormat(), this.zLocale());
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
this._rangeStart.set(start);
|
|
1599
|
+
this._rangeEnd.set(end);
|
|
1600
|
+
if (start && end) {
|
|
1601
|
+
this._currentMonth.set(start);
|
|
1602
|
+
this._endMonth.set(isSameMonth(start, end) ? addMonths(end, 1) : end);
|
|
1571
1603
|
if (!this.shortDisplayPresetKey()) {
|
|
1572
|
-
const presetKey = this._detectMatchingPreset(
|
|
1604
|
+
const presetKey = this._detectMatchingPreset(start, end);
|
|
1573
1605
|
this.activePresetKey.set(presetKey);
|
|
1574
1606
|
this.shortDisplayPresetKey.set(this.zShortTime() && presetKey !== 'custom' ? presetKey : null);
|
|
1575
1607
|
}
|
|
1576
1608
|
if (this.zShowTime()) {
|
|
1577
|
-
this._syncTimeSignals(
|
|
1578
|
-
this._syncEndTimeSignals(
|
|
1609
|
+
this._syncTimeSignals(start);
|
|
1610
|
+
this._syncEndTimeSignals(end);
|
|
1579
1611
|
}
|
|
1580
1612
|
}
|
|
1581
1613
|
else {
|
|
@@ -1589,8 +1621,13 @@ class ZCalendarComponent {
|
|
|
1589
1621
|
if (value instanceof Date) {
|
|
1590
1622
|
date = value;
|
|
1591
1623
|
}
|
|
1624
|
+
// Tự động phân tích chuỗi ISO của single mode (hữu ích khi nhận giá trị thô từ API)
|
|
1592
1625
|
if (!date && typeof value === 'string') {
|
|
1593
|
-
|
|
1626
|
+
const isIsoLike = /^\d{4}-\d{2}-\d{2}/.test(value);
|
|
1627
|
+
date = valueType === 'iso' || isIsoLike ? fromISOString(value) : parseDate(value, this.zFormat(), this.zLocale());
|
|
1628
|
+
if (isIsoLike && (!date || isNaN(date.getTime()))) {
|
|
1629
|
+
date = parseDate(value, this.zFormat(), this.zLocale());
|
|
1630
|
+
}
|
|
1594
1631
|
}
|
|
1595
1632
|
if (!date) {
|
|
1596
1633
|
return;
|
|
@@ -2973,14 +3010,15 @@ class ZCalendarComponent {
|
|
|
2973
3010
|
this.period.set(date.getHours() >= 12 ? 'PM' : 'AM');
|
|
2974
3011
|
}
|
|
2975
3012
|
_getParseFormat() {
|
|
2976
|
-
if (!this.zShowTime() && !this.isTimeMode()) {
|
|
2977
|
-
return this.zFormat();
|
|
2978
|
-
}
|
|
2979
|
-
const timeFormat = this._buildTimeFormat();
|
|
2980
3013
|
if (this.isTimeMode()) {
|
|
2981
|
-
return
|
|
3014
|
+
return this._buildTimeFormat();
|
|
3015
|
+
}
|
|
3016
|
+
const format = this.zFormat();
|
|
3017
|
+
const formatHasTime = hasTimeTokens(format);
|
|
3018
|
+
if (this.zShowTime() && !formatHasTime) {
|
|
3019
|
+
return `${format} ${this._buildTimeFormat()}`;
|
|
2982
3020
|
}
|
|
2983
|
-
return
|
|
3021
|
+
return format;
|
|
2984
3022
|
}
|
|
2985
3023
|
_buildTimeFormat(period) {
|
|
2986
3024
|
return buildTimeFormat(this.zShowHour(), this.zShowMinute(), this.zShowSecond(), this.zTimeFormat(), period);
|