@ejfdelgado/ejflab-common 1.14.4 → 1.15.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/MyDates.js +22 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.14.4",
4
+ "version": "1.15.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
package/src/MyDates.js CHANGED
@@ -448,6 +448,28 @@ class MyDates {
448
448
  var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
449
449
  return hDisplay + mDisplay + sDisplay;
450
450
  }
451
+
452
+ static age(dateMillis) {
453
+ if (typeof dateMillis == 'number' && !isNaN(dateMillis)) {
454
+ const dateOfBirth = new Date(dateMillis);
455
+ const dayOfBirth = dateOfBirth.getDate();
456
+ const millisDifference = new Date().getTime() - dateOfBirth.getTime();
457
+ const date = new Date(millisDifference);
458
+ const years = date.getFullYear() - 1970;
459
+ const months = date.getMonth();
460
+ let days = date.getDate();
461
+ if (days > dayOfBirth) {
462
+ days = date.getDate() - dayOfBirth;
463
+ }
464
+ const model = {
465
+ years,
466
+ months,
467
+ days
468
+ };
469
+ return model;
470
+ }
471
+ return null;
472
+ }
451
473
  }
452
474
 
453
475
  module.exports = {