diff --git a/apps/widmnth/ChangeLog b/apps/widmnth/ChangeLog new file mode 100644 index 000000000..370f41e8a --- /dev/null +++ b/apps/widmnth/ChangeLog @@ -0,0 +1 @@ +0.01: Simple new widget! diff --git a/apps/widmnth/README.md b/apps/widmnth/README.md new file mode 100644 index 000000000..ef912c739 --- /dev/null +++ b/apps/widmnth/README.md @@ -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 diff --git a/apps/widmnth/metadata.json b/apps/widmnth/metadata.json new file mode 100644 index 000000000..25f3a8126 --- /dev/null +++ b/apps/widmnth/metadata.json @@ -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"} + ] +} diff --git a/apps/widmnth/widget.js b/apps/widmnth/widget.js new file mode 100644 index 000000000..c4eca155a --- /dev/null +++ b/apps/widmnth/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 + }; +})(); \ No newline at end of file diff --git a/apps/widmnth/widget.png b/apps/widmnth/widget.png new file mode 100644 index 000000000..4a042ec05 Binary files /dev/null and b/apps/widmnth/widget.png differ