refactor 2
parent
df97a75200
commit
8bb7c24b81
|
|
@ -1,38 +1,38 @@
|
||||||
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
|
//write settings to file
|
||||||
function updateSettings() {
|
function updateSettings() {
|
||||||
storage.write('daysleft.json', settings);
|
storage.write('daysleft.json', settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set standard settings
|
//Define standard settings
|
||||||
function resetSettings() {
|
function resetSettings() {
|
||||||
settings = {
|
settings = {
|
||||||
day : 17,
|
day : 17,
|
||||||
month : 6,
|
month : 6,
|
||||||
year: 2020
|
year: 2020
|
||||||
};
|
};
|
||||||
updateSettings(); //update file
|
updateSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
settings = storage.readJSON('daysleft.json',1); //read file
|
settings = storage.readJSON('daysleft.json',1); //read storage
|
||||||
if (!settings) resetSettings(); //if file does not exist, reset settings
|
if (!settings) resetSettings(); //if settings file was not found, set to standard
|
||||||
|
|
||||||
|
var dd = settings.day,
|
||||||
|
mm = settings.month-1, //-1 because month is zero-based
|
||||||
|
yy = settings.year;
|
||||||
|
|
||||||
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
|
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
|
||||||
const targetDate = new Date(yy, mm, dd); //time is 00:00 then
|
const targetDate = new Date(yy, mm, dd); //is 00:00
|
||||||
const today = new Date();
|
const today = new Date(); //includes current time
|
||||||
|
|
||||||
//create date object with today, but 00:00:00
|
|
||||||
const currentYear = today.getFullYear();
|
const currentYear = today.getFullYear();
|
||||||
const currentMonth = today.getMonth();
|
const currentMonth = today.getMonth();
|
||||||
const currentDay = today.getDate();
|
const currentDay = today.getDate();
|
||||||
const todayMorning = new Date (currentYear, currentMonth, currentDay, 0, 0, 0); //set time to 00:00
|
const todayMorning = new Date (currentYear, currentMonth, currentDay, 0, 0, 0); //create date object with today, but 00:00:00
|
||||||
|
|
||||||
const diffDays = (targetDate - todayMorning) / oneDay; //calculate difference of days
|
const diffDays = (targetDate - todayMorning) / oneDay; //calculate day difference
|
||||||
|
|
||||||
//draw widget
|
//draw widget
|
||||||
WIDGETS["daysl"]={area:"tl",width:40,draw:function(){
|
WIDGETS["daysl"]={area:"tl",width:40,draw:function(){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue