From c5178ea441664ff370f2b63091d0fa166f1909c9 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Mon, 27 Aug 2018 16:17:05 +0200 Subject: [PATCH] If time has already passed, start notification tomorrow --- lib/notifications.js | 16 +++++++++++----- package.json | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/notifications.js b/lib/notifications.js index 3d34661..dc1a7a5 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -1,6 +1,7 @@ import {tempReminderObservable} from '../local-storage' import Notification from 'react-native-push-notification' import { LocalDate } from 'js-joda' +import Moment from 'moment' import { settings as labels } from '../components/labels' import { getOrCreateCycleDay } from '../db' @@ -16,14 +17,19 @@ export default function setupNotifications(navigate) { tempReminderObservable(reminder => { Notification.cancelAllLocalNotifications() if (reminder.enabled) { - const date = new Date() const [hours, minutes] = reminder.time.split(':') - date.setHours(parseInt(hours)) - date.setMinutes(parseInt(minutes)) - date.setSeconds(0) + let target = new Moment() + .hours(parseInt(hours)) + .minutes(parseInt(minutes)) + .seconds(0) + + if(target.isBefore(new Moment())) { + target = target.add(1, 'd') + } + Notification.localNotificationSchedule({ message: labels.tempReminder.notification, - date, + date: target.toDate(), vibrate: false, repeatType: 'day' }) diff --git a/package.json b/package.json index 66497ad..11c62a8 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "isobject": "^3.0.1", "js-base64": "^2.4.8", "js-joda": "^1.8.2", - "moment": "^2.22.1", + "moment": "^2.22.2", "object-path": "^0.11.4", "obv": "0.0.1", "react": "16.4.1",