@star-insure/sdk 4.1.2 → 4.1.3

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
@@ -2,7 +2,7 @@
2
2
  "name": "@star-insure/sdk",
3
3
  "description": "The SDK for Star Insure client apps with shared helper functions and TypeScript definitions.",
4
4
  "author": "alexclark_nz",
5
- "version": "4.1.2",
5
+ "version": "4.1.3",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,19 +1,26 @@
1
1
  /**
2
2
  * Calculate someone's age from a date of birth.
3
- * @param date YYYY-MM-DD
4
3
  */
5
- export function calculateAge(date: string): number {
6
- const today = new Date();
4
+ export function calculateAge(date: string|Date|null|undefined): number {
5
+ if (!date) {
6
+ return 0;
7
+ }
7
8
 
8
- const birthDate = new Date(date);
9
+ try {
10
+ const today = new Date();
9
11
 
10
- const age = today.getFullYear() - birthDate.getFullYear();
12
+ const birthDate = new Date(date);
11
13
 
12
- const m = today.getMonth() - birthDate.getMonth();
14
+ const age = today.getFullYear() - birthDate.getFullYear();
15
+ const m = today.getMonth() - birthDate.getMonth();
13
16
 
14
- if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
15
- return age - 1;
16
- }
17
+ if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
18
+ return age - 1;
19
+ }
17
20
 
18
- return age;
21
+ return age;
22
+ } catch (error) {
23
+ console.error(error);
24
+ return 0;
25
+ }
19
26
  }