Nitin Agarwal
Nitin Agarwal

Reputation: 941

I want localnotification in ionic based on particular from and to date with time using angular js

I want to show the local notification based on the user scheduled particular dates like from date, to date and their selected time. I am using the $cordovaLocalNotification.schedule

$cordovaLocalNotification.schedule({
        title: data.name,
        text: data.name,
        at: data.time
      })`

here i want to schedule this notification for the date and time which user has selected.

Please if you know, suggest answer, rather than mark it as duplicate or vote donw or anything else.

Thanks

Upvotes: 1

Views: 215

Answers (2)

ANK
ANK

Reputation: 293

As already i said, first check the condition from date and to date. Later get the dates between those to date as follows check this fiddle to get dates or check below code, here the loops rotates.

  while(fromdate<=todate){
   var d=new Date(fromdate);
  d.setDate(d.getDate()+1)
  $cordovaLocalNotification.schedule({
    title: data.name,
    text: data.name,
    at: data.time
  })
}

So, now the local notification will be scheduled for all dates taken from the user.

You can go with the above code or with the fiddle to get the between dates including from date and to date.

Here "at:" key will be the current date and user time need to format with new Date. like this,

 var notify=new Date(fromdate+ ' ' + <usertime>)
 $cordovaLocalNotification.schedule({
title: data.name,
text: data.name,
at: notify
 })

Upvotes: 1

ANK
ANK

Reputation: 293

To show the local notification based on from date and to date, try this,

var currtime=filter('date')(new Date(),'MM-dd-yy');

here you can change the format of date as per your need, now check the condition while loading data whether from date and to date is between it or not.

item.fromdate<=currtime && item.todate>=currtime

now you can place the local notification.

Upvotes: 1

Related Questions