mirror of https://github.com/espruino/BangleApps
Merge pull request #1551 from N-Onorato/master
First widget: Displays days left in the current month.pull/1513/head^2
commit
834cdbe3f6
|
@ -0,0 +1 @@
|
||||||
|
0.01: Simple new widget!
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Widget Name
|
||||||
|
|
||||||
|
The days left in month widget is simple and just prints the number of days left in the month in the top left corner.
|
||||||
|
The idea is to encourage people to keep track of time and keep goals they may have for the month.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Hopefully you just have to Install it and it'll work. Customizing the location would just be changing tl to tr.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Shows days left in month
|
||||||
|
* Only updates at midnight.
|
||||||
|
|
||||||
|
|
||||||
|
## Requests
|
||||||
|
|
||||||
|
Complaints,compliments,problems,suggestions,annoyances,bugs, and all other feedback can be filed at [this repo](https://github.com/N-Onorato/BangleApps)
|
||||||
|
|
||||||
|
## Creator
|
||||||
|
|
||||||
|
Nick
|
|
@ -0,0 +1,14 @@
|
||||||
|
{ "id": "widmnth",
|
||||||
|
"name": "Days left in month widget",
|
||||||
|
"shortName":"Month Countdown",
|
||||||
|
"version":"0.01",
|
||||||
|
"description": "A simple widget that displays the number of days left in the month.",
|
||||||
|
"icon": "widget.png",
|
||||||
|
"type": "widget",
|
||||||
|
"tags": "widget,date,time,countdown,month",
|
||||||
|
"supports" : ["BANGLEJS","BANGLEJS2"],
|
||||||
|
"readme": "README.md",
|
||||||
|
"storage": [
|
||||||
|
{"name":"widmnth.wid.js","url":"widget.js"}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
var days_left;
|
||||||
|
var clearCode;
|
||||||
|
|
||||||
|
function getDaysLeft(day) {
|
||||||
|
let year = day.getMonth() == 11 ? day.getFullYear() + 1 : day.getFullYear(); // rollover if december.
|
||||||
|
next_month = new Date(year, (day.getMonth() + 1) % 12, 1, 0, 0, 0);
|
||||||
|
let days_left = Math.floor((next_month - day) / 86400000); // ms left in month divided by ms in a day
|
||||||
|
return days_left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTimeTilMidnight(now) {
|
||||||
|
let midnight = new Date(now.getTime());
|
||||||
|
midnight.setHours(23);
|
||||||
|
midnight.setMinutes(59);
|
||||||
|
midnight.setSeconds(59);
|
||||||
|
midnight.setMilliseconds(999);
|
||||||
|
return (midnight - now) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
let now = new Date();
|
||||||
|
days_left = getDaysLeft(now);
|
||||||
|
let ms_til_midnight = getTimeTilMidnight(now);
|
||||||
|
clearCode = setTimeout(update, ms_til_midnight);
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
g.reset();
|
||||||
|
g.setFont("4x6", 3);
|
||||||
|
if(!clearCode) update(); // On first run calculate days left and setup interval to update state.
|
||||||
|
g.drawString(days_left < 10 ? "0" + days_left : days_left.toString(), this.x + 2, this.y + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add your widget
|
||||||
|
WIDGETS.widmonthcountdown={
|
||||||
|
area:"tl", // tl (top left), tr (top right), bl (bottom left), br (bottom right)
|
||||||
|
width: 24,
|
||||||
|
draw:draw
|
||||||
|
};
|
||||||
|
})();
|
Binary file not shown.
After Width: | Height: | Size: 470 B |
Loading…
Reference in New Issue