@bemoje/date 0.0.11 → 0.2.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/README.md +6 -34
- package/package.json +10 -7
- package/src/index.d.ts +32 -0
- package/src/index.js +36 -0
- package/src/index.js.map +1 -0
- package/src/lib/assertValidDate.d.ts +18 -0
- package/src/lib/assertValidDate.js +36 -0
- package/src/lib/assertValidDate.js.map +1 -0
- package/src/lib/assertValidDateDay.d.ts +15 -0
- package/src/lib/assertValidDateDay.js +24 -0
- package/src/lib/assertValidDateDay.js.map +1 -0
- package/src/lib/assertValidDateMonth.d.ts +12 -0
- package/src/lib/assertValidDateMonth.js +21 -0
- package/src/lib/assertValidDateMonth.js.map +1 -0
- package/src/lib/assertValidDateYear.d.ts +13 -0
- package/src/lib/assertValidDateYear.js +22 -0
- package/src/lib/assertValidDateYear.js.map +1 -0
- package/src/lib/constants/MS_IN_DAY.d.ts +4 -0
- package/src/lib/constants/MS_IN_DAY.js +8 -0
- package/src/lib/constants/MS_IN_DAY.js.map +1 -0
- package/src/lib/constants/MS_IN_HOUR.d.ts +4 -0
- package/src/lib/constants/MS_IN_HOUR.js +8 -0
- package/src/lib/constants/MS_IN_HOUR.js.map +1 -0
- package/src/lib/constants/MS_IN_MINUTE.d.ts +4 -0
- package/src/lib/constants/MS_IN_MINUTE.js +8 -0
- package/src/lib/constants/MS_IN_MINUTE.js.map +1 -0
- package/src/lib/constants/MS_IN_MONTH.d.ts +4 -0
- package/src/lib/constants/MS_IN_MONTH.js +8 -0
- package/src/lib/constants/MS_IN_MONTH.js.map +1 -0
- package/src/lib/constants/MS_IN_SECOND.d.ts +4 -0
- package/src/lib/constants/MS_IN_SECOND.js +8 -0
- package/src/lib/constants/MS_IN_SECOND.js.map +1 -0
- package/src/lib/constants/MS_IN_WEEK.d.ts +4 -0
- package/src/lib/constants/MS_IN_WEEK.js +8 -0
- package/src/lib/constants/MS_IN_WEEK.js.map +1 -0
- package/src/lib/constants/MS_IN_YEAR.d.ts +4 -0
- package/src/lib/constants/MS_IN_YEAR.js +8 -0
- package/src/lib/constants/MS_IN_YEAR.js.map +1 -0
- package/src/lib/dateDaysAgo.d.ts +10 -0
- package/src/lib/dateDaysAgo.js +19 -0
- package/src/lib/dateDaysAgo.js.map +1 -0
- package/src/lib/dateWeekDayName.d.ts +1 -0
- package/src/lib/dateWeekDayName.js +9 -0
- package/src/lib/dateWeekDayName.js.map +1 -0
- package/src/lib/daysSinceDate.d.ts +12 -0
- package/src/lib/daysSinceDate.js +21 -0
- package/src/lib/daysSinceDate.js.map +1 -0
- package/src/lib/getCentury.d.ts +13 -0
- package/src/lib/getCentury.js +22 -0
- package/src/lib/getCentury.js.map +1 -0
- package/src/lib/getCurrentYear.d.ts +10 -0
- package/src/lib/getCurrentYear.js +17 -0
- package/src/lib/getCurrentYear.js.map +1 -0
- package/src/lib/hoursSinceDate.d.ts +12 -0
- package/src/lib/hoursSinceDate.js +21 -0
- package/src/lib/hoursSinceDate.js.map +1 -0
- package/src/lib/isLeapYear.d.ts +15 -0
- package/src/lib/isLeapYear.js +24 -0
- package/src/lib/isLeapYear.js.map +1 -0
- package/src/lib/isValidDate.d.ts +20 -0
- package/src/lib/isValidDate.js +41 -0
- package/src/lib/isValidDate.js.map +1 -0
- package/src/lib/isValidDateDay.d.ts +16 -0
- package/src/lib/isValidDateDay.js +34 -0
- package/src/lib/isValidDateDay.js.map +1 -0
- package/src/lib/isValidDateMonth.d.ts +12 -0
- package/src/lib/isValidDateMonth.js +19 -0
- package/src/lib/isValidDateMonth.js.map +1 -0
- package/src/lib/isValidDateYear.d.ts +15 -0
- package/src/lib/isValidDateYear.js +22 -0
- package/src/lib/isValidDateYear.js.map +1 -0
- package/src/lib/isoDateTimestamp.d.ts +15 -0
- package/src/lib/isoDateTimestamp.js +22 -0
- package/src/lib/isoDateTimestamp.js.map +1 -0
- package/src/lib/isoDateTimestampForFilename.d.ts +11 -0
- package/src/lib/isoDateTimestampForFilename.js +21 -0
- package/src/lib/isoDateTimestampForFilename.js.map +1 -0
- package/src/lib/minutesSinceDate.d.ts +12 -0
- package/src/lib/minutesSinceDate.js +21 -0
- package/src/lib/minutesSinceDate.js.map +1 -0
- package/src/lib/monthsSinceDate.d.ts +12 -0
- package/src/lib/monthsSinceDate.js +21 -0
- package/src/lib/monthsSinceDate.js.map +1 -0
- package/src/lib/msSinceDate.d.ts +11 -0
- package/src/lib/msSinceDate.js +24 -0
- package/src/lib/msSinceDate.js.map +1 -0
- package/src/lib/numDaysInMonth.d.ts +17 -0
- package/src/lib/numDaysInMonth.js +28 -0
- package/src/lib/numDaysInMonth.js.map +1 -0
- package/src/lib/prettyIsoDateString.d.ts +1 -0
- package/src/lib/prettyIsoDateString.js +25 -0
- package/src/lib/prettyIsoDateString.js.map +1 -0
- package/src/lib/secondsSinceDate.d.ts +10 -0
- package/src/lib/secondsSinceDate.js +19 -0
- package/src/lib/secondsSinceDate.js.map +1 -0
- package/src/lib/weeksSinceDate.d.ts +10 -0
- package/src/lib/weeksSinceDate.js +19 -0
- package/src/lib/weeksSinceDate.js.map +1 -0
- package/src/lib/yearsSinceDate.d.ts +10 -0
- package/src/lib/yearsSinceDate.js +19 -0
- package/src/lib/yearsSinceDate.js.map +1 -0
- package/LICENSE +0 -21
- package/jest.config.ts +0 -13
- package/project.json +0 -40
- package/tsconfig.lib.json +0 -13
- package/tsconfig.spec.json +0 -9
package/README.md
CHANGED
|
@@ -1,39 +1,11 @@
|
|
|
1
|
-
#
|
|
2
|
-
Date related tools/util.
|
|
1
|
+
# date
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-

|
|
9
|
-

|
|
10
|
-

|
|
11
|
-

|
|
5
|
+
## Building
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
<span><a href="https://npmjs.org/@bemoje/date" title="View this project on NPM"><img src="https://img.shields.io/npm/v/@bemoje/date" alt="NPM Version" /></a></span>
|
|
15
|
-
<span><a href="https://npmjs.org/@bemoje/date" title="NPM Downloads"><img src="https://img.shields.io/npm/dt/@bemoje/date" alt="NPM Downloads" /></a></span>
|
|
7
|
+
Run `nx build date` to build the library.
|
|
16
8
|
|
|
17
|
-
##
|
|
18
|
-
[date docs](https://bemoje.github.io/tsmono/modules/date.html)
|
|
9
|
+
## Running unit tests
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
<span><a href="https://www.patreon.com/user?u=40752770" title="Donate using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon Donation" /></a></span>
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
This library is published in the NPM registry and can be installed using any compatible package manager.
|
|
25
|
-
|
|
26
|
-
#### NPM
|
|
27
|
-
```sh
|
|
28
|
-
npm install @bemoje/date
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
## Issues
|
|
33
|
-
Please let me know of any bugs or [issues](https://github.com/bemoje/https://github.com/bemoje/tsmono/issues).
|
|
34
|
-
|
|
35
|
-
## Contribute
|
|
36
|
-
Contributors are welcome to open a [pull request](https://github.com/bemoje/https://github.com/bemoje/tsmono/pulls).
|
|
37
|
-
|
|
38
|
-
## License
|
|
39
|
-
Released under the [MIT License](./LICENSE).
|
|
11
|
+
Run `nx test date` to execute the unit tests via [Jest](https://jestjs.io).
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemoje/date",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Date related tools/util.",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
},
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"scripts": {},
|
|
8
7
|
"author": {
|
|
9
8
|
"name": "Benjamin Møller Jensen",
|
|
10
9
|
"email": "bemoje@bemoje.net",
|
|
@@ -12,7 +11,9 @@
|
|
|
12
11
|
},
|
|
13
12
|
"license": "MIT",
|
|
14
13
|
"keywords": [],
|
|
15
|
-
"dependencies": {
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"tslib": "^2.3.0"
|
|
16
|
+
},
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
18
19
|
"url": "git+https://github.com/bemoje/tsmono.git"
|
|
@@ -25,5 +26,7 @@
|
|
|
25
26
|
"url": "https://github.com/bemoje/tsmono/issues"
|
|
26
27
|
},
|
|
27
28
|
"homepage": "https://github.com/bemoje/tsmono",
|
|
28
|
-
"type": "commonjs"
|
|
29
|
-
|
|
29
|
+
"type": "commonjs",
|
|
30
|
+
"typings": "./src/index.d.ts",
|
|
31
|
+
"types": "./src/index.d.ts"
|
|
32
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export * from './lib/assertValidDate';
|
|
2
|
+
export * from './lib/assertValidDateDay';
|
|
3
|
+
export * from './lib/assertValidDateMonth';
|
|
4
|
+
export * from './lib/assertValidDateYear';
|
|
5
|
+
export * from './lib/constants/MS_IN_DAY';
|
|
6
|
+
export * from './lib/constants/MS_IN_HOUR';
|
|
7
|
+
export * from './lib/constants/MS_IN_MINUTE';
|
|
8
|
+
export * from './lib/constants/MS_IN_MONTH';
|
|
9
|
+
export * from './lib/constants/MS_IN_SECOND';
|
|
10
|
+
export * from './lib/constants/MS_IN_WEEK';
|
|
11
|
+
export * from './lib/constants/MS_IN_YEAR';
|
|
12
|
+
export * from './lib/dateDaysAgo';
|
|
13
|
+
export * from './lib/dateWeekDayName';
|
|
14
|
+
export * from './lib/daysSinceDate';
|
|
15
|
+
export * from './lib/getCentury';
|
|
16
|
+
export * from './lib/getCurrentYear';
|
|
17
|
+
export * from './lib/hoursSinceDate';
|
|
18
|
+
export * from './lib/isLeapYear';
|
|
19
|
+
export * from './lib/isoDateTimestamp';
|
|
20
|
+
export * from './lib/isoDateTimestampForFilename';
|
|
21
|
+
export * from './lib/isValidDate';
|
|
22
|
+
export * from './lib/isValidDateDay';
|
|
23
|
+
export * from './lib/isValidDateMonth';
|
|
24
|
+
export * from './lib/isValidDateYear';
|
|
25
|
+
export * from './lib/minutesSinceDate';
|
|
26
|
+
export * from './lib/monthsSinceDate';
|
|
27
|
+
export * from './lib/msSinceDate';
|
|
28
|
+
export * from './lib/numDaysInMonth';
|
|
29
|
+
export * from './lib/prettyIsoDateString';
|
|
30
|
+
export * from './lib/secondsSinceDate';
|
|
31
|
+
export * from './lib/weeksSinceDate';
|
|
32
|
+
export * from './lib/yearsSinceDate';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/assertValidDate"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/assertValidDateDay"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/assertValidDateMonth"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/assertValidDateYear"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/constants/MS_IN_DAY"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./lib/constants/MS_IN_HOUR"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./lib/constants/MS_IN_MINUTE"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./lib/constants/MS_IN_MONTH"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./lib/constants/MS_IN_SECOND"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./lib/constants/MS_IN_WEEK"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./lib/constants/MS_IN_YEAR"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./lib/dateDaysAgo"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./lib/dateWeekDayName"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./lib/daysSinceDate"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./lib/getCentury"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./lib/getCurrentYear"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./lib/hoursSinceDate"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./lib/isLeapYear"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./lib/isoDateTimestamp"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./lib/isoDateTimestampForFilename"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./lib/isValidDate"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./lib/isValidDateDay"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./lib/isValidDateMonth"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./lib/isValidDateYear"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./lib/minutesSinceDate"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./lib/monthsSinceDate"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./lib/msSinceDate"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./lib/numDaysInMonth"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./lib/prettyIsoDateString"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./lib/secondsSinceDate"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./lib/weeksSinceDate"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./lib/yearsSinceDate"), exports);
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/date/src/index.ts"],"names":[],"mappings":";;;AAAA,gEAAqC;AACrC,mEAAwC;AACxC,qEAA0C;AAC1C,oEAAyC;AACzC,oEAAyC;AACzC,qEAA0C;AAC1C,uEAA4C;AAC5C,sEAA2C;AAC3C,uEAA4C;AAC5C,qEAA0C;AAC1C,qEAA0C;AAC1C,4DAAiC;AACjC,gEAAqC;AACrC,8DAAmC;AACnC,2DAAgC;AAChC,+DAAoC;AACpC,+DAAoC;AACpC,2DAAgC;AAChC,iEAAsC;AACtC,4EAAiD;AACjD,4DAAiC;AACjC,+DAAoC;AACpC,iEAAsC;AACtC,gEAAqC;AACrC,iEAAsC;AACtC,gEAAqC;AACrC,4DAAiC;AACjC,+DAAoC;AACpC,oEAAyC;AACzC,iEAAsC;AACtC,+DAAoC;AACpC,+DAAoC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that the provided date parameters form a valid date.
|
|
3
|
+
* @param year The year of the date.
|
|
4
|
+
* @param month The month of the date.
|
|
5
|
+
* @param day The day of the date.
|
|
6
|
+
* @param hour The hour of the date.
|
|
7
|
+
* @param minute The minute of the date.
|
|
8
|
+
* @param second The second of the date.
|
|
9
|
+
* @param millisecond The millisecond of the date.
|
|
10
|
+
* @throws Will throw an error if the date is not valid.
|
|
11
|
+
* @example ```ts
|
|
12
|
+
* assertValidDate(2021, 12, 31, 23, 59, 59, 999);;
|
|
13
|
+
* //=> true
|
|
14
|
+
* assertValidDate(2021, 13, 31, 23, 59, 59, 999);;
|
|
15
|
+
* //=> throws an error
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertValidDate(year?: number | string, month?: number | string, day?: number | string, hour?: number | string, minute?: number | string, second?: number | string, millisecond?: number | string): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidDate = void 0;
|
|
4
|
+
const isValidDate_1 = require("./isValidDate");
|
|
5
|
+
/**
|
|
6
|
+
* Asserts that the provided date parameters form a valid date.
|
|
7
|
+
* @param year The year of the date.
|
|
8
|
+
* @param month The month of the date.
|
|
9
|
+
* @param day The day of the date.
|
|
10
|
+
* @param hour The hour of the date.
|
|
11
|
+
* @param minute The minute of the date.
|
|
12
|
+
* @param second The second of the date.
|
|
13
|
+
* @param millisecond The millisecond of the date.
|
|
14
|
+
* @throws Will throw an error if the date is not valid.
|
|
15
|
+
* @example ```ts
|
|
16
|
+
* assertValidDate(2021, 12, 31, 23, 59, 59, 999);;
|
|
17
|
+
* //=> true
|
|
18
|
+
* assertValidDate(2021, 13, 31, 23, 59, 59, 999);;
|
|
19
|
+
* //=> throws an error
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function assertValidDate(year, month, day, hour, minute, second, millisecond) {
|
|
23
|
+
if (!(0, isValidDate_1.isValidDate)(year, month, day, hour, minute, second, millisecond)) {
|
|
24
|
+
throw new Error(`Expected valid date. Got: ${JSON.stringify({
|
|
25
|
+
year,
|
|
26
|
+
month,
|
|
27
|
+
day,
|
|
28
|
+
hour,
|
|
29
|
+
minute,
|
|
30
|
+
second,
|
|
31
|
+
millisecond,
|
|
32
|
+
})}.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.assertValidDate = assertValidDate;
|
|
36
|
+
//# sourceMappingURL=assertValidDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertValidDate.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/assertValidDate.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAE3C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,eAAe,CAC7B,IAAsB,EACtB,KAAuB,EACvB,GAAqB,EACrB,IAAsB,EACtB,MAAwB,EACxB,MAAwB,EACxB,WAA6B;IAE7B,IAAI,CAAC,IAAA,yBAAW,EAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE;QACrE,MAAM,IAAI,KAAK,CACb,6BAA6B,IAAI,CAAC,SAAS,CAAC;YAC1C,IAAI;YACJ,KAAK;YACL,GAAG;YACH,IAAI;YACJ,MAAM;YACN,MAAM;YACN,WAAW;SACZ,CAAC,GAAG,CACN,CAAA;KACF;AACH,CAAC;AAtBD,0CAsBC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that the provided day, month, and optional year form a valid date.
|
|
3
|
+
* If the date is not valid, it throws an error.
|
|
4
|
+
* @param day The day of the month. Should be an integer between 1 and 31.
|
|
5
|
+
* @param month The month of the year. Should be an integer between 1 and 12.
|
|
6
|
+
* @param year The year of the date. Optional parameter. If provided, should be a positive integer.
|
|
7
|
+
* @throws Will throw an error if the provided day, month, and optional year do not form a valid date.
|
|
8
|
+
* @example ```ts
|
|
9
|
+
* assertValidDateDay(31, 2, 2020);;
|
|
10
|
+
* //=> Error: Invalid day of the month: 31.
|
|
11
|
+
* assertValidDateDay(29, 2, 2020);;
|
|
12
|
+
* //=> no error
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function assertValidDateDay(day: number, month: number, year?: number): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidDateDay = void 0;
|
|
4
|
+
const isValidDateDay_1 = require("./isValidDateDay");
|
|
5
|
+
/**
|
|
6
|
+
* Asserts that the provided day, month, and optional year form a valid date.
|
|
7
|
+
* If the date is not valid, it throws an error.
|
|
8
|
+
* @param day The day of the month. Should be an integer between 1 and 31.
|
|
9
|
+
* @param month The month of the year. Should be an integer between 1 and 12.
|
|
10
|
+
* @param year The year of the date. Optional parameter. If provided, should be a positive integer.
|
|
11
|
+
* @throws Will throw an error if the provided day, month, and optional year do not form a valid date.
|
|
12
|
+
* @example ```ts
|
|
13
|
+
* assertValidDateDay(31, 2, 2020);;
|
|
14
|
+
* //=> Error: Invalid day of the month: 31.
|
|
15
|
+
* assertValidDateDay(29, 2, 2020);;
|
|
16
|
+
* //=> no error
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function assertValidDateDay(day, month, year) {
|
|
20
|
+
if (!(0, isValidDateDay_1.isValidDateDay)(day, month, year))
|
|
21
|
+
throw new Error(`Invalid day of the month: ${day}.`);
|
|
22
|
+
}
|
|
23
|
+
exports.assertValidDateDay = assertValidDateDay;
|
|
24
|
+
//# sourceMappingURL=assertValidDateDay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertValidDateDay.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/assertValidDateDay.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAEjD;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAAC,GAAW,EAAE,KAAa,EAAE,IAAa;IAC1E,IAAI,CAAC,IAAA,+BAAc,EAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,GAAG,CAAC,CAAA;AAC7F,CAAC;AAFD,gDAEC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts if the provided month is a valid date month.
|
|
3
|
+
* @param month The month to be validated. Should be a number between 1 and 12.
|
|
4
|
+
* @throws Will throw an error if the month is not a valid date month.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* assertValidDateMonth(13);;
|
|
7
|
+
* //=> Error: Invalid month: 13.
|
|
8
|
+
* assertValidDateMonth(1);;
|
|
9
|
+
* //=> undefined
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function assertValidDateMonth(month: number): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidDateMonth = void 0;
|
|
4
|
+
const isValidDateMonth_1 = require("./isValidDateMonth");
|
|
5
|
+
/**
|
|
6
|
+
* Asserts if the provided month is a valid date month.
|
|
7
|
+
* @param month The month to be validated. Should be a number between 1 and 12.
|
|
8
|
+
* @throws Will throw an error if the month is not a valid date month.
|
|
9
|
+
* @example ```ts
|
|
10
|
+
* assertValidDateMonth(13);;
|
|
11
|
+
* //=> Error: Invalid month: 13.
|
|
12
|
+
* assertValidDateMonth(1);;
|
|
13
|
+
* //=> undefined
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function assertValidDateMonth(month) {
|
|
17
|
+
if (!(0, isValidDateMonth_1.isValidDateMonth)(month))
|
|
18
|
+
throw new Error(`Invalid month: ${month}.`);
|
|
19
|
+
}
|
|
20
|
+
exports.assertValidDateMonth = assertValidDateMonth;
|
|
21
|
+
//# sourceMappingURL=assertValidDateMonth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertValidDateMonth.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/assertValidDateMonth.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAErD;;;;;;;;;;GAUG;AACH,SAAgB,oBAAoB,CAAC,KAAa;IAChD,IAAI,CAAC,IAAA,mCAAgB,EAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,GAAG,CAAC,CAAA;AAC3E,CAAC;AAFD,oDAEC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that the provided year is a valid date year.
|
|
3
|
+
* @param year The year to be validated
|
|
4
|
+
* @throws Will throw an error if the year is not valid.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* assertValidDateYear(2020);;
|
|
7
|
+
* //=> undefined
|
|
8
|
+
* assertValidDateYear(10000);;
|
|
9
|
+
* //=> Error: Invalid year: 10000.
|
|
10
|
+
* ```
|
|
11
|
+
* @returns void
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertValidDateYear(year: number): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidDateYear = void 0;
|
|
4
|
+
const isValidDateYear_1 = require("./isValidDateYear");
|
|
5
|
+
/**
|
|
6
|
+
* Asserts that the provided year is a valid date year.
|
|
7
|
+
* @param year The year to be validated
|
|
8
|
+
* @throws Will throw an error if the year is not valid.
|
|
9
|
+
* @example ```ts
|
|
10
|
+
* assertValidDateYear(2020);;
|
|
11
|
+
* //=> undefined
|
|
12
|
+
* assertValidDateYear(10000);;
|
|
13
|
+
* //=> Error: Invalid year: 10000.
|
|
14
|
+
* ```
|
|
15
|
+
* @returns void
|
|
16
|
+
*/
|
|
17
|
+
function assertValidDateYear(year) {
|
|
18
|
+
if (!(0, isValidDateYear_1.isValidDateYear)(year))
|
|
19
|
+
throw new Error(`Invalid year: ${year}.`);
|
|
20
|
+
}
|
|
21
|
+
exports.assertValidDateYear = assertValidDateYear;
|
|
22
|
+
//# sourceMappingURL=assertValidDateYear.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertValidDateYear.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/assertValidDateYear.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAEnD;;;;;;;;;;;GAWG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,IAAI,CAAC,IAAA,iCAAe,EAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,GAAG,CAAC,CAAA;AACvE,CAAC;AAFD,kDAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MS_IN_DAY.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/constants/MS_IN_DAY.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,SAAS,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MS_IN_HOUR.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/constants/MS_IN_HOUR.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,UAAU,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MS_IN_MINUTE.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/constants/MS_IN_MINUTE.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,YAAY,GAAG,IAAI,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MS_IN_MONTH.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/constants/MS_IN_MONTH.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,WAAW,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MS_IN_SECOND.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/constants/MS_IN_SECOND.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,YAAY,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MS_IN_WEEK.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/constants/MS_IN_WEEK.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,UAAU,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MS_IN_YEAR.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/constants/MS_IN_YEAR.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,UAAU,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a Date object representing a date that is a certain number of days in the past.
|
|
3
|
+
* @param days The number of days ago for the date to represent.
|
|
4
|
+
* @returns A Date object representing the date that is the specified number of days in the past.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* dateDaysAgo(5);;
|
|
7
|
+
* //=> result
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function dateDaysAgo(days: number): Date;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateDaysAgo = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Returns a Date object representing a date that is a certain number of days in the past.
|
|
6
|
+
* @param days The number of days ago for the date to represent.
|
|
7
|
+
* @returns A Date object representing the date that is the specified number of days in the past.
|
|
8
|
+
* @example ```ts
|
|
9
|
+
* dateDaysAgo(5);;
|
|
10
|
+
* //=> result
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
function dateDaysAgo(days) {
|
|
14
|
+
const date = new Date();
|
|
15
|
+
date.setDate(date.getDate() - days);
|
|
16
|
+
return date;
|
|
17
|
+
}
|
|
18
|
+
exports.dateDaysAgo = dateDaysAgo;
|
|
19
|
+
//# sourceMappingURL=dateDaysAgo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateDaysAgo.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/dateDaysAgo.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;IACnC,OAAO,IAAI,CAAA;AACb,CAAC;AAJD,kCAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dateWeekDayName(date: Date): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateWeekDayName = void 0;
|
|
4
|
+
function dateWeekDayName(date) {
|
|
5
|
+
return names[date.getDay()];
|
|
6
|
+
}
|
|
7
|
+
exports.dateWeekDayName = dateWeekDayName;
|
|
8
|
+
const names = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
9
|
+
//# sourceMappingURL=dateWeekDayName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateWeekDayName.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/dateWeekDayName.ts"],"names":[],"mappings":";;;AAAA,SAAgB,eAAe,CAAC,IAAU;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;AAC7B,CAAC;AAFD,0CAEC;AAED,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the number of days that have passed since the given date.
|
|
3
|
+
* @param date The date from which to calculate the number of days passed.
|
|
4
|
+
* @returns The number of days since the given date.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* new Date('2020-01-01');;
|
|
7
|
+
* //=> <date object>
|
|
8
|
+
* daysSinceDate(new Date('2020-01-01'));;
|
|
9
|
+
* //=> <number of days since 2020-01-01>
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function daysSinceDate(date: Date | number): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.daysSinceDate = void 0;
|
|
4
|
+
const MS_IN_DAY_1 = require("./constants/MS_IN_DAY");
|
|
5
|
+
const msSinceDate_1 = require("./msSinceDate");
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the number of days that have passed since the given date.
|
|
8
|
+
* @param date The date from which to calculate the number of days passed.
|
|
9
|
+
* @returns The number of days since the given date.
|
|
10
|
+
* @example ```ts
|
|
11
|
+
* new Date('2020-01-01');;
|
|
12
|
+
* //=> <date object>
|
|
13
|
+
* daysSinceDate(new Date('2020-01-01'));;
|
|
14
|
+
* //=> <number of days since 2020-01-01>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function daysSinceDate(date) {
|
|
18
|
+
return (0, msSinceDate_1.msSinceDate)(date) / MS_IN_DAY_1.MS_IN_DAY;
|
|
19
|
+
}
|
|
20
|
+
exports.daysSinceDate = daysSinceDate;
|
|
21
|
+
//# sourceMappingURL=daysSinceDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daysSinceDate.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/daysSinceDate.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AACjD,+CAA2C;AAE3C;;;;;;;;;;GAUG;AACH,SAAgB,aAAa,CAAC,IAAmB;IAC/C,OAAO,IAAA,yBAAW,EAAC,IAAI,CAAC,GAAG,qBAAS,CAAA;AACtC,CAAC;AAFD,sCAEC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function takes a year as a parameter and returns the century it belongs to.
|
|
3
|
+
* @param year The year to determine the century for. Must be a valid year number.
|
|
4
|
+
* @returns The century the year belongs to.
|
|
5
|
+
* @throws Will throw an error if the year is not a valid number.
|
|
6
|
+
* @example ```ts
|
|
7
|
+
* getCentury(2000);;
|
|
8
|
+
* //=> 20
|
|
9
|
+
* getCentury(1899);;
|
|
10
|
+
* //=> 19
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function getCentury(year: number): number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCentury = void 0;
|
|
4
|
+
const assertValidDateYear_1 = require("./assertValidDateYear");
|
|
5
|
+
/**
|
|
6
|
+
* This function takes a year as a parameter and returns the century it belongs to.
|
|
7
|
+
* @param year The year to determine the century for. Must be a valid year number.
|
|
8
|
+
* @returns The century the year belongs to.
|
|
9
|
+
* @throws Will throw an error if the year is not a valid number.
|
|
10
|
+
* @example ```ts
|
|
11
|
+
* getCentury(2000);;
|
|
12
|
+
* //=> 20
|
|
13
|
+
* getCentury(1899);;
|
|
14
|
+
* //=> 19
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function getCentury(year) {
|
|
18
|
+
(0, assertValidDateYear_1.assertValidDateYear)(year);
|
|
19
|
+
return Math.floor(year / 100) + 1;
|
|
20
|
+
}
|
|
21
|
+
exports.getCentury = getCentury;
|
|
22
|
+
//# sourceMappingURL=getCentury.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCentury.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/getCentury.ts"],"names":[],"mappings":";;;AAAA,+DAA2D;AAE3D;;;;;;;;;;;GAWG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,IAAA,yCAAmB,EAAC,IAAI,CAAC,CAAA;IACzB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;AACnC,CAAC;AAHD,gCAGC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current year as a number.
|
|
3
|
+
* @remarks This function uses the `getUTCFullYear` method of the `Date` object to get the current year.
|
|
4
|
+
* @returns The current year as a number.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* getCurrentYear();;
|
|
7
|
+
* //=> 2022
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function getCurrentYear(): number;
|