@adobe/spacecat-shared-utils 1.43.1 → 1.44.0
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/calendar-week-helper.js +23 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-utils-v1.44.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.43.1...@adobe/spacecat-shared-utils-v1.44.0) (2025-07-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add function for extracting list of calendar weeks ([#880](https://github.com/adobe/spacecat-shared/issues/880)) ([f69a808](https://github.com/adobe/spacecat-shared/commit/f69a808b96ee5e977e5cf5936e3effa378b51581))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-utils-v1.43.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.43.0...@adobe/spacecat-shared-utils-v1.43.1) (2025-07-27)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -19,20 +19,15 @@ const getFirstMondayOfYear = (year) => {
|
|
|
19
19
|
|
|
20
20
|
const getThursdayOfWeek = (date) => {
|
|
21
21
|
const thursday = new Date(date.getTime());
|
|
22
|
-
|
|
22
|
+
const dayOfWeek = date.getUTCDay() || 7;
|
|
23
|
+
thursday.setUTCDate(date.getUTCDate() + 4 - dayOfWeek);
|
|
23
24
|
return thursday;
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
const has53CalendarWeeks = (year) => {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const thursdayOfFirstWeek = new Date(firstMonday.getTime() + 3 * MILLISECONDS_IN_A_DAY);
|
|
31
|
-
|
|
32
|
-
const maxWeek = Math.ceil((lastThursday.getTime() - thursdayOfFirstWeek.getTime())
|
|
33
|
-
/ MILLISECONDS_IN_A_WEEK) + 1;
|
|
34
|
-
|
|
35
|
-
return maxWeek === 53;
|
|
28
|
+
const jan1 = new Date(Date.UTC(year, 0, 1));
|
|
29
|
+
const dec31 = new Date(Date.UTC(year, 11, 31));
|
|
30
|
+
return jan1.getUTCDay() === 4 || dec31.getUTCDay() === 4;
|
|
36
31
|
};
|
|
37
32
|
|
|
38
33
|
const isValidWeek = (week, year) => {
|
|
@@ -119,3 +114,21 @@ export function getDateRanges(week, year) {
|
|
|
119
114
|
},
|
|
120
115
|
];
|
|
121
116
|
}
|
|
117
|
+
|
|
118
|
+
// Note: This function binds week exclusively to one year
|
|
119
|
+
export function getLastNumberOfWeeks(number) {
|
|
120
|
+
const result = [];
|
|
121
|
+
let { week, year } = getLastFullCalendarWeek();
|
|
122
|
+
|
|
123
|
+
for (let i = 0; i < number; i += 1) {
|
|
124
|
+
result.unshift({ week, year });
|
|
125
|
+
|
|
126
|
+
week -= 1;
|
|
127
|
+
if (week < 1) {
|
|
128
|
+
year -= 1;
|
|
129
|
+
week = has53CalendarWeeks(year) ? 53 : 52;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return result;
|
|
134
|
+
}
|