Fix for setting past time in the scheduling.

This commit is contained in:
ifsnow 2018-07-05 14:55:39 +09:00
parent 654c6813d1
commit 5a21837fb9
1 changed files with 16 additions and 0 deletions

View File

@ -36,6 +36,7 @@ import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -357,6 +358,21 @@ public class RNFirebaseNotificationManager {
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (schedule.containsKey("repeatInterval")) { if (schedule.containsKey("repeatInterval")) {
// If fireDate you specify is in the past, the alarm triggers immediately.
// So we need to adjust the time for correct operation.
if (fireDate < System.currentTimeMillis()) {
Calendar newFireDate = Calendar.getInstance();
Calendar currentFireDate = Calendar.getInstance();
currentFireDate.setTimeInMillis(fireDate);
newFireDate.add(Calendar.DATE, 1);
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));
fireDate = newFireDate.getTimeInMillis();
}
Long interval = null; Long interval = null;
switch (schedule.getString("repeatInterval")) { switch (schedule.getString("repeatInterval")) {
case "minute": case "minute":