Local notification not getting triggered on exact set time and is not consistent on ionic


#1

Issue :
As a part of my project requirement, I need to display local-notification exactly at 7:07am, 8:08am upto 8:08pm except 9:09. But sometimes, local-nitifications are delayed by 2-3 minutes & sometimes it completely misbehaves.
Ex. - notification for 10:10am gets triggered at 11:10pm. Is it possible to display notifications exactly at desired time?

setSamaySampanata(){
let dt = new Date();
//console.log("----- peacePrayer.ts ---- setSamaySampanata() ---- Scheduling All Samay Sampanata reminders -----");
if( this.wantSamaySampanat == true ) {
console.log("----- peacePrayer.ts ---- setSamaySampanata() ---- Scheduling All Samay Sampanata reminders -----" + dt.getHours() +dt.getMinutes());
let seven = 0;
let eigth = 0;
let ten = 0;
let eleven = 0;
let twelv = 0;
let one = 0;
let two = 0;
let three = 0;
let four = 0;
let five = 0;
let six = 0;
let sevenPM = 0;
let eigthPM = 0;

		if((dt.getHours() == 7  && dt.getMinutes() > 7) || (dt.getHours() == 8  && dt.getMinutes() < 8)){
			 seven = 1;
			 console.log("------setSamaySampanata-----after-----seven")
		 }
		if((dt.getHours() == 8  && dt.getMinutes() > 8) || (dt.getHours() == 10  && dt.getMinutes() < 10)){
			 eigth = 1;
			 console.log("------setSamaySampanata-----after-----eigth")
		 }
		if((dt.getHours() == 10  && dt.getMinutes() > 10) || (dt.getHours() == 11  && dt.getMinutes() < 11)){
			 ten = 1;
			 console.log("------setSamaySampanata-----after-----ten")
		 }
		if((dt.getHours() == 11  && dt.getMinutes() > 11) || (dt.getHours() == 12  && dt.getMinutes() < 12)){
			 eleven = 1;
			 console.log("------setSamaySampanata-----after-----eleven")
		 }
		if((dt.getHours() == 12  && dt.getMinutes() > 12) || (dt.getHours() == 13  && dt.getMinutes() < 1)){
			 twelv = 1;
			 console.log("------setSamaySampanata-----after-----twelv")
		 }
		if((dt.getHours() == 13  && dt.getMinutes() > 1) || (dt.getHours() == 14  && dt.getMinutes() < 2)){
			 one = 1;
			 console.log("------setSamaySampanata-----after-----one")
		 }
		if((dt.getHours() == 14  && dt.getMinutes() > 2) || (dt.getHours() == 15  && dt.getMinutes() < 3)){
			 two = 1;
			 console.log("------setSamaySampanata-----after-----two")
		 }
		if((dt.getHours() == 15  && dt.getMinutes() > 3) || (dt.getHours() == 16  && dt.getMinutes() < 4)){
			 three = 1;
			 console.log("------setSamaySampanata-----after-----three")
		 }
		if((dt.getHours() == 16  && dt.getMinutes() > 4) || (dt.getHours() == 17  && dt.getMinutes() < 5)){
			 four = 1;
			 console.log("------setSamaySampanata-----after-----four")
		 }
		if((dt.getHours() == 17  && dt.getMinutes() > 5) || (dt.getHours() == 18  && dt.getMinutes() < 6)){
			 five = 1;
			 console.log("------setSamaySampanata-----after-----five")
		 }
		if((dt.getHours() == 18  && dt.getMinutes() > 6) || (dt.getHours() == 19  && dt.getMinutes() < 7)){
			 six = 1;
			 console.log("------setSamaySampanata-----after-----six")
		 }
		if((dt.getHours() == 19  && dt.getMinutes() > 7) || (dt.getHours() == 20  && dt.getMinutes() < 8)){
			 sevenPM = 1;
			 console.log("------setSamaySampanata-----after-----seven")
		 }
		if(dt.getHours() == 20  && dt.getMinutes() > 8){
			 eigthPM = 1;
			 console.log("------setSamaySampanata-----after-----eigthPM")
		 }
			 
	LocalNotifications.schedule([{
          id: 707,
          title: '07:07 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + seven) +" 07:07:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
          id: 808,  
          title: '08:08 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + eigth) +" 08:08:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1010,
          title: '10:10 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + ten)  +" 10:10:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1111,
          title: '11:11 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + eleven)  +" 11:11:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1212,
          title: '12:12 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + twelv)  +" 12:12:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1301,
          title: '01:01 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + one)  +" 13:01:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1402,
          title: '02:02 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + two)  +" 14:02:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1503,
          title: '03:03 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + three)  +" 15:03:01 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1604,
          title: '04:04 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + four)  +" 16:04:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1705,
          title: '05:05 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + five)  +" 17:05:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1806,
          title: '06:06 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + six)  +" 18:06:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 1907,
          title: '07:07 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + sevenPM)  +" 19:07:00 +0530")),
          led: '0000FF',
		        every: 'day',
		        sound: 'file://audio/SamaySampannaRing.mp3'
      },{
					  id: 2008,
          title: '08:08 SAMAY SAMPANATA Reminder',
          text: 'This is hourly reminder for SAMAY SAMPANATA.',
          at: new Date(Date.parse(dt.getFullYear() +"-" + (dt.getMonth() + 1) + "-" + (dt.getDate() + eigthPM)  +" 20:08:00 +0530")),
          led: '0000FF',
		        every: 'day',
		       // sound: 'res://platform_default'
					  sound: 'file://audio/SamaySampannaRing.mp3'
				}]);
	}else{
		//console.log("----- peacePrayer.ts ---- setSamaySampanata() ---- Canceling All Samay Sampanata reminders -----");
		LocalNotifications.cancel([707,808,1010,1111,1212,1301,1402,1503,1604,1705,1806,1907,2008]);
	}
}