@hkdigital/lib-core 0.5.44 → 0.5.46

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.
@@ -185,12 +185,16 @@ export function getWeekNumber(dateOrTimestamp) {
185
185
  //
186
186
  // Create a copy of this date object
187
187
  //
188
- const target = new Date(date.valueOf());
188
+ const target = new Date(Date.UTC(
189
+ date.getUTCFullYear(),
190
+ date.getUTCMonth(),
191
+ date.getUTCDate()
192
+ ));
189
193
 
190
194
  //
191
195
  // ISO week date weeks start on Monday, so correct the day number
192
196
  //
193
- const dayNumber = (date.getDay() + 6) % 7;
197
+ const dayNumber = (date.getUTCDay() + 6) % 7;
194
198
 
195
199
  //
196
200
  // ISO 8601 states that week 1 is the week with the first Thursday
@@ -198,22 +202,29 @@ export function getWeekNumber(dateOrTimestamp) {
198
202
  //
199
203
  // Set the target date to the Thursday in the target week
200
204
  //
201
- target.setDate(target.getDate() - dayNumber + 3);
205
+ target.setUTCDate(target.getUTCDate() - dayNumber + 3);
202
206
 
203
207
  //
204
208
  // Store the millisecond value of the target date
205
209
  //
206
210
  const firstThursday = target.valueOf();
207
211
 
208
- // Set the target to the first Thursday of the year
209
- // First, set the target to January 1st
210
- target.setMonth(0, 1);
212
+ //
213
+ // Get the year of the Thursday in the target week
214
+ // (This is important for dates near year boundaries)
215
+ //
216
+ const yearOfThursday = target.getUTCFullYear();
217
+
218
+ // Set the target to the first Thursday of that year
219
+ // First, set the target to January 1st of that year
220
+ target.setUTCFullYear(yearOfThursday);
221
+ target.setUTCMonth(0, 1);
211
222
 
212
223
  //
213
224
  // Not a Thursday? Correct the date to the next Thursday
214
225
  //
215
- if (target.getDay() !== 4) {
216
- target.setMonth(0, 1 + ((4 - target.getDay() + 7) % 7));
226
+ if (target.getUTCDay() !== 4) {
227
+ target.setUTCMonth(0, 1 + ((4 - target.getUTCDay() + 7) % 7));
217
228
  }
218
229
 
219
230
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.44",
3
+ "version": "0.5.46",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"