If time has already passed, start notification tomorrow

This commit is contained in:
Julia Friesel
2018-08-27 16:17:05 +02:00
parent eb41ae354f
commit c5178ea441
2 changed files with 12 additions and 6 deletions
+11 -5
View File
@@ -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'
})
+1 -1
View File
@@ -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",