added ISO weeknumber

* update changelog, screenshots and readme
* created a settings dialog
master
Danny 2021-12-25 23:58:46 +01:00
parent d9d5926416
commit fcf8a0b1f0
6 changed files with 57 additions and 11 deletions

View File

@ -1 +1,2 @@
0.01: New Clock Nifty A 0.01: New Clock Nifty A
0.02: Shows the current week number, can be disabled via settings ""

View File

@ -1,4 +1,9 @@
# Nifty-A Clock # Nifty-A Clock
## This is the clock
![](screenshot_nifty.png) ![](screenshot_nifty.png)
## The week number can be turned On/Off via settings
![](screenshot_settings_nifty.png)
default is "On"

View File

@ -1,5 +1,6 @@
const locale = require("locale"); const locale = require("locale");
const is12Hour = (require("Storage").readJSON("setting.json", 1) || {})["12hour"]; const is12Hour = (require("Storage").readJSON("setting.json", 1) || {})["12hour"];
const CFG = require('Storage').readJSON("ffcniftya.json", true) || {showWeek: true};
/* Clock *********************************************/ /* Clock *********************************************/
const scale = g.getWidth() / 176; const scale = g.getWidth() / 176;
@ -16,6 +17,18 @@ const center = {
y: Math.round(((viewport.height - widget) / 2) + widget), y: Math.round(((viewport.height - widget) / 2) + widget),
} }
function ISO8601_week_no(date) { //copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
var tdt = new Date(date.valueOf());
var dayn = (date.getDay() + 6) % 7;
tdt.setDate(tdt.getDate() - dayn + 3);
var firstThursday = tdt.valueOf();
tdt.setMonth(0, 1);
if (tdt.getDay() !== 4) {
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
}
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
}
function d02(value) { function d02(value) {
return ('0' + value).substr(-2); return ('0' + value).substr(-2);
} }
@ -29,23 +42,25 @@ function draw() {
const minutes = d02(now.getMinutes()); const minutes = d02(now.getMinutes());
const day = d02(now.getDate()); const day = d02(now.getDate());
const month = d02(now.getMonth() + 1); const month = d02(now.getMonth() + 1);
const year = now.getFullYear(); const year = now.getFullYear(now);
const monthName = locale.month(now, 3);
const month2 = locale.month(now, 3); const dayName = locale.dow(now, 3);
const day2 = locale.dow(now, 3);
const centerTimeScaleX = center.x + 32 * scale;
g.setFontAlign(1, 0).setFont("Vector", 90 * scale); g.setFontAlign(1, 0).setFont("Vector", 90 * scale);
g.drawString(hour, center.x + 32 * scale, center.y - 31 * scale); g.drawString(hour, centerTimeScaleX, center.y - 31 * scale);
g.drawString(minutes, center.x + 32 * scale, center.y + 46 * scale); g.drawString(minutes, centerTimeScaleX, center.y + 46 * scale);
g.fillRect(center.x + 30 * scale, center.y - 72 * scale, center.x + 32 * scale, center.y + 74 * scale); g.fillRect(center.x + 30 * scale, center.y - 72 * scale, center.x + 32 * scale, center.y + 74 * scale);
const centerDatesScaleX = center.x + 40 * scale;
g.setFontAlign(-1, 0).setFont("Vector", 16 * scale); g.setFontAlign(-1, 0).setFont("Vector", 16 * scale);
g.drawString(year, center.x + 40 * scale, center.y - 62 * scale); g.drawString(year, centerDatesScaleX, center.y - 62 * scale);
g.drawString(month, center.x + 40 * scale, center.y - 44 * scale); g.drawString(month, centerDatesScaleX, center.y - 44 * scale);
g.drawString(day, center.x + 40 * scale, center.y - 26 * scale); g.drawString(day, centerDatesScaleX, center.y - 26 * scale);
g.drawString(month2, center.x + 40 * scale, center.y + 48 * scale); if (CFG.showWeek) g.drawString(d02(ISO8601_week_no(now)), centerDatesScaleX, center.y + 15 * scale);
g.drawString(day2, center.x + 40 * scale, center.y + 66 * scale); g.drawString(monthName, centerDatesScaleX, center.y + 48 * scale);
g.drawString(dayName, centerDatesScaleX, center.y + 66 * scale);
} }

View File

@ -0,0 +1,25 @@
(function(back) {
var FILE = "\ffcniftya.json";
// Load settings
var cfg = Object.assign({
showWeekNum: true,
}, require('Storage').readJSON(FILE, true) || {});
function writeSettings() {
require('Storage').writeJSON(FILE, cfg);
}
// Show the menu
E.showMenu({
"" : { "title" : "Nifty-A Clock" },
"< Back" : () => back(),
'week number?': {
value: cfg.showWeekNum,
format: v => v?"On":"Off",
onchange: v => {
cfg.showWeekNum = v;
writeSettings();
}
}
});
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB