Properly compute new schedule date when old is in past
This commit is contained in:
parent
9144314eac
commit
c17cc50229
|
@ -363,25 +363,28 @@ public class RNFirebaseNotificationManager {
|
||||||
if (fireDate < System.currentTimeMillis()) {
|
if (fireDate < System.currentTimeMillis()) {
|
||||||
Log.w(TAG, "Scheduled notification date is in the past, will adjust it to be in future");
|
Log.w(TAG, "Scheduled notification date is in the past, will adjust it to be in future");
|
||||||
Calendar newFireDate = Calendar.getInstance();
|
Calendar newFireDate = Calendar.getInstance();
|
||||||
Calendar currentFireDate = Calendar.getInstance();
|
Calendar pastFireDate = Calendar.getInstance();
|
||||||
currentFireDate.setTimeInMillis(fireDate);
|
pastFireDate.setTimeInMillis(fireDate);
|
||||||
|
|
||||||
newFireDate.set(Calendar.DATE, currentFireDate.get(Calendar.DATE));
|
newFireDate.set(Calendar.SECOND, pastFireDate.get(Calendar.SECOND));
|
||||||
newFireDate.set(Calendar.HOUR_OF_DAY, currentFireDate.get(Calendar.HOUR_OF_DAY));
|
|
||||||
newFireDate.set(Calendar.MINUTE, currentFireDate.get(Calendar.MINUTE));
|
|
||||||
newFireDate.set(Calendar.SECOND, currentFireDate.get(Calendar.SECOND));
|
|
||||||
|
|
||||||
switch (schedule.getString("repeatInterval")) {
|
switch (schedule.getString("repeatInterval")) {
|
||||||
case "minute":
|
case "minute":
|
||||||
newFireDate.add(Calendar.MINUTE, 1);
|
newFireDate.add(Calendar.MINUTE, 1);
|
||||||
break;
|
break;
|
||||||
case "hour":
|
case "hour":
|
||||||
|
newFireDate.set(Calendar.MINUTE, pastFireDate.get(Calendar.MINUTE));
|
||||||
newFireDate.add(Calendar.HOUR, 1);
|
newFireDate.add(Calendar.HOUR, 1);
|
||||||
break;
|
break;
|
||||||
case "day":
|
case "day":
|
||||||
|
newFireDate.set(Calendar.MINUTE, pastFireDate.get(Calendar.MINUTE));
|
||||||
|
newFireDate.set(Calendar.HOUR_OF_DAY, pastFireDate.get(Calendar.HOUR_OF_DAY));
|
||||||
newFireDate.add(Calendar.DATE, 1);
|
newFireDate.add(Calendar.DATE, 1);
|
||||||
break;
|
break;
|
||||||
case "week":
|
case "week":
|
||||||
|
newFireDate.set(Calendar.MINUTE, pastFireDate.get(Calendar.MINUTE));
|
||||||
|
newFireDate.set(Calendar.HOUR_OF_DAY, pastFireDate.get(Calendar.HOUR_OF_DAY));
|
||||||
|
newFireDate.set(Calendar.DATE, pastFireDate.get(Calendar.DATE));
|
||||||
newFireDate.add(Calendar.DATE, 7);
|
newFireDate.add(Calendar.DATE, 7);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue