mirror of https://github.com/espruino/BangleApps
sleepphasealarm: Fix json dates
Fix handle dates saved as object with millisecondspull/3277/head
parent
cdbe4aa3ee
commit
7503254033
|
@ -19,3 +19,4 @@
|
|||
Add plot logged data to settings
|
||||
0.15: Convert Yes/No On/Off in settings to checkboxes
|
||||
0.16: Fix Keep alarm enabled inverted settings
|
||||
0.17: Fix handle dates saved as object with milliseconds
|
||||
|
|
|
@ -136,7 +136,7 @@ function buzz() {
|
|||
}
|
||||
|
||||
function addLog(time, type) {
|
||||
logs.push({time: time, type: type});
|
||||
logs.push({time: time.toISOString(), type: type});
|
||||
if (logs.length > 1) { // Do not write if there is only one state
|
||||
require("Storage").writeJSON(CONFIGFILE, config);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ function getData() {
|
|||
logs.forEach((log, i) => {
|
||||
const timeStr = log.filter(entry => entry.type === "alarm")[0]?.time;
|
||||
if (timeStr) {
|
||||
const date = new Date(timeStr);
|
||||
const date = new Date(typeof timeStr === 'string' ? timeStr : timeStr.ms);
|
||||
let option = document.createElement("option");
|
||||
option.text = date.toLocaleDateString();
|
||||
option.value = i;
|
||||
|
@ -89,10 +89,10 @@ function getData() {
|
|||
|
||||
select.onchange = () => {
|
||||
const log = logs[select.value];
|
||||
chart.data.labels = log.map(entry => new Date(entry.time));
|
||||
chart.data.labels = log.map(entry => new Date(typeof entry.time === 'string' ? entry.time : entry.time.ms));
|
||||
chart.data.datasets[0].data = log.map(entry => yTicks.indexOf(entry.type));
|
||||
const timeStr = log.filter(entry => entry.type === "alarm")[0]?.time;
|
||||
chart.data.datasets[0].label = new Date(timeStr).toLocaleDateString();
|
||||
chart.data.datasets[0].label = new Date(typeof timeStr === 'string' ? timeStr : timeStr.ms).toLocaleDateString();
|
||||
chart.update();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id": "sleepphasealarm",
|
||||
"name": "SleepPhaseAlarm",
|
||||
"shortName": "SleepPhaseAlarm",
|
||||
"version": "0.16",
|
||||
"version": "0.17",
|
||||
"description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.",
|
||||
"icon": "app.png",
|
||||
"tags": "tool,alarm",
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
function draw(log) {
|
||||
const step = 10*60*1000; // resolution 10min
|
||||
const yTicks = ["sleep", "awake", "alarm"];
|
||||
const starttime = new Date(log[0].time);
|
||||
const endtime = new Date(log[log.length-1].time);
|
||||
const starttime = dateFromJson(log[0].time);
|
||||
const endtime = dateFromJson(log[log.length-1].time);
|
||||
|
||||
let logidx = 0;
|
||||
let curtime = starttime;
|
||||
|
@ -29,7 +29,7 @@
|
|||
if (logtime === undefined || curtime > logtime) {
|
||||
curval = yTicks.indexOf(log[logidx].type);
|
||||
logidx++;
|
||||
logtime = new Date(log[logidx].time);
|
||||
logtime = dateFromJson(log[logidx].time);
|
||||
}
|
||||
|
||||
data[i++] = curval;
|
||||
|
@ -70,8 +70,8 @@
|
|||
|
||||
const logs = config.logs.filter(log => log != null && log.filter(entry => entry.type === "alarm").length > 0);
|
||||
logs.sort(function(a, b) { // sort by alarm date desc
|
||||
const adate = new Date(a.filter(entry => entry.type === "alarm")[0].time);
|
||||
const bdate = new Date(b.filter(entry => entry.type === "alarm")[0].time);
|
||||
const adate = dateFromJson(a.filter(entry => entry.type === "alarm")[0].time);
|
||||
const bdate = dateFromJson(b.filter(entry => entry.type === "alarm")[0].time);
|
||||
return bdate - adate;
|
||||
});
|
||||
|
||||
|
@ -79,12 +79,16 @@
|
|||
menu[""] = { title: /*LANG*/"Select day" };
|
||||
menu["< Back"] = () => settingsmenu();
|
||||
logs.forEach((log, i) => {
|
||||
const date = new Date(log.filter(entry => entry.type === "alarm")[0].time);
|
||||
const date = dateFromJson(log.filter(entry => entry.type === "alarm")[0].time);
|
||||
menu[require("locale").date(date, 1)] = () => { E.showMenu(); draw(log); };
|
||||
});
|
||||
E.showMenu(menu);
|
||||
}
|
||||
|
||||
function dateFromJson(o) {
|
||||
return new Date(typeof o === 'string' ? o : o.ms);
|
||||
}
|
||||
|
||||
function settingsmenu() {
|
||||
// Show the menu
|
||||
E.showMenu({
|
||||
|
|
Loading…
Reference in New Issue