@bbn/bbn 1.0.469 → 1.0.471

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/dist/date.d.ts CHANGED
@@ -9,6 +9,13 @@ declare class bbnDateTool {
9
9
  minutes(v?: number): number | bbnDateTool;
10
10
  seconds(v?: number): number | bbnDateTool;
11
11
  weekday(v?: number, past?: boolean): number | bbnDateTool;
12
+ /**
13
+ * Returns the ISO-8601 week number of this date.
14
+ * Week starts on Monday, and week 1 is the week with Jan 4.
15
+ *
16
+ * @returns {number} ISO week number (1–53)
17
+ */
18
+ week(): number;
12
19
  get tst(): number;
13
20
  get mtst(): number;
14
21
  get YYYY(): string;
package/dist/date.js CHANGED
@@ -309,6 +309,26 @@ class bbnDateTool {
309
309
  }
310
310
  return __classPrivateFieldGet(this, _bbnDateTool_value, "f").getDay();
311
311
  }
312
+ /**
313
+ * Returns the ISO-8601 week number of this date.
314
+ * Week starts on Monday, and week 1 is the week with Jan 4.
315
+ *
316
+ * @returns {number} ISO week number (1–53)
317
+ */
318
+ week() {
319
+ // Copy date in UTC to avoid timezone issues
320
+ const d = new Date(Date.UTC(this.year(), this.month() - 1, this.day()));
321
+ // Set to nearest Thursday (ISO anchor)
322
+ // (Thursday = day 4, because Sunday=0, Monday=1,...)
323
+ const dayNum = d.getUTCDay() || 7; // make Sunday = 7
324
+ // Move date to Thursday of this week
325
+ d.setUTCDate(d.getUTCDate() + (4 - dayNum));
326
+ // First week of the year is the week with Jan 4 in it
327
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
328
+ // Calculate full weeks between the dates
329
+ const weekNo = Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7);
330
+ return weekNo;
331
+ }
312
332
  get tst() {
313
333
  return Math.ceil(__classPrivateFieldGet(this, _bbnDateTool_value, "f").getTime() / 1000);
314
334
  }
@@ -471,7 +491,7 @@ class bbnDateTool {
471
491
  * @returns -1 if this < other, 0 if equal, 1 if this > other
472
492
  */
473
493
  compare(date, unit = '') {
474
- const d = new bbnDateTool(date);
494
+ const d = date instanceof bbnDateTool ? date : new bbnDateTool(date);
475
495
  const realUnit = unitsCorrespondence[unit] || null;
476
496
  // If no unit or unknown unit, fall back to timestamp comparison
477
497
  if (!realUnit) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.469",
3
+ "version": "1.0.471",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",