funda-ui 4.7.740 → 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.
@@ -2418,6 +2418,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2418
2418
  return (/* binding */_getPrevYearDate
2419
2419
  );
2420
2420
  },
2421
+ /* harmony export */"getSpecialDateEnd": function getSpecialDateEnd() {
2422
+ return (/* binding */_getSpecialDateEnd
2423
+ );
2424
+ },
2421
2425
  /* harmony export */"getSpecifiedDate": function getSpecifiedDate() {
2422
2426
  return (/* binding */_getSpecifiedDate
2423
2427
  );
@@ -2430,6 +2434,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2430
2434
  return (/* binding */_getTomorrowDate
2431
2435
  );
2432
2436
  },
2437
+ /* harmony export */"getWeekDatesByDate": function getWeekDatesByDate() {
2438
+ return (/* binding */_getWeekDatesByDate
2439
+ );
2440
+ },
2433
2441
  /* harmony export */"getWeekDatesFromMon": function getWeekDatesFromMon() {
2434
2442
  return (/* binding */_getWeekDatesFromMon
2435
2443
  );
@@ -2492,6 +2500,47 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2492
2500
  }
2493
2501
  /* harmony export */
2494
2502
  });
2503
+ /**
2504
+ * Get the Sunday of the week of the specific date, and return to the
2505
+ * end of January next year if it is New Year's Eve
2506
+ * @param {Date | String} v
2507
+ * @returns {String} yyyy-MM-dd
2508
+ *
2509
+ * @example
2510
+ * getSpecialDateEnd('2025-12-29'); // 2026-01-31
2511
+ * getSpecialDateEnd('2025-12-17'); // 2025-12-31
2512
+ */
2513
+ /**
2514
+ * Calculates a special end date based on the week and month logic.
2515
+ * @param v - The input date (Date object, string, or timestamp)
2516
+ * @returns A formatted date string (YYYY-MM-DD)
2517
+ */
2518
+ function _getSpecialDateEnd(v) {
2519
+ // Assuming dateFormat returns a Date object based on your logic
2520
+ var date = new Date(v);
2521
+
2522
+ // getWeekDatesByDate should return Date[]
2523
+ var weekDates = _getWeekDatesByDate(v);
2524
+ var sunday = weekDates[6]; // Sunday of that week
2525
+
2526
+ // If Sunday of this week rolls into the next year
2527
+ if (sunday.getFullYear() > date.getFullYear()) {
2528
+ var year = sunday.getFullYear();
2529
+
2530
+ // Get the last day of January of that new year
2531
+ // Note: month 1 in 'new Date' is February, day 0 gives the last day of Jan
2532
+ var lastDay = new Date(year, 1, 0).getDate();
2533
+
2534
+ // Using template literals for the return string
2535
+ return "".concat(year, "-01-").concat(lastDay.toString().padStart(2, '0'));
2536
+ }
2537
+
2538
+ // Default: Return the last day of the current month
2539
+ // We create a date for the "0th" day of the next month to get the end of current month
2540
+ var endOfCurrentMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
2541
+ return _getCalendarDate(endOfCurrentMonth);
2542
+ }
2543
+
2495
2544
  /**
2496
2545
  * The check string contains only hours, minutes, and seconds
2497
2546
  * @returns {Boolean}
@@ -2947,19 +2996,40 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2947
2996
  }
2948
2997
 
2949
2998
  /**
2950
- * Get the date of the specified week (From Sunday)
2951
- * @param {Number} weekOffset
2952
- * @returns {Array<Date>}
2999
+ * Get all 7 dates for a specific week starting from Sunday.
3000
+ * * @param {Number} weekOffset - The offset of weeks from the current week.
3001
+ * 0: Current week
3002
+ * -1: Previous week
3003
+ * 1: Next week
3004
+ * @returns {Array<Date>} - An array containing 7 Date objects from Sunday to Saturday.
2953
3005
  */
3006
+ /*
3007
+ // Demo 1: Get dates for the current week (Sunday Start)
3008
+ const currentWeekSun = getWeekDatesFromSun(0);
3009
+ console.log('Sunday (Start):', currentWeekSun[0].toLocaleDateString());
3010
+ console.log('Saturday (End):', currentWeekSun[6].toLocaleDateString());
3011
+
3012
+ // Demo 2: Get the date range for the previous week
3013
+ const lastWeek = getWeekDatesFromSun(-1);
3014
+ const rangeStart = lastWeek[0].toISOString().split('T')[0];
3015
+ const rangeEnd = lastWeek[6].toISOString().split('T')[0];
3016
+ console.log(`Previous Week Range: ${rangeStart} to ${rangeEnd}`);
3017
+
3018
+ // Demo 3: Checking for Month/Year transitions
3019
+ const transitionWeek = getWeekDatesFromSun(0).map(d => d.toDateString());
3020
+ console.log('Transition Week Dates:', transitionWeek);
3021
+
3022
+ */
2954
3023
  function _getWeekDatesFromSun(weekOffset) {
2955
3024
  var dates = [];
3025
+ // Start with a clean date (midnight) to avoid timezone/DST shifts during calculation
2956
3026
  var currentDate = new Date();
3027
+ currentDate.setHours(0, 0, 0, 0);
3028
+ var dayOfWeek = currentDate.getDay();
2957
3029
 
2958
- // Calculate the date of Sunday
2959
- var dayOfWeek = currentDate.getDay(); // 0 is Sunday
3030
+ // Move to the Sunday of the current week, then apply the week offset
3031
+ // Formula: Current Date - Current Day Index + (Offset * 7)
2960
3032
  currentDate.setDate(currentDate.getDate() - dayOfWeek + weekOffset * 7);
2961
-
2962
- // Get the date of the week
2963
3033
  for (var i = 0; i < 7; i++) {
2964
3034
  var date = new Date(currentDate);
2965
3035
  date.setDate(currentDate.getDate() + i);
@@ -2969,20 +3039,46 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2969
3039
  }
2970
3040
 
2971
3041
  /**
2972
- * Get the date of the specified week (From Monday)
2973
- * @param {Number} weekOffset
2974
- * @returns {Array<Date>}
3042
+ * Get all 7 dates for a specific week starting from Monday.
3043
+ * * @param {Number} weekOffset - The offset of weeks from the current week.
3044
+ * 0: Current week
3045
+ * -1: Previous week
3046
+ * 1: Next week
3047
+ * @returns {Array<Date>} - An array containing 7 Date objects from Monday to Sunday.
2975
3048
  */
3049
+ /*
3050
+ // Demo 1: Get dates for the current week
3051
+ const currentWeek = getWeekDatesFromMon(0);
3052
+ console.log('Monday of this week:', currentWeek[0].toLocaleDateString());
3053
+ console.log('Sunday of this week:', currentWeek[6].toLocaleDateString());
3054
+
3055
+ // Demo 2: Get dates for the next week
3056
+ const nextWeek = getWeekDatesFromMon(1);
3057
+ console.log('Monday of next week:', nextWeek[0].toLocaleDateString());
3058
+
3059
+ // Demo 3: Format the output as YYYY-MM-DD
3060
+ const formattedWeek = getWeekDatesFromMon(0).map(date => {
3061
+ const y = date.getFullYear();
3062
+ const m = String(date.getMonth() + 1).padStart(2, '0');
3063
+ const d = String(date.getDate()).padStart(2, '0');
3064
+ return `${y}-${m}-${d}`;
3065
+ });
3066
+ console.log('Formatted Week Array:', formattedWeek);
3067
+ // Result: ["2025-12-29", "2025-12-30", ..., "2026-01-04"]
3068
+ */
2976
3069
  function _getWeekDatesFromMon(weekOffset) {
2977
3070
  var dates = [];
2978
3071
  var currentDate = new Date();
2979
3072
 
2980
- // Set the date to Monday
3073
+ // Calculate the difference to get to Monday of the current week
3074
+ // If today is Sunday (0), we go back 6 days. Otherwise, go to (1 - currentDay).
2981
3075
  var dayOfWeek = currentDate.getDay();
2982
3076
  var diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
3077
+
3078
+ // Apply the Monday offset and the week offset (7 days per week)
2983
3079
  currentDate.setDate(currentDate.getDate() + diffToMonday + weekOffset * 7);
2984
3080
 
2985
- // Get the date of the week
3081
+ // Generate the 7 days of the week
2986
3082
  for (var i = 0; i < 7; i++) {
2987
3083
  var date = new Date(currentDate);
2988
3084
  date.setDate(currentDate.getDate() + i);
@@ -2991,6 +3087,37 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2991
3087
  return dates;
2992
3088
  }
2993
3089
 
3090
+ /**
3091
+ * Get the date list of the week for the specified date (starting from Monday)
3092
+ * @param {Date | String} v - The specified date
3093
+ * @returns {Array<Date>} - An array containing 7 Date objects
3094
+ */
3095
+ function _getWeekDatesByDate(v) {
3096
+ var dates = [];
3097
+
3098
+ // Ensure we are working with a Date object.
3099
+ // If 'dateFormat' was a custom utility in your JS, replace 'new Date(v)' with that utility.
3100
+ var currentDate = new Date(v);
3101
+
3102
+ // Get the day of the week (0 for Sunday, 1 for Monday, ..., 6 for Saturday)
3103
+ var dayOfWeek = currentDate.getDay();
3104
+
3105
+ // Calculate difference to Monday: if Sunday (0) subtract 6 days, otherwise subtract (day - 1)
3106
+ var diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
3107
+
3108
+ // Create the Monday starting point
3109
+ var monday = new Date(currentDate);
3110
+ monday.setDate(currentDate.getDate() + diffToMonday);
3111
+
3112
+ // Generate the 7 days of the week
3113
+ for (var i = 0; i < 7; i++) {
3114
+ var date = new Date(monday);
3115
+ date.setDate(monday.getDate() + i);
3116
+ dates.push(date);
3117
+ }
3118
+ return dates;
3119
+ }
3120
+
2994
3121
  /******/
2995
3122
  return __webpack_exports__;
2996
3123
  /******/
@@ -4238,10 +4365,45 @@ var EventCalendarTimeline = function EventCalendarTimeline(props) {
4238
4365
  //================================================================
4239
4366
  // Weekly calendar
4240
4367
  //================================================================
4368
+ var hasInitializedRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(false);
4369
+
4370
+ // Helper function to calculate offset from a specific date
4371
+ var calculateWeekOffset = function calculateWeekOffset(targetDate) {
4372
+ var _curDate = typeof targetDate === 'undefined' ? date : targetDate;
4373
+
4374
+ // 1. Get the current selected date (from customTodayDate or user selection)
4375
+ var selected = new Date(_curDate.getFullYear(), _curDate.getMonth(), _curDate.getDate());
4376
+
4377
+ // 2. Get the reference Monday of the "actual current week" (offset 0)
4378
+ var currentWeekDates = (0,funda_utils_dist_cjs_date__WEBPACK_IMPORTED_MODULE_6__.getWeekDatesFromMon)(0);
4379
+ var currentMonday = new Date(currentWeekDates[0]);
4380
+ currentMonday.setHours(0, 0, 0, 0);
4381
+
4382
+ // 3. Calculate the difference in days
4383
+ var diffTime = selected.getTime() - currentMonday.getTime();
4384
+ var diffDays = Math.round(diffTime / (1000 * 60 * 60 * 24));
4385
+
4386
+ // 4. Update the week offset automatically
4387
+ var offset = Math.floor(diffDays / 7);
4388
+ setWeekOffset(offset);
4389
+ };
4390
+ // Initialize weekOffset based on customTodayDate instead of default 0
4241
4391
  var _useState39 = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(0),
4242
4392
  _useState40 = _slicedToArray(_useState39, 2),
4243
4393
  weekOffset = _useState40[0],
4244
4394
  setWeekOffset = _useState40[1];
4395
+
4396
+ // Sync weekOffset whenever date changes or mode switches to 'week'
4397
+ (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
4398
+ if (!hasInitializedRef.current) {
4399
+ var customDateValid = (0,funda_utils_dist_cjs_date__WEBPACK_IMPORTED_MODULE_6__.isValidDate)(customTodayDate);
4400
+ if (customDateValid) {
4401
+ calculateWeekOffset(new Date(customTodayDate));
4402
+ setDate(new Date(customTodayDate));
4403
+ hasInitializedRef.current = true;
4404
+ }
4405
+ }
4406
+ }, [date, appearanceMode, customTodayDate]);
4245
4407
  var handleNextWeek = function handleNextWeek() {
4246
4408
  setWeekOffset(weekOffset + 1);
4247
4409
  return weekOffset + 1;
@@ -5071,7 +5233,8 @@ var EventCalendarTimeline = function EventCalendarTimeline(props) {
5071
5233
  var _mode = e.target.dataset.mode;
5072
5234
  setAppearanceMode(_mode);
5073
5235
 
5074
- //
5236
+ // The useEffect above will handle the weekOffset calculation
5237
+ // as soon as appearanceMode becomes 'week'
5075
5238
  onChangeAppearanceMode === null || onChangeAppearanceMode === void 0 ? void 0 : onChangeAppearanceMode(_mode);
5076
5239
  }
5077
5240
  function handleShowWinYear() {
@@ -5161,8 +5324,11 @@ var EventCalendarTimeline = function EventCalendarTimeline(props) {
5161
5324
  colSpan: 1,
5162
5325
  "data-date": _dateShow,
5163
5326
  "data-day": _dateDayShow,
5164
- "data-week": weekDay,
5165
- style: {
5327
+ "data-week": weekDay
5328
+
5329
+ // FIX: In 'week' mode, we don't want a hardcoded minWidth
5330
+ ,
5331
+ style: appearanceMode === 'week' ? undefined : {
5166
5332
  minWidth: CELL_MIN_W + 'px'
5167
5333
  },
5168
5334
  onMouseEnter: function onMouseEnter(e) {
@@ -5906,14 +6072,29 @@ var EventCalendarTimeline = function EventCalendarTimeline(props) {
5906
6072
  (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
5907
6073
  updateTodayDate(date, prevDateRef.current);
5908
6074
  }, [date]);
6075
+
6076
+ // Guaranteed year change triggered by the next/prev buttons
6077
+ var isFirstRenderRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(true);
6078
+ var prevYearRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(year); // Record the year of the last occurrence.
5909
6079
  (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
5910
- // Guaranteed year change triggered by the front and rear buttons
5911
- onChangeYear === null || onChangeYear === void 0 ? void 0 : onChangeYear({
5912
- day: (0,funda_utils_dist_cjs_date__WEBPACK_IMPORTED_MODULE_6__.padZero)(day),
5913
- month: (0,funda_utils_dist_cjs_date__WEBPACK_IMPORTED_MODULE_6__.padZero)(month + 1),
5914
- year: year.toString()
5915
- });
5916
- }, [year]);
6080
+ // 1. Intercept the first render (Mount)
6081
+ if (isFirstRenderRef.current) {
6082
+ isFirstRenderRef.current = false;
6083
+ return;
6084
+ }
6085
+
6086
+ // 2. It only triggers when the year actually changes
6087
+ if (year !== prevYearRef.current) {
6088
+ onChangeYear === null || onChangeYear === void 0 ? void 0 : onChangeYear({
6089
+ day: (0,funda_utils_dist_cjs_date__WEBPACK_IMPORTED_MODULE_6__.padZero)(day),
6090
+ month: (0,funda_utils_dist_cjs_date__WEBPACK_IMPORTED_MODULE_6__.padZero)(month + 1),
6091
+ year: year.toString()
6092
+ });
6093
+
6094
+ // Update the old year ref for next comparison
6095
+ prevYearRef.current = year;
6096
+ }
6097
+ }, [year, month, day, onChangeYear]);
5917
6098
  (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
5918
6099
  var _getCells5 = getCells(),
5919
6100
  forwardFillTotal = _getCells5.forwardFillTotal,
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 the date of the specified week (From Sunday)
217
- * @param {Number} weekOffset
218
- * @returns {Array<Date>}
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 the date of the specified week (From Monday)
223
- * @param {Number} weekOffset
224
- * @returns {Array<Date>}
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
- export { 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 };
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 the date of the specified week (From Sunday)
541
- * @param {Number} weekOffset
542
- * @returns {Array<Date>}
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
- // Calculate the date of Sunday
549
- var dayOfWeek = currentDate.getDay(); // 0 is Sunday
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 the date of the specified week (From Monday)
563
- * @param {Number} weekOffset
564
- * @returns {Array<Date>}
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
- // Set the date to Monday
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
- // Get the date of the week
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
  ;