funda-ui 4.7.743 → 4.7.750
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/index.js +139 -12
- package/EventCalendar/index.js +139 -12
- package/EventCalendarTimeline/index.js +161 -19
- package/Utils/date.d.ts +35 -7
- package/Utils/date.js +133 -12
- package/lib/cjs/Date/index.js +139 -12
- package/lib/cjs/EventCalendar/index.js +139 -12
- package/lib/cjs/EventCalendarTimeline/index.js +161 -19
- package/lib/cjs/Utils/date.d.ts +35 -7
- package/lib/cjs/Utils/date.js +133 -12
- package/lib/esm/EventCalendarTimeline/index.tsx +22 -8
- package/lib/esm/Utils/libs/date.ts +152 -21
- package/package.json +1 -1
package/Utils/date.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the Sunday of the week of the specific date, and return to the
|
|
3
|
+
* end of January next year if it is New Year's Eve
|
|
4
|
+
* @param {Date | String} v
|
|
5
|
+
* @returns {String} yyyy-MM-dd
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* getSpecialDateEnd('2025-12-29'); // 2026-01-31
|
|
9
|
+
* getSpecialDateEnd('2025-12-17'); // 2025-12-31
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Calculates a special end date based on the week and month logic.
|
|
13
|
+
* @param v - The input date (Date object, string, or timestamp)
|
|
14
|
+
* @returns A formatted date string (YYYY-MM-DD)
|
|
15
|
+
*/
|
|
16
|
+
declare function getSpecialDateEnd(v: Date | string | number): string;
|
|
1
17
|
/**
|
|
2
18
|
* The check string contains only hours, minutes, and seconds
|
|
3
19
|
* @returns {Boolean}
|
|
@@ -213,15 +229,27 @@ declare function timestampToDate(v: number, padZeroEnabled?: boolean): string;
|
|
|
213
229
|
*/
|
|
214
230
|
declare function getMonthDates(year: number, month: number): string[];
|
|
215
231
|
/**
|
|
216
|
-
* Get
|
|
217
|
-
* @param {Number} weekOffset
|
|
218
|
-
*
|
|
232
|
+
* Get all 7 dates for a specific week starting from Sunday.
|
|
233
|
+
* * @param {Number} weekOffset - The offset of weeks from the current week.
|
|
234
|
+
* 0: Current week
|
|
235
|
+
* -1: Previous week
|
|
236
|
+
* 1: Next week
|
|
237
|
+
* @returns {Array<Date>} - An array containing 7 Date objects from Sunday to Saturday.
|
|
219
238
|
*/
|
|
220
239
|
declare function getWeekDatesFromSun(weekOffset: number): Date[];
|
|
221
240
|
/**
|
|
222
|
-
* Get
|
|
223
|
-
* @param {Number} weekOffset
|
|
224
|
-
*
|
|
241
|
+
* Get all 7 dates for a specific week starting from Monday.
|
|
242
|
+
* * @param {Number} weekOffset - The offset of weeks from the current week.
|
|
243
|
+
* 0: Current week
|
|
244
|
+
* -1: Previous week
|
|
245
|
+
* 1: Next week
|
|
246
|
+
* @returns {Array<Date>} - An array containing 7 Date objects from Monday to Sunday.
|
|
225
247
|
*/
|
|
226
248
|
declare function getWeekDatesFromMon(weekOffset: number): Date[];
|
|
227
|
-
|
|
249
|
+
/**
|
|
250
|
+
* Get the date list of the week for the specified date (starting from Monday)
|
|
251
|
+
* @param {Date | String} v - The specified date
|
|
252
|
+
* @returns {Array<Date>} - An array containing 7 Date objects
|
|
253
|
+
*/
|
|
254
|
+
declare function getWeekDatesByDate(v: Date | string | number): Date[];
|
|
255
|
+
export { getSpecialDateEnd, isTimeString, getNow, padZero, dateFormat, getDateDetails, isValidDate, isValidHours, isValidMinutesAndSeconds, isValidYear, isValidMonth, isValidDay, getLastDayInMonth, getFirstAndLastMonthDay, getCalendarDate, getFullTime, getTodayDate, getCurrentMonth, getCurrentYear, getCurrentDay, getCurrentDate, getTomorrowDate, getYesterdayDate, getNextMonthDate, getPrevMonthDate, getNextYearDate, getPrevYearDate, getSpecifiedDate, getDaysInLastMonths, setDateHours, setDateMinutes, setDateDays, timestampToDate, getMonthDates, getWeekDatesFromSun, getWeekDatesFromMon, getWeekDatesByDate };
|
package/Utils/date.js
CHANGED
|
@@ -63,9 +63,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
63
63
|
/* harmony export */ "getNow": () => (/* binding */ getNow),
|
|
64
64
|
/* harmony export */ "getPrevMonthDate": () => (/* binding */ getPrevMonthDate),
|
|
65
65
|
/* harmony export */ "getPrevYearDate": () => (/* binding */ getPrevYearDate),
|
|
66
|
+
/* harmony export */ "getSpecialDateEnd": () => (/* binding */ getSpecialDateEnd),
|
|
66
67
|
/* harmony export */ "getSpecifiedDate": () => (/* binding */ getSpecifiedDate),
|
|
67
68
|
/* harmony export */ "getTodayDate": () => (/* binding */ getTodayDate),
|
|
68
69
|
/* harmony export */ "getTomorrowDate": () => (/* binding */ getTomorrowDate),
|
|
70
|
+
/* harmony export */ "getWeekDatesByDate": () => (/* binding */ getWeekDatesByDate),
|
|
69
71
|
/* harmony export */ "getWeekDatesFromMon": () => (/* binding */ getWeekDatesFromMon),
|
|
70
72
|
/* harmony export */ "getWeekDatesFromSun": () => (/* binding */ getWeekDatesFromSun),
|
|
71
73
|
/* harmony export */ "getYesterdayDate": () => (/* binding */ getYesterdayDate),
|
|
@@ -82,6 +84,47 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
82
84
|
/* harmony export */ "setDateMinutes": () => (/* binding */ setDateMinutes),
|
|
83
85
|
/* harmony export */ "timestampToDate": () => (/* binding */ timestampToDate)
|
|
84
86
|
/* harmony export */ });
|
|
87
|
+
/**
|
|
88
|
+
* Get the Sunday of the week of the specific date, and return to the
|
|
89
|
+
* end of January next year if it is New Year's Eve
|
|
90
|
+
* @param {Date | String} v
|
|
91
|
+
* @returns {String} yyyy-MM-dd
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* getSpecialDateEnd('2025-12-29'); // 2026-01-31
|
|
95
|
+
* getSpecialDateEnd('2025-12-17'); // 2025-12-31
|
|
96
|
+
*/
|
|
97
|
+
/**
|
|
98
|
+
* Calculates a special end date based on the week and month logic.
|
|
99
|
+
* @param v - The input date (Date object, string, or timestamp)
|
|
100
|
+
* @returns A formatted date string (YYYY-MM-DD)
|
|
101
|
+
*/
|
|
102
|
+
function getSpecialDateEnd(v) {
|
|
103
|
+
// Assuming dateFormat returns a Date object based on your logic
|
|
104
|
+
var date = new Date(v);
|
|
105
|
+
|
|
106
|
+
// getWeekDatesByDate should return Date[]
|
|
107
|
+
var weekDates = getWeekDatesByDate(v);
|
|
108
|
+
var sunday = weekDates[6]; // Sunday of that week
|
|
109
|
+
|
|
110
|
+
// If Sunday of this week rolls into the next year
|
|
111
|
+
if (sunday.getFullYear() > date.getFullYear()) {
|
|
112
|
+
var year = sunday.getFullYear();
|
|
113
|
+
|
|
114
|
+
// Get the last day of January of that new year
|
|
115
|
+
// Note: month 1 in 'new Date' is February, day 0 gives the last day of Jan
|
|
116
|
+
var lastDay = new Date(year, 1, 0).getDate();
|
|
117
|
+
|
|
118
|
+
// Using template literals for the return string
|
|
119
|
+
return "".concat(year, "-01-").concat(lastDay.toString().padStart(2, '0'));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Default: Return the last day of the current month
|
|
123
|
+
// We create a date for the "0th" day of the next month to get the end of current month
|
|
124
|
+
var endOfCurrentMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
125
|
+
return getCalendarDate(endOfCurrentMonth);
|
|
126
|
+
}
|
|
127
|
+
|
|
85
128
|
/**
|
|
86
129
|
* The check string contains only hours, minutes, and seconds
|
|
87
130
|
* @returns {Boolean}
|
|
@@ -537,19 +580,40 @@ function getMonthDates(year, month) {
|
|
|
537
580
|
}
|
|
538
581
|
|
|
539
582
|
/**
|
|
540
|
-
* Get
|
|
541
|
-
* @param {Number} weekOffset
|
|
542
|
-
*
|
|
583
|
+
* Get all 7 dates for a specific week starting from Sunday.
|
|
584
|
+
* * @param {Number} weekOffset - The offset of weeks from the current week.
|
|
585
|
+
* 0: Current week
|
|
586
|
+
* -1: Previous week
|
|
587
|
+
* 1: Next week
|
|
588
|
+
* @returns {Array<Date>} - An array containing 7 Date objects from Sunday to Saturday.
|
|
543
589
|
*/
|
|
590
|
+
/*
|
|
591
|
+
// Demo 1: Get dates for the current week (Sunday Start)
|
|
592
|
+
const currentWeekSun = getWeekDatesFromSun(0);
|
|
593
|
+
console.log('Sunday (Start):', currentWeekSun[0].toLocaleDateString());
|
|
594
|
+
console.log('Saturday (End):', currentWeekSun[6].toLocaleDateString());
|
|
595
|
+
|
|
596
|
+
// Demo 2: Get the date range for the previous week
|
|
597
|
+
const lastWeek = getWeekDatesFromSun(-1);
|
|
598
|
+
const rangeStart = lastWeek[0].toISOString().split('T')[0];
|
|
599
|
+
const rangeEnd = lastWeek[6].toISOString().split('T')[0];
|
|
600
|
+
console.log(`Previous Week Range: ${rangeStart} to ${rangeEnd}`);
|
|
601
|
+
|
|
602
|
+
// Demo 3: Checking for Month/Year transitions
|
|
603
|
+
const transitionWeek = getWeekDatesFromSun(0).map(d => d.toDateString());
|
|
604
|
+
console.log('Transition Week Dates:', transitionWeek);
|
|
605
|
+
|
|
606
|
+
*/
|
|
544
607
|
function getWeekDatesFromSun(weekOffset) {
|
|
545
608
|
var dates = [];
|
|
609
|
+
// Start with a clean date (midnight) to avoid timezone/DST shifts during calculation
|
|
546
610
|
var currentDate = new Date();
|
|
611
|
+
currentDate.setHours(0, 0, 0, 0);
|
|
612
|
+
var dayOfWeek = currentDate.getDay();
|
|
547
613
|
|
|
548
|
-
//
|
|
549
|
-
|
|
614
|
+
// Move to the Sunday of the current week, then apply the week offset
|
|
615
|
+
// Formula: Current Date - Current Day Index + (Offset * 7)
|
|
550
616
|
currentDate.setDate(currentDate.getDate() - dayOfWeek + weekOffset * 7);
|
|
551
|
-
|
|
552
|
-
// Get the date of the week
|
|
553
617
|
for (var i = 0; i < 7; i++) {
|
|
554
618
|
var date = new Date(currentDate);
|
|
555
619
|
date.setDate(currentDate.getDate() + i);
|
|
@@ -559,20 +623,46 @@ function getWeekDatesFromSun(weekOffset) {
|
|
|
559
623
|
}
|
|
560
624
|
|
|
561
625
|
/**
|
|
562
|
-
* Get
|
|
563
|
-
* @param {Number} weekOffset
|
|
564
|
-
*
|
|
626
|
+
* Get all 7 dates for a specific week starting from Monday.
|
|
627
|
+
* * @param {Number} weekOffset - The offset of weeks from the current week.
|
|
628
|
+
* 0: Current week
|
|
629
|
+
* -1: Previous week
|
|
630
|
+
* 1: Next week
|
|
631
|
+
* @returns {Array<Date>} - An array containing 7 Date objects from Monday to Sunday.
|
|
565
632
|
*/
|
|
633
|
+
/*
|
|
634
|
+
// Demo 1: Get dates for the current week
|
|
635
|
+
const currentWeek = getWeekDatesFromMon(0);
|
|
636
|
+
console.log('Monday of this week:', currentWeek[0].toLocaleDateString());
|
|
637
|
+
console.log('Sunday of this week:', currentWeek[6].toLocaleDateString());
|
|
638
|
+
|
|
639
|
+
// Demo 2: Get dates for the next week
|
|
640
|
+
const nextWeek = getWeekDatesFromMon(1);
|
|
641
|
+
console.log('Monday of next week:', nextWeek[0].toLocaleDateString());
|
|
642
|
+
|
|
643
|
+
// Demo 3: Format the output as YYYY-MM-DD
|
|
644
|
+
const formattedWeek = getWeekDatesFromMon(0).map(date => {
|
|
645
|
+
const y = date.getFullYear();
|
|
646
|
+
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
647
|
+
const d = String(date.getDate()).padStart(2, '0');
|
|
648
|
+
return `${y}-${m}-${d}`;
|
|
649
|
+
});
|
|
650
|
+
console.log('Formatted Week Array:', formattedWeek);
|
|
651
|
+
// Result: ["2025-12-29", "2025-12-30", ..., "2026-01-04"]
|
|
652
|
+
*/
|
|
566
653
|
function getWeekDatesFromMon(weekOffset) {
|
|
567
654
|
var dates = [];
|
|
568
655
|
var currentDate = new Date();
|
|
569
656
|
|
|
570
|
-
//
|
|
657
|
+
// Calculate the difference to get to Monday of the current week
|
|
658
|
+
// If today is Sunday (0), we go back 6 days. Otherwise, go to (1 - currentDay).
|
|
571
659
|
var dayOfWeek = currentDate.getDay();
|
|
572
660
|
var diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
|
|
661
|
+
|
|
662
|
+
// Apply the Monday offset and the week offset (7 days per week)
|
|
573
663
|
currentDate.setDate(currentDate.getDate() + diffToMonday + weekOffset * 7);
|
|
574
664
|
|
|
575
|
-
//
|
|
665
|
+
// Generate the 7 days of the week
|
|
576
666
|
for (var i = 0; i < 7; i++) {
|
|
577
667
|
var date = new Date(currentDate);
|
|
578
668
|
date.setDate(currentDate.getDate() + i);
|
|
@@ -581,6 +671,37 @@ function getWeekDatesFromMon(weekOffset) {
|
|
|
581
671
|
return dates;
|
|
582
672
|
}
|
|
583
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Get the date list of the week for the specified date (starting from Monday)
|
|
676
|
+
* @param {Date | String} v - The specified date
|
|
677
|
+
* @returns {Array<Date>} - An array containing 7 Date objects
|
|
678
|
+
*/
|
|
679
|
+
function getWeekDatesByDate(v) {
|
|
680
|
+
var dates = [];
|
|
681
|
+
|
|
682
|
+
// Ensure we are working with a Date object.
|
|
683
|
+
// If 'dateFormat' was a custom utility in your JS, replace 'new Date(v)' with that utility.
|
|
684
|
+
var currentDate = new Date(v);
|
|
685
|
+
|
|
686
|
+
// Get the day of the week (0 for Sunday, 1 for Monday, ..., 6 for Saturday)
|
|
687
|
+
var dayOfWeek = currentDate.getDay();
|
|
688
|
+
|
|
689
|
+
// Calculate difference to Monday: if Sunday (0) subtract 6 days, otherwise subtract (day - 1)
|
|
690
|
+
var diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
|
|
691
|
+
|
|
692
|
+
// Create the Monday starting point
|
|
693
|
+
var monday = new Date(currentDate);
|
|
694
|
+
monday.setDate(currentDate.getDate() + diffToMonday);
|
|
695
|
+
|
|
696
|
+
// Generate the 7 days of the week
|
|
697
|
+
for (var i = 0; i < 7; i++) {
|
|
698
|
+
var date = new Date(monday);
|
|
699
|
+
date.setDate(monday.getDate() + i);
|
|
700
|
+
dates.push(date);
|
|
701
|
+
}
|
|
702
|
+
return dates;
|
|
703
|
+
}
|
|
704
|
+
|
|
584
705
|
/******/ return __webpack_exports__;
|
|
585
706
|
/******/ })()
|
|
586
707
|
;
|
package/lib/cjs/Date/index.js
CHANGED
|
@@ -2588,6 +2588,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2588
2588
|
return (/* binding */_getPrevYearDate
|
|
2589
2589
|
);
|
|
2590
2590
|
},
|
|
2591
|
+
/* harmony export */"getSpecialDateEnd": function getSpecialDateEnd() {
|
|
2592
|
+
return (/* binding */_getSpecialDateEnd
|
|
2593
|
+
);
|
|
2594
|
+
},
|
|
2591
2595
|
/* harmony export */"getSpecifiedDate": function getSpecifiedDate() {
|
|
2592
2596
|
return (/* binding */_getSpecifiedDate
|
|
2593
2597
|
);
|
|
@@ -2600,6 +2604,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2600
2604
|
return (/* binding */_getTomorrowDate
|
|
2601
2605
|
);
|
|
2602
2606
|
},
|
|
2607
|
+
/* harmony export */"getWeekDatesByDate": function getWeekDatesByDate() {
|
|
2608
|
+
return (/* binding */_getWeekDatesByDate
|
|
2609
|
+
);
|
|
2610
|
+
},
|
|
2603
2611
|
/* harmony export */"getWeekDatesFromMon": function getWeekDatesFromMon() {
|
|
2604
2612
|
return (/* binding */_getWeekDatesFromMon
|
|
2605
2613
|
);
|
|
@@ -2662,6 +2670,47 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2662
2670
|
}
|
|
2663
2671
|
/* harmony export */
|
|
2664
2672
|
});
|
|
2673
|
+
/**
|
|
2674
|
+
* Get the Sunday of the week of the specific date, and return to the
|
|
2675
|
+
* end of January next year if it is New Year's Eve
|
|
2676
|
+
* @param {Date | String} v
|
|
2677
|
+
* @returns {String} yyyy-MM-dd
|
|
2678
|
+
*
|
|
2679
|
+
* @example
|
|
2680
|
+
* getSpecialDateEnd('2025-12-29'); // 2026-01-31
|
|
2681
|
+
* getSpecialDateEnd('2025-12-17'); // 2025-12-31
|
|
2682
|
+
*/
|
|
2683
|
+
/**
|
|
2684
|
+
* Calculates a special end date based on the week and month logic.
|
|
2685
|
+
* @param v - The input date (Date object, string, or timestamp)
|
|
2686
|
+
* @returns A formatted date string (YYYY-MM-DD)
|
|
2687
|
+
*/
|
|
2688
|
+
function _getSpecialDateEnd(v) {
|
|
2689
|
+
// Assuming dateFormat returns a Date object based on your logic
|
|
2690
|
+
var date = new Date(v);
|
|
2691
|
+
|
|
2692
|
+
// getWeekDatesByDate should return Date[]
|
|
2693
|
+
var weekDates = _getWeekDatesByDate(v);
|
|
2694
|
+
var sunday = weekDates[6]; // Sunday of that week
|
|
2695
|
+
|
|
2696
|
+
// If Sunday of this week rolls into the next year
|
|
2697
|
+
if (sunday.getFullYear() > date.getFullYear()) {
|
|
2698
|
+
var year = sunday.getFullYear();
|
|
2699
|
+
|
|
2700
|
+
// Get the last day of January of that new year
|
|
2701
|
+
// Note: month 1 in 'new Date' is February, day 0 gives the last day of Jan
|
|
2702
|
+
var lastDay = new Date(year, 1, 0).getDate();
|
|
2703
|
+
|
|
2704
|
+
// Using template literals for the return string
|
|
2705
|
+
return "".concat(year, "-01-").concat(lastDay.toString().padStart(2, '0'));
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
// Default: Return the last day of the current month
|
|
2709
|
+
// We create a date for the "0th" day of the next month to get the end of current month
|
|
2710
|
+
var endOfCurrentMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
2711
|
+
return _getCalendarDate(endOfCurrentMonth);
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2665
2714
|
/**
|
|
2666
2715
|
* The check string contains only hours, minutes, and seconds
|
|
2667
2716
|
* @returns {Boolean}
|
|
@@ -3117,19 +3166,40 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
3117
3166
|
}
|
|
3118
3167
|
|
|
3119
3168
|
/**
|
|
3120
|
-
* Get
|
|
3121
|
-
* @param {Number} weekOffset
|
|
3122
|
-
*
|
|
3169
|
+
* Get all 7 dates for a specific week starting from Sunday.
|
|
3170
|
+
* * @param {Number} weekOffset - The offset of weeks from the current week.
|
|
3171
|
+
* 0: Current week
|
|
3172
|
+
* -1: Previous week
|
|
3173
|
+
* 1: Next week
|
|
3174
|
+
* @returns {Array<Date>} - An array containing 7 Date objects from Sunday to Saturday.
|
|
3123
3175
|
*/
|
|
3176
|
+
/*
|
|
3177
|
+
// Demo 1: Get dates for the current week (Sunday Start)
|
|
3178
|
+
const currentWeekSun = getWeekDatesFromSun(0);
|
|
3179
|
+
console.log('Sunday (Start):', currentWeekSun[0].toLocaleDateString());
|
|
3180
|
+
console.log('Saturday (End):', currentWeekSun[6].toLocaleDateString());
|
|
3181
|
+
|
|
3182
|
+
// Demo 2: Get the date range for the previous week
|
|
3183
|
+
const lastWeek = getWeekDatesFromSun(-1);
|
|
3184
|
+
const rangeStart = lastWeek[0].toISOString().split('T')[0];
|
|
3185
|
+
const rangeEnd = lastWeek[6].toISOString().split('T')[0];
|
|
3186
|
+
console.log(`Previous Week Range: ${rangeStart} to ${rangeEnd}`);
|
|
3187
|
+
|
|
3188
|
+
// Demo 3: Checking for Month/Year transitions
|
|
3189
|
+
const transitionWeek = getWeekDatesFromSun(0).map(d => d.toDateString());
|
|
3190
|
+
console.log('Transition Week Dates:', transitionWeek);
|
|
3191
|
+
|
|
3192
|
+
*/
|
|
3124
3193
|
function _getWeekDatesFromSun(weekOffset) {
|
|
3125
3194
|
var dates = [];
|
|
3195
|
+
// Start with a clean date (midnight) to avoid timezone/DST shifts during calculation
|
|
3126
3196
|
var currentDate = new Date();
|
|
3197
|
+
currentDate.setHours(0, 0, 0, 0);
|
|
3198
|
+
var dayOfWeek = currentDate.getDay();
|
|
3127
3199
|
|
|
3128
|
-
//
|
|
3129
|
-
|
|
3200
|
+
// Move to the Sunday of the current week, then apply the week offset
|
|
3201
|
+
// Formula: Current Date - Current Day Index + (Offset * 7)
|
|
3130
3202
|
currentDate.setDate(currentDate.getDate() - dayOfWeek + weekOffset * 7);
|
|
3131
|
-
|
|
3132
|
-
// Get the date of the week
|
|
3133
3203
|
for (var i = 0; i < 7; i++) {
|
|
3134
3204
|
var date = new Date(currentDate);
|
|
3135
3205
|
date.setDate(currentDate.getDate() + i);
|
|
@@ -3139,20 +3209,46 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
3139
3209
|
}
|
|
3140
3210
|
|
|
3141
3211
|
/**
|
|
3142
|
-
* Get
|
|
3143
|
-
* @param {Number} weekOffset
|
|
3144
|
-
*
|
|
3212
|
+
* Get all 7 dates for a specific week starting from Monday.
|
|
3213
|
+
* * @param {Number} weekOffset - The offset of weeks from the current week.
|
|
3214
|
+
* 0: Current week
|
|
3215
|
+
* -1: Previous week
|
|
3216
|
+
* 1: Next week
|
|
3217
|
+
* @returns {Array<Date>} - An array containing 7 Date objects from Monday to Sunday.
|
|
3145
3218
|
*/
|
|
3219
|
+
/*
|
|
3220
|
+
// Demo 1: Get dates for the current week
|
|
3221
|
+
const currentWeek = getWeekDatesFromMon(0);
|
|
3222
|
+
console.log('Monday of this week:', currentWeek[0].toLocaleDateString());
|
|
3223
|
+
console.log('Sunday of this week:', currentWeek[6].toLocaleDateString());
|
|
3224
|
+
|
|
3225
|
+
// Demo 2: Get dates for the next week
|
|
3226
|
+
const nextWeek = getWeekDatesFromMon(1);
|
|
3227
|
+
console.log('Monday of next week:', nextWeek[0].toLocaleDateString());
|
|
3228
|
+
|
|
3229
|
+
// Demo 3: Format the output as YYYY-MM-DD
|
|
3230
|
+
const formattedWeek = getWeekDatesFromMon(0).map(date => {
|
|
3231
|
+
const y = date.getFullYear();
|
|
3232
|
+
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
3233
|
+
const d = String(date.getDate()).padStart(2, '0');
|
|
3234
|
+
return `${y}-${m}-${d}`;
|
|
3235
|
+
});
|
|
3236
|
+
console.log('Formatted Week Array:', formattedWeek);
|
|
3237
|
+
// Result: ["2025-12-29", "2025-12-30", ..., "2026-01-04"]
|
|
3238
|
+
*/
|
|
3146
3239
|
function _getWeekDatesFromMon(weekOffset) {
|
|
3147
3240
|
var dates = [];
|
|
3148
3241
|
var currentDate = new Date();
|
|
3149
3242
|
|
|
3150
|
-
//
|
|
3243
|
+
// Calculate the difference to get to Monday of the current week
|
|
3244
|
+
// If today is Sunday (0), we go back 6 days. Otherwise, go to (1 - currentDay).
|
|
3151
3245
|
var dayOfWeek = currentDate.getDay();
|
|
3152
3246
|
var diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
|
|
3247
|
+
|
|
3248
|
+
// Apply the Monday offset and the week offset (7 days per week)
|
|
3153
3249
|
currentDate.setDate(currentDate.getDate() + diffToMonday + weekOffset * 7);
|
|
3154
3250
|
|
|
3155
|
-
//
|
|
3251
|
+
// Generate the 7 days of the week
|
|
3156
3252
|
for (var i = 0; i < 7; i++) {
|
|
3157
3253
|
var date = new Date(currentDate);
|
|
3158
3254
|
date.setDate(currentDate.getDate() + i);
|
|
@@ -3161,6 +3257,37 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
3161
3257
|
return dates;
|
|
3162
3258
|
}
|
|
3163
3259
|
|
|
3260
|
+
/**
|
|
3261
|
+
* Get the date list of the week for the specified date (starting from Monday)
|
|
3262
|
+
* @param {Date | String} v - The specified date
|
|
3263
|
+
* @returns {Array<Date>} - An array containing 7 Date objects
|
|
3264
|
+
*/
|
|
3265
|
+
function _getWeekDatesByDate(v) {
|
|
3266
|
+
var dates = [];
|
|
3267
|
+
|
|
3268
|
+
// Ensure we are working with a Date object.
|
|
3269
|
+
// If 'dateFormat' was a custom utility in your JS, replace 'new Date(v)' with that utility.
|
|
3270
|
+
var currentDate = new Date(v);
|
|
3271
|
+
|
|
3272
|
+
// Get the day of the week (0 for Sunday, 1 for Monday, ..., 6 for Saturday)
|
|
3273
|
+
var dayOfWeek = currentDate.getDay();
|
|
3274
|
+
|
|
3275
|
+
// Calculate difference to Monday: if Sunday (0) subtract 6 days, otherwise subtract (day - 1)
|
|
3276
|
+
var diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
|
|
3277
|
+
|
|
3278
|
+
// Create the Monday starting point
|
|
3279
|
+
var monday = new Date(currentDate);
|
|
3280
|
+
monday.setDate(currentDate.getDate() + diffToMonday);
|
|
3281
|
+
|
|
3282
|
+
// Generate the 7 days of the week
|
|
3283
|
+
for (var i = 0; i < 7; i++) {
|
|
3284
|
+
var date = new Date(monday);
|
|
3285
|
+
date.setDate(monday.getDate() + i);
|
|
3286
|
+
dates.push(date);
|
|
3287
|
+
}
|
|
3288
|
+
return dates;
|
|
3289
|
+
}
|
|
3290
|
+
|
|
3164
3291
|
/******/
|
|
3165
3292
|
return __webpack_exports__;
|
|
3166
3293
|
/******/
|
|
@@ -2216,6 +2216,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2216
2216
|
return (/* binding */_getPrevYearDate
|
|
2217
2217
|
);
|
|
2218
2218
|
},
|
|
2219
|
+
/* harmony export */"getSpecialDateEnd": function getSpecialDateEnd() {
|
|
2220
|
+
return (/* binding */_getSpecialDateEnd
|
|
2221
|
+
);
|
|
2222
|
+
},
|
|
2219
2223
|
/* harmony export */"getSpecifiedDate": function getSpecifiedDate() {
|
|
2220
2224
|
return (/* binding */_getSpecifiedDate
|
|
2221
2225
|
);
|
|
@@ -2228,6 +2232,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2228
2232
|
return (/* binding */_getTomorrowDate
|
|
2229
2233
|
);
|
|
2230
2234
|
},
|
|
2235
|
+
/* harmony export */"getWeekDatesByDate": function getWeekDatesByDate() {
|
|
2236
|
+
return (/* binding */_getWeekDatesByDate
|
|
2237
|
+
);
|
|
2238
|
+
},
|
|
2231
2239
|
/* harmony export */"getWeekDatesFromMon": function getWeekDatesFromMon() {
|
|
2232
2240
|
return (/* binding */_getWeekDatesFromMon
|
|
2233
2241
|
);
|
|
@@ -2290,6 +2298,47 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2290
2298
|
}
|
|
2291
2299
|
/* harmony export */
|
|
2292
2300
|
});
|
|
2301
|
+
/**
|
|
2302
|
+
* Get the Sunday of the week of the specific date, and return to the
|
|
2303
|
+
* end of January next year if it is New Year's Eve
|
|
2304
|
+
* @param {Date | String} v
|
|
2305
|
+
* @returns {String} yyyy-MM-dd
|
|
2306
|
+
*
|
|
2307
|
+
* @example
|
|
2308
|
+
* getSpecialDateEnd('2025-12-29'); // 2026-01-31
|
|
2309
|
+
* getSpecialDateEnd('2025-12-17'); // 2025-12-31
|
|
2310
|
+
*/
|
|
2311
|
+
/**
|
|
2312
|
+
* Calculates a special end date based on the week and month logic.
|
|
2313
|
+
* @param v - The input date (Date object, string, or timestamp)
|
|
2314
|
+
* @returns A formatted date string (YYYY-MM-DD)
|
|
2315
|
+
*/
|
|
2316
|
+
function _getSpecialDateEnd(v) {
|
|
2317
|
+
// Assuming dateFormat returns a Date object based on your logic
|
|
2318
|
+
var date = new Date(v);
|
|
2319
|
+
|
|
2320
|
+
// getWeekDatesByDate should return Date[]
|
|
2321
|
+
var weekDates = _getWeekDatesByDate(v);
|
|
2322
|
+
var sunday = weekDates[6]; // Sunday of that week
|
|
2323
|
+
|
|
2324
|
+
// If Sunday of this week rolls into the next year
|
|
2325
|
+
if (sunday.getFullYear() > date.getFullYear()) {
|
|
2326
|
+
var year = sunday.getFullYear();
|
|
2327
|
+
|
|
2328
|
+
// Get the last day of January of that new year
|
|
2329
|
+
// Note: month 1 in 'new Date' is February, day 0 gives the last day of Jan
|
|
2330
|
+
var lastDay = new Date(year, 1, 0).getDate();
|
|
2331
|
+
|
|
2332
|
+
// Using template literals for the return string
|
|
2333
|
+
return "".concat(year, "-01-").concat(lastDay.toString().padStart(2, '0'));
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// Default: Return the last day of the current month
|
|
2337
|
+
// We create a date for the "0th" day of the next month to get the end of current month
|
|
2338
|
+
var endOfCurrentMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
2339
|
+
return _getCalendarDate(endOfCurrentMonth);
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2293
2342
|
/**
|
|
2294
2343
|
* The check string contains only hours, minutes, and seconds
|
|
2295
2344
|
* @returns {Boolean}
|
|
@@ -2745,19 +2794,40 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2745
2794
|
}
|
|
2746
2795
|
|
|
2747
2796
|
/**
|
|
2748
|
-
* Get
|
|
2749
|
-
* @param {Number} weekOffset
|
|
2750
|
-
*
|
|
2797
|
+
* Get all 7 dates for a specific week starting from Sunday.
|
|
2798
|
+
* * @param {Number} weekOffset - The offset of weeks from the current week.
|
|
2799
|
+
* 0: Current week
|
|
2800
|
+
* -1: Previous week
|
|
2801
|
+
* 1: Next week
|
|
2802
|
+
* @returns {Array<Date>} - An array containing 7 Date objects from Sunday to Saturday.
|
|
2751
2803
|
*/
|
|
2804
|
+
/*
|
|
2805
|
+
// Demo 1: Get dates for the current week (Sunday Start)
|
|
2806
|
+
const currentWeekSun = getWeekDatesFromSun(0);
|
|
2807
|
+
console.log('Sunday (Start):', currentWeekSun[0].toLocaleDateString());
|
|
2808
|
+
console.log('Saturday (End):', currentWeekSun[6].toLocaleDateString());
|
|
2809
|
+
|
|
2810
|
+
// Demo 2: Get the date range for the previous week
|
|
2811
|
+
const lastWeek = getWeekDatesFromSun(-1);
|
|
2812
|
+
const rangeStart = lastWeek[0].toISOString().split('T')[0];
|
|
2813
|
+
const rangeEnd = lastWeek[6].toISOString().split('T')[0];
|
|
2814
|
+
console.log(`Previous Week Range: ${rangeStart} to ${rangeEnd}`);
|
|
2815
|
+
|
|
2816
|
+
// Demo 3: Checking for Month/Year transitions
|
|
2817
|
+
const transitionWeek = getWeekDatesFromSun(0).map(d => d.toDateString());
|
|
2818
|
+
console.log('Transition Week Dates:', transitionWeek);
|
|
2819
|
+
|
|
2820
|
+
*/
|
|
2752
2821
|
function _getWeekDatesFromSun(weekOffset) {
|
|
2753
2822
|
var dates = [];
|
|
2823
|
+
// Start with a clean date (midnight) to avoid timezone/DST shifts during calculation
|
|
2754
2824
|
var currentDate = new Date();
|
|
2825
|
+
currentDate.setHours(0, 0, 0, 0);
|
|
2826
|
+
var dayOfWeek = currentDate.getDay();
|
|
2755
2827
|
|
|
2756
|
-
//
|
|
2757
|
-
|
|
2828
|
+
// Move to the Sunday of the current week, then apply the week offset
|
|
2829
|
+
// Formula: Current Date - Current Day Index + (Offset * 7)
|
|
2758
2830
|
currentDate.setDate(currentDate.getDate() - dayOfWeek + weekOffset * 7);
|
|
2759
|
-
|
|
2760
|
-
// Get the date of the week
|
|
2761
2831
|
for (var i = 0; i < 7; i++) {
|
|
2762
2832
|
var date = new Date(currentDate);
|
|
2763
2833
|
date.setDate(currentDate.getDate() + i);
|
|
@@ -2767,20 +2837,46 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2767
2837
|
}
|
|
2768
2838
|
|
|
2769
2839
|
/**
|
|
2770
|
-
* Get
|
|
2771
|
-
* @param {Number} weekOffset
|
|
2772
|
-
*
|
|
2840
|
+
* Get all 7 dates for a specific week starting from Monday.
|
|
2841
|
+
* * @param {Number} weekOffset - The offset of weeks from the current week.
|
|
2842
|
+
* 0: Current week
|
|
2843
|
+
* -1: Previous week
|
|
2844
|
+
* 1: Next week
|
|
2845
|
+
* @returns {Array<Date>} - An array containing 7 Date objects from Monday to Sunday.
|
|
2773
2846
|
*/
|
|
2847
|
+
/*
|
|
2848
|
+
// Demo 1: Get dates for the current week
|
|
2849
|
+
const currentWeek = getWeekDatesFromMon(0);
|
|
2850
|
+
console.log('Monday of this week:', currentWeek[0].toLocaleDateString());
|
|
2851
|
+
console.log('Sunday of this week:', currentWeek[6].toLocaleDateString());
|
|
2852
|
+
|
|
2853
|
+
// Demo 2: Get dates for the next week
|
|
2854
|
+
const nextWeek = getWeekDatesFromMon(1);
|
|
2855
|
+
console.log('Monday of next week:', nextWeek[0].toLocaleDateString());
|
|
2856
|
+
|
|
2857
|
+
// Demo 3: Format the output as YYYY-MM-DD
|
|
2858
|
+
const formattedWeek = getWeekDatesFromMon(0).map(date => {
|
|
2859
|
+
const y = date.getFullYear();
|
|
2860
|
+
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
2861
|
+
const d = String(date.getDate()).padStart(2, '0');
|
|
2862
|
+
return `${y}-${m}-${d}`;
|
|
2863
|
+
});
|
|
2864
|
+
console.log('Formatted Week Array:', formattedWeek);
|
|
2865
|
+
// Result: ["2025-12-29", "2025-12-30", ..., "2026-01-04"]
|
|
2866
|
+
*/
|
|
2774
2867
|
function _getWeekDatesFromMon(weekOffset) {
|
|
2775
2868
|
var dates = [];
|
|
2776
2869
|
var currentDate = new Date();
|
|
2777
2870
|
|
|
2778
|
-
//
|
|
2871
|
+
// Calculate the difference to get to Monday of the current week
|
|
2872
|
+
// If today is Sunday (0), we go back 6 days. Otherwise, go to (1 - currentDay).
|
|
2779
2873
|
var dayOfWeek = currentDate.getDay();
|
|
2780
2874
|
var diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
|
|
2875
|
+
|
|
2876
|
+
// Apply the Monday offset and the week offset (7 days per week)
|
|
2781
2877
|
currentDate.setDate(currentDate.getDate() + diffToMonday + weekOffset * 7);
|
|
2782
2878
|
|
|
2783
|
-
//
|
|
2879
|
+
// Generate the 7 days of the week
|
|
2784
2880
|
for (var i = 0; i < 7; i++) {
|
|
2785
2881
|
var date = new Date(currentDate);
|
|
2786
2882
|
date.setDate(currentDate.getDate() + i);
|
|
@@ -2789,6 +2885,37 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
2789
2885
|
return dates;
|
|
2790
2886
|
}
|
|
2791
2887
|
|
|
2888
|
+
/**
|
|
2889
|
+
* Get the date list of the week for the specified date (starting from Monday)
|
|
2890
|
+
* @param {Date | String} v - The specified date
|
|
2891
|
+
* @returns {Array<Date>} - An array containing 7 Date objects
|
|
2892
|
+
*/
|
|
2893
|
+
function _getWeekDatesByDate(v) {
|
|
2894
|
+
var dates = [];
|
|
2895
|
+
|
|
2896
|
+
// Ensure we are working with a Date object.
|
|
2897
|
+
// If 'dateFormat' was a custom utility in your JS, replace 'new Date(v)' with that utility.
|
|
2898
|
+
var currentDate = new Date(v);
|
|
2899
|
+
|
|
2900
|
+
// Get the day of the week (0 for Sunday, 1 for Monday, ..., 6 for Saturday)
|
|
2901
|
+
var dayOfWeek = currentDate.getDay();
|
|
2902
|
+
|
|
2903
|
+
// Calculate difference to Monday: if Sunday (0) subtract 6 days, otherwise subtract (day - 1)
|
|
2904
|
+
var diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
|
|
2905
|
+
|
|
2906
|
+
// Create the Monday starting point
|
|
2907
|
+
var monday = new Date(currentDate);
|
|
2908
|
+
monday.setDate(currentDate.getDate() + diffToMonday);
|
|
2909
|
+
|
|
2910
|
+
// Generate the 7 days of the week
|
|
2911
|
+
for (var i = 0; i < 7; i++) {
|
|
2912
|
+
var date = new Date(monday);
|
|
2913
|
+
date.setDate(monday.getDate() + i);
|
|
2914
|
+
dates.push(date);
|
|
2915
|
+
}
|
|
2916
|
+
return dates;
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2792
2919
|
/******/
|
|
2793
2920
|
return __webpack_exports__;
|
|
2794
2921
|
/******/
|