diff --git a/local-notifications/README.md b/local-notifications/README.md index a5d6d998b..2616cd903 100644 --- a/local-notifications/README.md +++ b/local-notifications/README.md @@ -382,6 +382,7 @@ Enables basic storage and retrieval of dates and times. | **`day`** | number | | **`hour`** | number | | **`minute`** | number | +| **`second`** | number | #### Attachment diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/DateMatch.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/DateMatch.java index f1a131724..323ed22f7 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/DateMatch.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/DateMatch.java @@ -16,6 +16,7 @@ public class DateMatch { private Integer day; private Integer hour; private Integer minute; + private Integer second; // Unit used to save the last used unit for a trigger. // One of the Calendar constants values @@ -63,6 +64,14 @@ public void setMinute(Integer minute) { this.minute = minute; } + public Integer getSecond() { + return second; + } + + public void setSecond(Integer second) { + this.second = second; + } + /** * Gets a calendar instance pointing to the specified date. * @@ -72,7 +81,6 @@ private Calendar buildCalendar(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.MILLISECOND, 0); - cal.set(Calendar.SECOND, 0); return cal; } @@ -102,6 +110,8 @@ private long postponeTriggerIfNeeded(Calendar current, Calendar next) { incrementUnit = Calendar.DAY_OF_MONTH; } else if (unit == Calendar.MINUTE) { incrementUnit = Calendar.HOUR_OF_DAY; + } else if (unit == Calendar.SECOND) { + incrementUnit = Calendar.MINUTE; } if (incrementUnit != -1) { @@ -133,12 +143,31 @@ private Calendar buildNextTriggerTime(Date date) { next.set(Calendar.MINUTE, minute); if (unit == -1) unit = Calendar.MINUTE; } + if (second != null) { + next.set(Calendar.SECOND, second); + if (unit == -1) unit = Calendar.SECOND; + } return next; } @Override public String toString() { - return "DateMatch{" + "year=" + year + ", month=" + month + ", day=" + day + ", hour=" + hour + ", minute=" + minute + '}'; + return ( + "DateMatch{" + + "year=" + + year + + ", month=" + + month + + ", day=" + + day + + ", hour=" + + hour + + ", minute=" + + minute + + ", second=" + + second + + '}' + ); } @Override @@ -152,7 +181,8 @@ public boolean equals(Object o) { if (month != null ? !month.equals(dateMatch.month) : dateMatch.month != null) return false; if (day != null ? !day.equals(dateMatch.day) : dateMatch.day != null) return false; if (hour != null ? !hour.equals(dateMatch.hour) : dateMatch.hour != null) return false; - return minute != null ? minute.equals(dateMatch.minute) : dateMatch.minute == null; + if (minute != null ? !minute.equals(dateMatch.minute) : dateMatch.minute != null) return false; + return second != null ? second.equals(dateMatch.second) : dateMatch.second == null; } @Override @@ -162,6 +192,7 @@ public int hashCode() { result = 31 * result + (day != null ? day.hashCode() : 0); result = 31 * result + (hour != null ? hour.hashCode() : 0); result = 31 * result + (minute != null ? minute.hashCode() : 0); + result = 31 + result + (second != null ? second.hashCode() : 0); return result; } @@ -171,7 +202,8 @@ public int hashCode() { * @return */ public String toMatchString() { - String matchString = year + separator + month + separator + day + separator + hour + separator + minute + separator + unit; + String matchString = + year + separator + month + separator + day + separator + hour + separator + minute + separator + second + separator + unit; return matchString.replace("null", "*"); } @@ -192,6 +224,17 @@ public static DateMatch fromMatchString(String matchString) { date.setMinute(getValueFromCronElement(split[4])); date.setUnit(getValueFromCronElement(split[5])); } + + if (split != null && split.length == 7) { + date.setYear(getValueFromCronElement(split[0])); + date.setMonth(getValueFromCronElement(split[1])); + date.setDay(getValueFromCronElement(split[2])); + date.setHour(getValueFromCronElement(split[3])); + date.setMinute(getValueFromCronElement(split[4])); + date.setSecond(getValueFromCronElement(split[5])); + date.setUnit(getValueFromCronElement(split[6])); + } + return date; } diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationSchedule.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationSchedule.java index ade6c554e..da6819dd2 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationSchedule.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationSchedule.java @@ -67,6 +67,7 @@ private void buildOnElement(JSObject schedule) { on.setDay(onJson.getInteger("day")); on.setHour(onJson.getInteger("hour")); on.setMinute(onJson.getInteger("minute")); + on.setSecond(onJson.getInteger("second")); } } diff --git a/local-notifications/src/definitions.ts b/local-notifications/src/definitions.ts index 0859fb740..c084ca801 100644 --- a/local-notifications/src/definitions.ts +++ b/local-notifications/src/definitions.ts @@ -734,6 +734,7 @@ export interface ScheduleOn { day?: number; hour?: number; minute?: number; + second?: number; } export type ScheduleEvery =