If time has already passed, start notification tomorrow
This commit is contained in:
+11
-5
@@ -1,6 +1,7 @@
|
|||||||
import {tempReminderObservable} from '../local-storage'
|
import {tempReminderObservable} from '../local-storage'
|
||||||
import Notification from 'react-native-push-notification'
|
import Notification from 'react-native-push-notification'
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
|
import Moment from 'moment'
|
||||||
import { settings as labels } from '../components/labels'
|
import { settings as labels } from '../components/labels'
|
||||||
import { getOrCreateCycleDay } from '../db'
|
import { getOrCreateCycleDay } from '../db'
|
||||||
|
|
||||||
@@ -16,14 +17,19 @@ export default function setupNotifications(navigate) {
|
|||||||
tempReminderObservable(reminder => {
|
tempReminderObservable(reminder => {
|
||||||
Notification.cancelAllLocalNotifications()
|
Notification.cancelAllLocalNotifications()
|
||||||
if (reminder.enabled) {
|
if (reminder.enabled) {
|
||||||
const date = new Date()
|
|
||||||
const [hours, minutes] = reminder.time.split(':')
|
const [hours, minutes] = reminder.time.split(':')
|
||||||
date.setHours(parseInt(hours))
|
let target = new Moment()
|
||||||
date.setMinutes(parseInt(minutes))
|
.hours(parseInt(hours))
|
||||||
date.setSeconds(0)
|
.minutes(parseInt(minutes))
|
||||||
|
.seconds(0)
|
||||||
|
|
||||||
|
if(target.isBefore(new Moment())) {
|
||||||
|
target = target.add(1, 'd')
|
||||||
|
}
|
||||||
|
|
||||||
Notification.localNotificationSchedule({
|
Notification.localNotificationSchedule({
|
||||||
message: labels.tempReminder.notification,
|
message: labels.tempReminder.notification,
|
||||||
date,
|
date: target.toDate(),
|
||||||
vibrate: false,
|
vibrate: false,
|
||||||
repeatType: 'day'
|
repeatType: 'day'
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@
|
|||||||
"isobject": "^3.0.1",
|
"isobject": "^3.0.1",
|
||||||
"js-base64": "^2.4.8",
|
"js-base64": "^2.4.8",
|
||||||
"js-joda": "^1.8.2",
|
"js-joda": "^1.8.2",
|
||||||
"moment": "^2.22.1",
|
"moment": "^2.22.2",
|
||||||
"object-path": "^0.11.4",
|
"object-path": "^0.11.4",
|
||||||
"obv": "0.0.1",
|
"obv": "0.0.1",
|
||||||
"react": "16.4.1",
|
"react": "16.4.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user