Commit 07f860ab authored by Robert Hitt's avatar Robert Hitt
Browse files

Notifications can no longer be set in the past

parent 39a597fb
Pipeline #784 passed with stages
in 4 minutes and 47 seconds
...@@ -273,7 +273,7 @@ public class NotificationPresenter { ...@@ -273,7 +273,7 @@ public class NotificationPresenter {
alarm.cancel(pendingIntent); alarm.cancel(pendingIntent);
} }
private Long parseTimeString(String timeString, int day, boolean thisWeek) { private Long parseTimeString(String timeString, int day, boolean timeIsPassed) {
Calendar alarmCalendar = Calendar.getInstance(); Calendar alarmCalendar = Calendar.getInstance();
int month = alarmCalendar.get(Calendar.MONTH); int month = alarmCalendar.get(Calendar.MONTH);
int dayOfMonth = alarmCalendar.get(Calendar.DAY_OF_MONTH); int dayOfMonth = alarmCalendar.get(Calendar.DAY_OF_MONTH);
...@@ -290,7 +290,7 @@ public class NotificationPresenter { ...@@ -290,7 +290,7 @@ public class NotificationPresenter {
alarmCalendar.set(year, month, dayOfMonth); alarmCalendar.set(year, month, dayOfMonth);
// to make sure that the alarm isn't set in the past // to make sure that the alarm isn't set in the past
if(!thisWeek) if(timeIsPassed)
alarmCalendar.add(Calendar.DATE, 1); alarmCalendar.add(Calendar.DATE, 1);
// set the day to the next day matching the given day of the week // set the day to the next day matching the given day of the week
...@@ -331,7 +331,6 @@ public class NotificationPresenter { ...@@ -331,7 +331,6 @@ public class NotificationPresenter {
} }
// Determines if the given time is earlier in the current day // Determines if the given time is earlier in the current day
// TODO: does not seem to work
private boolean timeIsPassed(String time, int day) { private boolean timeIsPassed(String time, int day) {
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
...@@ -341,7 +340,9 @@ public class NotificationPresenter { ...@@ -341,7 +340,9 @@ public class NotificationPresenter {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
try { try {
Date timeDate = sdf.parse(time); Date timeDate = sdf.parse(time);
return now.getTime().compareTo(timeDate) > 0; Date currentDate = sdf.parse(sdf.format(now.getTime()));
return currentDate.compareTo(timeDate) > 0;
} catch (ParseException pe) { } catch (ParseException pe) {
pe.printStackTrace(); pe.printStackTrace();
return false; return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment