BangleApps/apps/daysl/widget.js

32 lines
837 B
JavaScript
Raw Normal View History

2020-03-31 21:17:46 +00:00
const storage = require('Storage');
let settings;
function updateSettings() {
storage.write('daysleft.json', settings);
}
2020-03-31 21:17:46 +00:00
function resetSettings() {
settings = {
day : 17,
month : 6,
year: 2020
2020-03-31 21:17:46 +00:00
};
updateSettings();
}
settings = storage.readJSON('daysleft.json',1);
if (!settings) resetSettings();
var dd = settings.day,
mm = settings.month-1, //month is zero-based
2020-03-31 21:17:46 +00:00
yy = settings.year;
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
const targetDate = new Date(yy, mm, dd, 23, 59, 59);
2020-03-31 21:17:46 +00:00
const today = new Date();
const diffDays = Math.round(Math.abs((targetDate - today) / oneDay));
WIDGETS["daysl"]={area:"tl",width:40,draw:function(){
g.setFont("6x8", 1);
g.drawString(diffDays,this.x+12,this.y+12);
}};