@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurrentYear = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the current year as a number.
|
|
6
|
+
* @remarks This function uses the `getUTCFullYear` method of the `Date` object to get the current year.
|
|
7
|
+
* @returns The current year as a number.
|
|
8
|
+
* @example ```ts
|
|
9
|
+
* getCurrentYear();;
|
|
10
|
+
* //=> 2022
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
function getCurrentYear() {
|
|
14
|
+
return new Date().getUTCFullYear();
|
|
15
|
+
}
|
|
16
|
+
exports.getCurrentYear = getCurrentYear;
|
|
17
|
+
//# sourceMappingURL=getCurrentYear.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCurrentYear.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/getCurrentYear.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,SAAgB,cAAc;IAC5B,OAAO,IAAI,IAAI,EAAE,CAAC,cAAc,EAAE,CAAA;AACpC,CAAC;AAFD,wCAEC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the number of hours that have passed since the given date.
|
|
3
|
+
* @param date The date from which to calculate the number of hours passed.
|
|
4
|
+
* @returns The number of hours that have passed since the given date.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* new Date('2020-01-01T00:00:00Z');;
|
|
7
|
+
* //=> {date object}
|
|
8
|
+
* hoursSinceDate(new Date('2020-01-01T00:00:00Z'));;
|
|
9
|
+
* //=> {number of hours since January 1, 2020}
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function hoursSinceDate(date: Date | number): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hoursSinceDate = void 0;
|
|
4
|
+
const MS_IN_HOUR_1 = require("./constants/MS_IN_HOUR");
|
|
5
|
+
const msSinceDate_1 = require("./msSinceDate");
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the number of hours that have passed since the given date.
|
|
8
|
+
* @param date The date from which to calculate the number of hours passed.
|
|
9
|
+
* @returns The number of hours that have passed since the given date.
|
|
10
|
+
* @example ```ts
|
|
11
|
+
* new Date('2020-01-01T00:00:00Z');;
|
|
12
|
+
* //=> {date object}
|
|
13
|
+
* hoursSinceDate(new Date('2020-01-01T00:00:00Z'));;
|
|
14
|
+
* //=> {number of hours since January 1, 2020}
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function hoursSinceDate(date) {
|
|
18
|
+
return (0, msSinceDate_1.msSinceDate)(date) / MS_IN_HOUR_1.MS_IN_HOUR;
|
|
19
|
+
}
|
|
20
|
+
exports.hoursSinceDate = hoursSinceDate;
|
|
21
|
+
//# sourceMappingURL=hoursSinceDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hoursSinceDate.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/hoursSinceDate.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AACnD,+CAA2C;AAE3C;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAAC,IAAmB;IAChD,OAAO,IAAA,yBAAW,EAAC,IAAI,CAAC,GAAG,uBAAU,CAAA;AACvC,CAAC;AAFD,wCAEC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given year is a leap year.
|
|
3
|
+
* A leap year is exactly divisible by 4 except for century years (years ending with 00).
|
|
4
|
+
* The century year is a leap year only if it is perfectly divisible by 400.
|
|
5
|
+
* @param year The year to check. Must be a valid year number.
|
|
6
|
+
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
7
|
+
* @throws Will throw an error if the year is not a valid number.
|
|
8
|
+
* @example ```ts
|
|
9
|
+
* isLeapYear(2000); ;
|
|
10
|
+
* //=> true
|
|
11
|
+
* isLeapYear(2001); ;
|
|
12
|
+
* //=> false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function isLeapYear(year: number): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLeapYear = void 0;
|
|
4
|
+
const assertValidDateYear_1 = require("./assertValidDateYear");
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a given year is a leap year.
|
|
7
|
+
* A leap year is exactly divisible by 4 except for century years (years ending with 00).
|
|
8
|
+
* The century year is a leap year only if it is perfectly divisible by 400.
|
|
9
|
+
* @param year The year to check. Must be a valid year number.
|
|
10
|
+
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
11
|
+
* @throws Will throw an error if the year is not a valid number.
|
|
12
|
+
* @example ```ts
|
|
13
|
+
* isLeapYear(2000); ;
|
|
14
|
+
* //=> true
|
|
15
|
+
* isLeapYear(2001); ;
|
|
16
|
+
* //=> false
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function isLeapYear(year) {
|
|
20
|
+
(0, assertValidDateYear_1.assertValidDateYear)(year);
|
|
21
|
+
return (0 == year % 4 && 0 != year % 100) || 0 == year % 400;
|
|
22
|
+
}
|
|
23
|
+
exports.isLeapYear = isLeapYear;
|
|
24
|
+
//# sourceMappingURL=isLeapYear.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isLeapYear.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/isLeapYear.ts"],"names":[],"mappings":";;;AAAA,+DAA2D;AAE3D;;;;;;;;;;;;;GAaG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,IAAA,yCAAmB,EAAC,IAAI,CAAC,CAAA;IACzB,OAAO,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,GAAG,CAAA;AAC9D,CAAC;AAHD,gCAGC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the provided date and time values 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 time.
|
|
7
|
+
* @param minute The minute of the time.
|
|
8
|
+
* @param second The second of the time.
|
|
9
|
+
* @param millisecond The millisecond of the time.
|
|
10
|
+
* @returns A boolean indicating whether the provided date and time values form a valid date.
|
|
11
|
+
* @example ```ts
|
|
12
|
+
* isValidDate(2021, 12, 31, 23, 59, 59, 999);;
|
|
13
|
+
* //=> true
|
|
14
|
+
* isValidDate('2021', '12', '31', '23', '59', '59', '999');;
|
|
15
|
+
* //=> true
|
|
16
|
+
* isValidDate(2021, 13, 31, 23, 59, 59, 999);;
|
|
17
|
+
* //=> false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function isValidDate(year?: number | string, month?: number | string, day?: number | string, hour?: number | string, minute?: number | string, second?: number | string, millisecond?: number | string): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidDate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the provided date and time values form a valid date.
|
|
6
|
+
* @param year The year of the date.
|
|
7
|
+
* @param month The month of the date.
|
|
8
|
+
* @param day The day of the date.
|
|
9
|
+
* @param hour The hour of the time.
|
|
10
|
+
* @param minute The minute of the time.
|
|
11
|
+
* @param second The second of the time.
|
|
12
|
+
* @param millisecond The millisecond of the time.
|
|
13
|
+
* @returns A boolean indicating whether the provided date and time values form a valid date.
|
|
14
|
+
* @example ```ts
|
|
15
|
+
* isValidDate(2021, 12, 31, 23, 59, 59, 999);;
|
|
16
|
+
* //=> true
|
|
17
|
+
* isValidDate('2021', '12', '31', '23', '59', '59', '999');;
|
|
18
|
+
* //=> true
|
|
19
|
+
* isValidDate(2021, 13, 31, 23, 59, 59, 999);;
|
|
20
|
+
* //=> false
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function isValidDate(year, month, day, hour, minute, second, millisecond) {
|
|
24
|
+
year = year ? Number(year) : 0;
|
|
25
|
+
month = month ? Number(month) : 0;
|
|
26
|
+
day = day ? Number(day) : 0;
|
|
27
|
+
hour = hour ? Number(hour) : 0;
|
|
28
|
+
minute = minute ? Number(minute) : 0;
|
|
29
|
+
second = second ? Number(second) : 0;
|
|
30
|
+
millisecond = millisecond ? Number(millisecond) : 0;
|
|
31
|
+
const d = new Date(year, month - 1, day, hour, minute, second, millisecond);
|
|
32
|
+
return (d.getFullYear() === year &&
|
|
33
|
+
d.getMonth() + 1 === month &&
|
|
34
|
+
d.getDate() === day &&
|
|
35
|
+
d.getHours() === hour &&
|
|
36
|
+
d.getMinutes() === minute &&
|
|
37
|
+
d.getSeconds() === second &&
|
|
38
|
+
d.getMilliseconds() === millisecond);
|
|
39
|
+
}
|
|
40
|
+
exports.isValidDate = isValidDate;
|
|
41
|
+
//# sourceMappingURL=isValidDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidDate.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/isValidDate.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,WAAW,CACzB,IAAsB,EACtB,KAAuB,EACvB,GAAqB,EACrB,IAAsB,EACtB,MAAwB,EACxB,MAAwB,EACxB,WAA6B;IAE7B,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9B,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACjC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3B,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9B,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACpC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACpC,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACnD,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;IAC3E,OAAO,CACL,CAAC,CAAC,WAAW,EAAE,KAAK,IAAI;QACxB,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,KAAK;QAC1B,CAAC,CAAC,OAAO,EAAE,KAAK,GAAG;QACnB,CAAC,CAAC,QAAQ,EAAE,KAAK,IAAI;QACrB,CAAC,CAAC,UAAU,EAAE,KAAK,MAAM;QACzB,CAAC,CAAC,UAAU,EAAE,KAAK,MAAM;QACzB,CAAC,CAAC,eAAe,EAAE,KAAK,WAAW,CACpC,CAAA;AACH,CAAC;AA1BD,kCA0BC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given day is a valid day of the month.
|
|
3
|
+
* @param day The day of the month. Must be an integer.
|
|
4
|
+
* @param month The month of the year. Must be an integer.
|
|
5
|
+
* @param year The year. Optional parameter. If not provided, the function will not check for leap years.
|
|
6
|
+
* @returns A boolean indicating whether the day is valid for the given month and year.
|
|
7
|
+
* @example ```ts
|
|
8
|
+
* isValidDateDay(31, 1, 2000);
|
|
9
|
+
* //=> true
|
|
10
|
+
* isValidDateDay(31, 2, 2000);
|
|
11
|
+
* //=> false
|
|
12
|
+
* isValidDateDay(29, 2);
|
|
13
|
+
* //=> true
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function isValidDateDay(day: number, month: number, year?: number): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidDateDay = void 0;
|
|
4
|
+
const numDaysInMonth_1 = require("./numDaysInMonth");
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the given day is a valid day of the month.
|
|
7
|
+
* @param day The day of the month. Must be an integer.
|
|
8
|
+
* @param month The month of the year. Must be an integer.
|
|
9
|
+
* @param year The year. Optional parameter. If not provided, the function will not check for leap years.
|
|
10
|
+
* @returns A boolean indicating whether the day is valid for the given month and year.
|
|
11
|
+
* @example ```ts
|
|
12
|
+
* isValidDateDay(31, 1, 2000);
|
|
13
|
+
* //=> true
|
|
14
|
+
* isValidDateDay(31, 2, 2000);
|
|
15
|
+
* //=> false
|
|
16
|
+
* isValidDateDay(29, 2);
|
|
17
|
+
* //=> true
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
function isValidDateDay(day, month, year) {
|
|
21
|
+
if (!Number.isInteger(day))
|
|
22
|
+
return false;
|
|
23
|
+
if (!Number.isInteger(month))
|
|
24
|
+
return false;
|
|
25
|
+
if (year && !Number.isInteger(year))
|
|
26
|
+
return false;
|
|
27
|
+
if (day < 1)
|
|
28
|
+
return false;
|
|
29
|
+
if (day > (0, numDaysInMonth_1.numDaysInMonth)(month, year))
|
|
30
|
+
return false;
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
exports.isValidDateDay = isValidDateDay;
|
|
34
|
+
//# sourceMappingURL=isValidDateDay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidDateDay.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/isValidDateDay.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAEjD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,cAAc,CAAC,GAAW,EAAE,KAAa,EAAE,IAAa;IACtE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA;IACxC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC1C,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IACjD,IAAI,GAAG,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA;IACzB,IAAI,GAAG,GAAG,IAAA,+BAAc,EAAC,KAAK,EAAE,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IACnD,OAAO,IAAI,CAAA;AACb,CAAC;AAPD,wCAOC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the provided month is a valid month number (1-12).
|
|
3
|
+
* @param month The month number to validate.
|
|
4
|
+
* @returns A boolean indicating whether the month is valid.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* isValidDateMonth(5);;
|
|
7
|
+
* //=> true
|
|
8
|
+
* isValidDateMonth(13);;
|
|
9
|
+
* //=> false
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidDateMonth(month: number): boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidDateMonth = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the provided month is a valid month number (1-12).
|
|
6
|
+
* @param month The month number to validate.
|
|
7
|
+
* @returns A boolean indicating whether the month is valid.
|
|
8
|
+
* @example ```ts
|
|
9
|
+
* isValidDateMonth(5);;
|
|
10
|
+
* //=> true
|
|
11
|
+
* isValidDateMonth(13);;
|
|
12
|
+
* //=> false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
function isValidDateMonth(month) {
|
|
16
|
+
return Number.isInteger(month) && month >= 1 && month <= 12;
|
|
17
|
+
}
|
|
18
|
+
exports.isValidDateMonth = isValidDateMonth;
|
|
19
|
+
//# sourceMappingURL=isValidDateMonth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidDateMonth.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/isValidDateMonth.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAA;AAC7D,CAAC;AAFD,4CAEC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the provided year is a valid date year.
|
|
3
|
+
* @remarks This function will return true if the year is a positive integer, false otherwise.
|
|
4
|
+
* @param year The year to be checked.
|
|
5
|
+
* @returns A boolean indicating whether the year is valid or not.
|
|
6
|
+
* @example ```ts
|
|
7
|
+
* isValidDateYear(2020); ;
|
|
8
|
+
* //=> true
|
|
9
|
+
* isValidDateYear(-2020);;
|
|
10
|
+
* //=> false
|
|
11
|
+
* isValidDateYear(2020.5);;
|
|
12
|
+
* //=> false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function isValidDateYear(year: number): boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidDateYear = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the provided year is a valid date year.
|
|
6
|
+
* @remarks This function will return true if the year is a positive integer, false otherwise.
|
|
7
|
+
* @param year The year to be checked.
|
|
8
|
+
* @returns A boolean indicating whether the year is valid or not.
|
|
9
|
+
* @example ```ts
|
|
10
|
+
* isValidDateYear(2020); ;
|
|
11
|
+
* //=> true
|
|
12
|
+
* isValidDateYear(-2020);;
|
|
13
|
+
* //=> false
|
|
14
|
+
* isValidDateYear(2020.5);;
|
|
15
|
+
* //=> false
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function isValidDateYear(year) {
|
|
19
|
+
return Number.isInteger(year) && year >= 0;
|
|
20
|
+
}
|
|
21
|
+
exports.isValidDateYear = isValidDateYear;
|
|
22
|
+
//# sourceMappingURL=isValidDateYear.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidDateYear.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/isValidDateYear.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,SAAgB,eAAe,CAAC,IAAY;IAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,CAAA;AAC5C,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given date to an ISO date timestamp string.
|
|
3
|
+
* If no date is provided, the current date and time will be used.
|
|
4
|
+
* @param - The date to convert. Defaults to the current date and time.
|
|
5
|
+
* @returns The ISO date timestamp string.
|
|
6
|
+
* @example ```ts
|
|
7
|
+
* isoDateTimestamp(new Date('2020-01-01T00:00:00Z'));;
|
|
8
|
+
* //=> "20200101T000000Z"
|
|
9
|
+
* ```
|
|
10
|
+
* @example ```ts
|
|
11
|
+
* const timestamp = isoDateTimestamp();
|
|
12
|
+
* console.log(timestamp); // Outputs the current date and time in ISO format, e.g. "20210520T102030Z"
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function isoDateTimestamp(date?: Date): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isoDateTimestamp = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a given date to an ISO date timestamp string.
|
|
6
|
+
* If no date is provided, the current date and time will be used.
|
|
7
|
+
* @param - The date to convert. Defaults to the current date and time.
|
|
8
|
+
* @returns The ISO date timestamp string.
|
|
9
|
+
* @example ```ts
|
|
10
|
+
* isoDateTimestamp(new Date('2020-01-01T00:00:00Z'));;
|
|
11
|
+
* //=> "20200101T000000Z"
|
|
12
|
+
* ```
|
|
13
|
+
* @example ```ts
|
|
14
|
+
* const timestamp = isoDateTimestamp();
|
|
15
|
+
* console.log(timestamp); // Outputs the current date and time in ISO format, e.g. "20210520T102030Z"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function isoDateTimestamp(date = new Date()) {
|
|
19
|
+
return date.toISOString().replace(/\D/g, '');
|
|
20
|
+
}
|
|
21
|
+
exports.isoDateTimestamp = isoDateTimestamp;
|
|
22
|
+
//# sourceMappingURL=isoDateTimestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isoDateTimestamp.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/isoDateTimestamp.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,SAAgB,gBAAgB,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE;IAChD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC9C,CAAC;AAFD,4CAEC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function takes a date object and returns a string in ISO format suitable for filenames.
|
|
3
|
+
* If no date is provided, it uses the current date and time.
|
|
4
|
+
* @param date The date object to be converted. Defaults to the current date and time.
|
|
5
|
+
* @returns A string in the format "YYYY-MM-DD-HH-MM-SS-SSS".
|
|
6
|
+
* @example ```ts
|
|
7
|
+
* isoDateTimestampForFilename(new Date('2022-01-01T00:00:00Z'));;
|
|
8
|
+
* //=> "2022-01-01-00-00-00-000"
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function isoDateTimestampForFilename(date?: Date): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isoDateTimestampForFilename = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This function takes a date object and returns a string in ISO format suitable for filenames.
|
|
6
|
+
* If no date is provided, it uses the current date and time.
|
|
7
|
+
* @param date The date object to be converted. Defaults to the current date and time.
|
|
8
|
+
* @returns A string in the format "YYYY-MM-DD-HH-MM-SS-SSS".
|
|
9
|
+
* @example ```ts
|
|
10
|
+
* isoDateTimestampForFilename(new Date('2022-01-01T00:00:00Z'));;
|
|
11
|
+
* //=> "2022-01-01-00-00-00-000"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function isoDateTimestampForFilename(date = new Date()) {
|
|
15
|
+
return date
|
|
16
|
+
.toISOString()
|
|
17
|
+
.replace(/[-:T.]/g, '-')
|
|
18
|
+
.replace('Z', '');
|
|
19
|
+
}
|
|
20
|
+
exports.isoDateTimestampForFilename = isoDateTimestampForFilename;
|
|
21
|
+
//# sourceMappingURL=isoDateTimestampForFilename.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isoDateTimestampForFilename.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/isoDateTimestampForFilename.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,SAAgB,2BAA2B,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE;IAC3D,OAAO,IAAI;SACR,WAAW,EAAE;SACb,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AACrB,CAAC;AALD,kEAKC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the number of minutes that have passed since the given date.
|
|
3
|
+
* @param date The date from which to calculate the number of minutes that have passed.
|
|
4
|
+
* @returns The number of minutes that have passed since the given date.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* new Date('2020-01-01T00:00:00Z');;
|
|
7
|
+
* //=> {date}
|
|
8
|
+
* minutesSinceDate(new Date('2020-01-01T00:00:00Z'));;
|
|
9
|
+
* //=> {number of minutes since 2020-01-01T00:00:00Z}
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function minutesSinceDate(date: Date | number): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.minutesSinceDate = void 0;
|
|
4
|
+
const MS_IN_MINUTE_1 = require("./constants/MS_IN_MINUTE");
|
|
5
|
+
const msSinceDate_1 = require("./msSinceDate");
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the number of minutes that have passed since the given date.
|
|
8
|
+
* @param date The date from which to calculate the number of minutes that have passed.
|
|
9
|
+
* @returns The number of minutes that have passed since the given date.
|
|
10
|
+
* @example ```ts
|
|
11
|
+
* new Date('2020-01-01T00:00:00Z');;
|
|
12
|
+
* //=> {date}
|
|
13
|
+
* minutesSinceDate(new Date('2020-01-01T00:00:00Z'));;
|
|
14
|
+
* //=> {number of minutes since 2020-01-01T00:00:00Z}
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function minutesSinceDate(date) {
|
|
18
|
+
return (0, msSinceDate_1.msSinceDate)(date) / MS_IN_MINUTE_1.MS_IN_MINUTE;
|
|
19
|
+
}
|
|
20
|
+
exports.minutesSinceDate = minutesSinceDate;
|
|
21
|
+
//# sourceMappingURL=minutesSinceDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minutesSinceDate.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/minutesSinceDate.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AACvD,+CAA2C;AAE3C;;;;;;;;;;GAUG;AACH,SAAgB,gBAAgB,CAAC,IAAmB;IAClD,OAAO,IAAA,yBAAW,EAAC,IAAI,CAAC,GAAG,2BAAY,CAAA;AACzC,CAAC;AAFD,4CAEC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the number of months that have passed since the provided date.
|
|
3
|
+
* @param date The date from which to calculate the number of passed months.
|
|
4
|
+
* @returns The number of months that have passed since the provided date.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* new Date(2020, 0, 1);;
|
|
7
|
+
* //=> {date}
|
|
8
|
+
* monthsSinceDate(new Date(2020, 0, 1));;
|
|
9
|
+
* //=> {number of months since January 1, 2020}
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function monthsSinceDate(date: Date | number): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.monthsSinceDate = void 0;
|
|
4
|
+
const MS_IN_MONTH_1 = require("./constants/MS_IN_MONTH");
|
|
5
|
+
const msSinceDate_1 = require("./msSinceDate");
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the number of months that have passed since the provided date.
|
|
8
|
+
* @param date The date from which to calculate the number of passed months.
|
|
9
|
+
* @returns The number of months that have passed since the provided date.
|
|
10
|
+
* @example ```ts
|
|
11
|
+
* new Date(2020, 0, 1);;
|
|
12
|
+
* //=> {date}
|
|
13
|
+
* monthsSinceDate(new Date(2020, 0, 1));;
|
|
14
|
+
* //=> {number of months since January 1, 2020}
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function monthsSinceDate(date) {
|
|
18
|
+
return (0, msSinceDate_1.msSinceDate)(date) / MS_IN_MONTH_1.MS_IN_MONTH;
|
|
19
|
+
}
|
|
20
|
+
exports.monthsSinceDate = monthsSinceDate;
|
|
21
|
+
//# sourceMappingURL=monthsSinceDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monthsSinceDate.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/monthsSinceDate.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AACrD,+CAA2C;AAE3C;;;;;;;;;;GAUG;AACH,SAAgB,eAAe,CAAC,IAAmB;IACjD,OAAO,IAAA,yBAAW,EAAC,IAAI,CAAC,GAAG,yBAAW,CAAA;AACxC,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the number of milliseconds that have passed since the provided date.
|
|
3
|
+
* @param date The date from which to calculate the elapsed time.
|
|
4
|
+
* @throws If the provided date is not a Date object or an integer.
|
|
5
|
+
* @returns The number of milliseconds that have passed since the provided date.
|
|
6
|
+
* @example ```ts
|
|
7
|
+
* msSinceDate(new Date('2020-01-01'));;
|
|
8
|
+
* //=> {number of milliseconds since 2020-01-01}
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function msSinceDate(date: Date | number): number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.msSinceDate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the number of milliseconds that have passed since the provided date.
|
|
6
|
+
* @param date The date from which to calculate the elapsed time.
|
|
7
|
+
* @throws If the provided date is not a Date object or an integer.
|
|
8
|
+
* @returns The number of milliseconds that have passed since the provided date.
|
|
9
|
+
* @example ```ts
|
|
10
|
+
* msSinceDate(new Date('2020-01-01'));;
|
|
11
|
+
* //=> {number of milliseconds since 2020-01-01}
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function msSinceDate(date) {
|
|
15
|
+
if (typeof date === 'number') {
|
|
16
|
+
if (!Number.isInteger(date)) {
|
|
17
|
+
throw new Error('Expected date to be a Date or an integer. Got: ' + date);
|
|
18
|
+
}
|
|
19
|
+
date = new Date(date);
|
|
20
|
+
}
|
|
21
|
+
return Date.now() - date.getTime();
|
|
22
|
+
}
|
|
23
|
+
exports.msSinceDate = msSinceDate;
|
|
24
|
+
//# sourceMappingURL=msSinceDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msSinceDate.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/msSinceDate.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,SAAgB,WAAW,CAAC,IAAmB;IAC7C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,iDAAiD,GAAG,IAAI,CAAC,CAAA;SAC1E;QACD,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAA;KACtB;IACD,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;AACpC,CAAC;AARD,kCAQC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get number of days that there are in a given month of a given year.
|
|
3
|
+
* Note: The number of days in february depends on whether it is leap year. If no year is given, it is assumed that it is not leap year.
|
|
4
|
+
* @param month The month for which the number of days is to be calculated. Should be a number between 1 and 12.
|
|
5
|
+
* @param year The year for which the number of days in the month is to be calculated. Optional.
|
|
6
|
+
* @returns The number of days in the given month for the specified year.
|
|
7
|
+
* @throws Will throw an error if the month is not a valid number between 1 and 12.
|
|
8
|
+
* @example ```ts
|
|
9
|
+
* numDaysInMonth(2, 2020);;
|
|
10
|
+
* //=> 29
|
|
11
|
+
* numDaysInMonth(2);;
|
|
12
|
+
* //=> 28
|
|
13
|
+
* numDaysInMonth(1);;
|
|
14
|
+
* //=> 31
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function numDaysInMonth(month: number, year?: number): number;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.numDaysInMonth = void 0;
|
|
4
|
+
const assertValidDateMonth_1 = require("./assertValidDateMonth");
|
|
5
|
+
const isLeapYear_1 = require("./isLeapYear");
|
|
6
|
+
/**
|
|
7
|
+
* Get number of days that there are in a given month of a given year.
|
|
8
|
+
* Note: The number of days in february depends on whether it is leap year. If no year is given, it is assumed that it is not leap year.
|
|
9
|
+
* @param month The month for which the number of days is to be calculated. Should be a number between 1 and 12.
|
|
10
|
+
* @param year The year for which the number of days in the month is to be calculated. Optional.
|
|
11
|
+
* @returns The number of days in the given month for the specified year.
|
|
12
|
+
* @throws Will throw an error if the month is not a valid number between 1 and 12.
|
|
13
|
+
* @example ```ts
|
|
14
|
+
* numDaysInMonth(2, 2020);;
|
|
15
|
+
* //=> 29
|
|
16
|
+
* numDaysInMonth(2);;
|
|
17
|
+
* //=> 28
|
|
18
|
+
* numDaysInMonth(1);;
|
|
19
|
+
* //=> 31
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function numDaysInMonth(month, year) {
|
|
23
|
+
(0, assertValidDateMonth_1.assertValidDateMonth)(month);
|
|
24
|
+
const DAYS_IN_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
25
|
+
return month === 2 && year !== undefined && (0, isLeapYear_1.isLeapYear)(year) ? 29 : DAYS_IN_MONTH[month];
|
|
26
|
+
}
|
|
27
|
+
exports.numDaysInMonth = numDaysInMonth;
|
|
28
|
+
//# sourceMappingURL=numDaysInMonth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numDaysInMonth.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/numDaysInMonth.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAC7D,6CAAyC;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,cAAc,CAAC,KAAa,EAAE,IAAa;IACzD,IAAA,2CAAoB,EAAC,KAAK,CAAC,CAAA;IAC3B,MAAM,aAAa,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;IACzE,OAAO,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAA,uBAAU,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AAC1F,CAAC;AAJD,wCAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prettyIsoDateString(iso: string, dateTimeSeparator?: string, precision?: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prettyIsoDateString = void 0;
|
|
4
|
+
function prettyIsoDateString(iso, dateTimeSeparator = '_', precision = 'millisecond') {
|
|
5
|
+
return iso.substring(0, map[precision]).replace(/T/, dateTimeSeparator).replace(/-|:/g, '.');
|
|
6
|
+
}
|
|
7
|
+
exports.prettyIsoDateString = prettyIsoDateString;
|
|
8
|
+
const map = {
|
|
9
|
+
year: 4,
|
|
10
|
+
month: 7,
|
|
11
|
+
day: 10,
|
|
12
|
+
hour: 13,
|
|
13
|
+
minute: 16,
|
|
14
|
+
second: 19,
|
|
15
|
+
millisecond: 23,
|
|
16
|
+
};
|
|
17
|
+
// const s = '2020-02-03T14:01:04.437Z'
|
|
18
|
+
// console.log(prettyIsoDateString(s, '_', 'year'))
|
|
19
|
+
// console.log(prettyIsoDateString(s, '_', 'month'))
|
|
20
|
+
// console.log(prettyIsoDateString(s, '_', 'day'))
|
|
21
|
+
// console.log(prettyIsoDateString(s, '_', 'hour'))
|
|
22
|
+
// console.log(prettyIsoDateString(s, '_', 'minute'))
|
|
23
|
+
// console.log(prettyIsoDateString(s, '_', 'second'))
|
|
24
|
+
// console.log(prettyIsoDateString(s, '_', 'millisecond'))
|
|
25
|
+
//# sourceMappingURL=prettyIsoDateString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prettyIsoDateString.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/prettyIsoDateString.ts"],"names":[],"mappings":";;;AAAA,SAAgB,mBAAmB,CACjC,GAAW,EACX,iBAAiB,GAAG,GAAG,EACvB,YAAqF,aAAa;IAElG,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC9F,CAAC;AAND,kDAMC;AAED,MAAM,GAAG,GAAG;IACV,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;IACV,WAAW,EAAE,EAAE;CAChB,CAAA;AAED,uCAAuC;AACvC,mDAAmD;AACnD,oDAAoD;AACpD,kDAAkD;AAClD,mDAAmD;AACnD,qDAAqD;AACrD,qDAAqD;AACrD,0DAA0D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the number of seconds that have passed since the given date.
|
|
3
|
+
* @param date The date from which to calculate the number of seconds.
|
|
4
|
+
* @returns The number of seconds since the given date.
|
|
5
|
+
* @example ```ts
|
|
6
|
+
* secondsSinceDate(new Date('2020-01-01'));;
|
|
7
|
+
* //=> {number of seconds since 2020-01-01}
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function secondsSinceDate(date: Date | number): number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.secondsSinceDate = void 0;
|
|
4
|
+
const MS_IN_SECOND_1 = require("./constants/MS_IN_SECOND");
|
|
5
|
+
const msSinceDate_1 = require("./msSinceDate");
|
|
6
|
+
/**
|
|
7
|
+
* Returns the number of seconds that have passed since the given date.
|
|
8
|
+
* @param date The date from which to calculate the number of seconds.
|
|
9
|
+
* @returns The number of seconds since the given date.
|
|
10
|
+
* @example ```ts
|
|
11
|
+
* secondsSinceDate(new Date('2020-01-01'));;
|
|
12
|
+
* //=> {number of seconds since 2020-01-01}
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
function secondsSinceDate(date) {
|
|
16
|
+
return (0, msSinceDate_1.msSinceDate)(date) / MS_IN_SECOND_1.MS_IN_SECOND;
|
|
17
|
+
}
|
|
18
|
+
exports.secondsSinceDate = secondsSinceDate;
|
|
19
|
+
//# sourceMappingURL=secondsSinceDate.js.map
|