mybase 1.1.21 → 1.1.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mybase",
3
- "version": "1.1.21",
3
+ "version": "1.1.22",
4
4
  "description": "",
5
5
  "main": "mybase.js",
6
6
  "scripts": {
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWeekNumber = void 0;
4
+ // credit: https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php
5
+ /* For a given date, get the ISO week number
6
+
7
+ Based on information at:
8
+
9
+ THIS PAGE (DOMAIN EVEN) DOESN'T EXIST ANYMORE UNFORTUNATELY
10
+ http://www.merlyn.demon.co.uk/weekcalc.htm#WNR
11
+
12
+ Algorithm is to find nearest thursday, it's year
13
+ is the year of the week number. Then get weeks
14
+ between that date and the first day of that year.
15
+
16
+ Note that dates in one year can be weeks of previous
17
+ or next year, overlap is up to 3 days.
18
+
19
+ e.g. 2014/12/29 is Monday in week 1 of 2015
20
+ 2012/1/1 is Sunday in week 52 of 2011
21
+ */
22
+ function getWeekNumber(d = new Date()) {
23
+ // Copy date so don't modify original
24
+ const date = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
25
+ // Set to nearest Thursday: current date + 4 - current day number
26
+ // Make Sunday's day number 7
27
+ date.setUTCDate(date.getUTCDate() + 4 - (date.getUTCDay() || 7));
28
+ // Get first day of year
29
+ const yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1));
30
+ // Calculate full weeks to nearest Thursday
31
+ const weekNo = Math.ceil(((date.getTime() - yearStart.getTime()) / 86400000 + 1) / 7);
32
+ // Return the week number
33
+ return weekNo;
34
+ }
35
+ exports.getWeekNumber = getWeekNumber;
36
+ //# sourceMappingURL=getWeekNumber.js.map
@@ -0,0 +1,9 @@
1
+ import { getWeekNumber } from './getWeekNumber'
2
+
3
+
4
+ describe('getWeekNumber', () => {
5
+ it('should return the correct week number', () => {
6
+ expect(getWeekNumber(new Date('2012-01-01'))).toBe(52)
7
+ expect(getWeekNumber(new Date('2014-12-30'))).toBe(1)
8
+ })
9
+ })
@@ -0,0 +1,31 @@
1
+ // credit: https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php
2
+ /* For a given date, get the ISO week number
3
+
4
+ Based on information at:
5
+
6
+ THIS PAGE (DOMAIN EVEN) DOESN'T EXIST ANYMORE UNFORTUNATELY
7
+ http://www.merlyn.demon.co.uk/weekcalc.htm#WNR
8
+
9
+ Algorithm is to find nearest thursday, it's year
10
+ is the year of the week number. Then get weeks
11
+ between that date and the first day of that year.
12
+
13
+ Note that dates in one year can be weeks of previous
14
+ or next year, overlap is up to 3 days.
15
+
16
+ e.g. 2014/12/29 is Monday in week 1 of 2015
17
+ 2012/1/1 is Sunday in week 52 of 2011
18
+ */
19
+ export function getWeekNumber(d: Date = new Date()): number {
20
+ // Copy date so don't modify original
21
+ const date = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
22
+ // Set to nearest Thursday: current date + 4 - current day number
23
+ // Make Sunday's day number 7
24
+ date.setUTCDate(date.getUTCDate() + 4 - (date.getUTCDay() || 7));
25
+ // Get first day of year
26
+ const yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1));
27
+ // Calculate full weeks to nearest Thursday
28
+ const weekNo = Math.ceil(((date.getTime() - yearStart.getTime()) / 86400000 + 1) / 7);
29
+ // Return the week number
30
+ return weekNo;
31
+ }
package/ts/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./funcs/getWeekNumber"), exports);
17
18
  __exportStar(require("./funcs/Geoip2Paths"), exports);
18
19
  __exportStar(require("./funcs/isLocal"), exports);
19
20
  __exportStar(require("./funcs/randomString"), exports);
package/ts/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./funcs/getWeekNumber"
1
2
  export * from "./funcs/Geoip2Paths";
2
3
  export * from "./funcs/isLocal"
3
4
  export * from "./funcs/randomString"
@@ -1,6 +1,3 @@
1
-
2
-
3
-
4
1
  export class Timespan {
5
2
  constructor(private readonly ms: number){
6
3
  }