add time adjustment time pushover message, if type is note set priority to -1

This commit is contained in:
Jason Calabrese
2014-12-13 11:20:29 -08:00
parent 2567431cef
commit bd1af6344e
+33 -2
View File
@@ -52,12 +52,16 @@ function storage (collection, storage, pushover) {
if (pushover) {
//since we don't know the time zone on the device viewing the push messeage
//we can only show the amount of adjustment
var timeAdjustment = calcTimeAdjustment(eventTime);
var text = (obj.glucose ? 'BG: ' + obj.glucose + ' (' + obj.glucoseType + ')' : '') +
(obj.carbs ? '\nCarbs: ' + obj.carbs : '') +
(obj.insulin ? '\nInsulin: ' + obj.insulin : '')+
(obj.preBolus > 0 ? '\nPre-Bolus: ' + obj.preBolus + " minutes" : '')+
(obj.enteredBy ? '\nEntered By: ' + obj.enteredBy : '') +
(eventTime ? '\nEvent Time: adjusted' : '') +
(timeAdjustment ? '\nEvent Time: ' + timeAdjustment : '') +
(obj.notes ? '\nNotes: ' + obj.notes : '');
var msg = {
@@ -66,7 +70,7 @@ function storage (collection, storage, pushover) {
title: obj.eventType,
sound: 'gamelan',
timestamp: new Date( ),
priority: 0,
priority: (obj.eventType == 'Note' ? -1 : 0),
retry: 30
};
@@ -78,6 +82,33 @@ function storage (collection, storage, pushover) {
});
}
function calcTimeAdjustment(eventTime) {
if (!eventTime) return null;
var now = (new Date()).getTime(),
other = eventTime.getTime(),
past = other < now,
offset = Math.abs(now - other);
var MINUTE = 60 * 1000,
HOUR = 3600 * 1000;
var parts = {};
if (offset <= MINUTE)
return 'now';
else if (offset < (HOUR * 2))
parts = { value: Math.round(Math.abs(offset / MINUTE)), label: 'mins' };
else
parts = { value: Math.round(Math.abs(offset / HOUR)), label: 'hrs' };
if (past)
return parts.value + ' ' + parts.label + ' ago';
else
return 'in ' + parts.value + ' ' + parts.label;
}
function list (opts, fn) {
function find ( ) {
var q = opts && opts.find ? opts.find : { };