refactor and comments

master
Christian Hemker 2020-04-04 16:02:34 +02:00
parent 5829ed618d
commit df97a75200
1 changed files with 25 additions and 23 deletions

View File

@ -1,38 +1,40 @@
const storage = require('Storage'); const storage = require('Storage');
let settings; let settings;
var dd = settings.day,
mm = settings.month-1, //-1 because month is zero-based
yy = settings.year;
//update file
function updateSettings() { function updateSettings() {
storage.write('daysleft.json', settings); storage.write('daysleft.json', settings);
} }
function resetSettings() { //set standard settings
settings = { function resetSettings() {
day : 17, settings = {
month : 6, day : 17,
year: 2020 month : 6,
}; year: 2020
updateSettings(); };
} updateSettings(); //update file
}
settings = storage.readJSON('daysleft.json',1); settings = storage.readJSON('daysleft.json',1); //read file
if (!settings) resetSettings(); if (!settings) resetSettings(); //if file does not exist, reset settings
var dd = settings.day, const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
mm = settings.month-1, //month is zero-based const targetDate = new Date(yy, mm, dd); //time is 00:00 then
yy = settings.year; const today = new Date();
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds //create date object with today, but 00:00:00
const targetDate = new Date(yy, mm, dd); const currentYear = today.getFullYear();
const today = new Date(); const currentMonth = today.getMonth();
const currentDay = today.getDate();
const todayMorning = new Date (currentYear, currentMonth, currentDay, 0, 0, 0); //set time to 00:00
//create date object with today, but 00:00:00 const diffDays = (targetDate - todayMorning) / oneDay; //calculate difference of days
const currentYear = today.getFullYear();
const currentMonth = today.getMonth();
const currentDay = today.getDate();
const todayMorning = new Date (currentYear, currentMonth, currentDay, 0, 0, 0);
const diffDays = (targetDate - todayMorning) / oneDay;
//draw widget
WIDGETS["daysl"]={area:"tl",width:40,draw:function(){ WIDGETS["daysl"]={area:"tl",width:40,draw:function(){
g.setFont("6x8", 1); g.setFont("6x8", 1);
g.drawString(diffDays,this.x+12,this.y+12); g.drawString(diffDays,this.x+12,this.y+12);