heartraite 1.0.83 → 1.0.84
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function calculateAgeFromDateString(isoDateString: string): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateAgeFromDateString = calculateAgeFromDateString;
|
|
4
|
+
function calculateAgeFromDateString(isoDateString) {
|
|
5
|
+
const birthDate = new Date(isoDateString);
|
|
6
|
+
const today = new Date();
|
|
7
|
+
const ageDiff = today.getFullYear() - birthDate.getFullYear();
|
|
8
|
+
const hasBirthdayPassed = today.getMonth() > birthDate.getMonth() ||
|
|
9
|
+
(today.getMonth() === birthDate.getMonth() &&
|
|
10
|
+
today.getDate() >= birthDate.getDate());
|
|
11
|
+
return hasBirthdayPassed ? ageDiff : ageDiff - 1;
|
|
12
|
+
}
|
package/dist/utils/date/index.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function calculateAgeFromDateString(isoDateString: string): number {
|
|
2
|
+
const birthDate = new Date(isoDateString);
|
|
3
|
+
const today = new Date();
|
|
4
|
+
|
|
5
|
+
const ageDiff = today.getFullYear() - birthDate.getFullYear();
|
|
6
|
+
const hasBirthdayPassed =
|
|
7
|
+
today.getMonth() > birthDate.getMonth() ||
|
|
8
|
+
(today.getMonth() === birthDate.getMonth() &&
|
|
9
|
+
today.getDate() >= birthDate.getDate());
|
|
10
|
+
|
|
11
|
+
return hasBirthdayPassed ? ageDiff : ageDiff - 1;
|
|
12
|
+
}
|
package/src/utils/date/index.ts
CHANGED