FB: Testing when a SMS should be sent

by milesmatthias

JavaScript

function shouldSendBirthdayReminder(birthdate) {
  if(!birthdate){console.error('Error in shouldSendBirthdayReminder: birthdate is null');return false;}
  
  var today = new Date(),
      ellapsedMS = today - birthdate,
      daysTillBirthday = ellapsedMS / (1000 * 60 * 60 * 24),
      ret = false;

  console.log('birthdate: ' + birthdate);
  console.log('daysTillBirthday: ' + daysTillBirthday);

  // Only send texts when day is 7, 5, 3, and 1 days away.
  if (daysTillBirthday < 8 && daysTillBirthday % 2 >= 1){
    ret = true;
  }

  return ret;
}
      
console.log(shouldSendBirthdayReminder());