Bug 1592536 - Fix contact age calculation in address book. r+a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 04 Nov 2019 21:59:45 +1300
changeset 36375 48cd321f476533f865ecfccca545056e6b7f410c
parent 36374 0dc166cf7ad001f0b78a44f49f7f881bedea967e
child 36376 f28c010aac310532478294838f0c4ae9d988c9c8
push id2521
push usermozilla@jorgk.com
push dateWed, 06 Nov 2019 09:31:04 +0000
treeherdercomm-beta@308f336efa3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1592536
Bug 1592536 - Fix contact age calculation in address book. r+a=jorgk
mail/components/addrbook/content/abCard.js
--- a/mail/components/addrbook/content/abCard.js
+++ b/mail/components/addrbook/content/abCard.js
@@ -844,36 +844,40 @@ function calculateAge() {
 
   if (birthMonth == -1 || birthDay == -1) {
     return;
   }
   if (isNaN(birthYear) || birthYear < kMinYear || birthYear > kMaxYear) {
     return;
   }
 
+  birthMonth--; // Date object months are 0-indexed.
   let today = new Date();
   let age = today.getFullYear() - birthYear;
   if (birthMonth > today.getMonth()) {
     age--;
   } else if (birthMonth == today.getMonth() && birthDay > today.getDate()) {
     age--;
   }
-  document.getElementById("Age").value = age;
+  if (age >= 0) {
+    document.getElementById("Age").value = age;
+  }
 }
 
 function calculateYear() {
   let age = document.getElementById("Age").value;
   if (isNaN(age)) {
     return;
   }
 
   let today = new Date();
   let year = today.getFullYear() - age;
 
   let birthMonth = document.getElementById("BirthMonth").value;
+  birthMonth--; // Date object months are 0-indexed.
   let birthDay = document.getElementById("BirthDay").value;
   if (birthMonth > today.getMonth()) {
     year--;
   } else if (birthMonth == today.getMonth() && birthDay > today.getDate()) {
     year--;
   }
   document.getElementById("BirthYear").value = year;
   setDisabledMonthDays();