Merge branch 'ffcniftya-clock-0.02' of https://github.com/DDDanny/BangleApps into DDDanny-ffcniftya-clock-0.02

pull/1293/head
Gordon Williams 2022-01-13 13:18:20 +00:00
commit 74ed936ac6
9 changed files with 70 additions and 14 deletions

View File

@ -4404,8 +4404,10 @@
"allow_emulator": true,
"storage": [
{"name":"ffcniftya.app.js","url":"app.js"},
{"name":"ffcniftya.img","url":"app-icon.js","evaluate":true}
]
{"name":"ffcniftya.img","url":"app-icon.js","evaluate":true},
{"name":"ffcniftya.settings.js","url":"settings.js"}
],
"data": [{"name":"ffcniftya.json"}]
},
{
"id": "ffcniftyb",

View File

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

View File

@ -1,4 +1,18 @@
# Nifty-A Clock
![](screenshot_nifty.png)
Colors are black/white - photos have non correct camera color "blue"
## This is the clock
![](screenshot_nifty.png) (*emulated*)
![](photo_nifty.png) (*photo*)
## The week number (ISO8601) can be turned of in settings
(default is **"On"**)
![](screenshot_settings_nifty.png) (*emulated*)
![](photo_settings_nifty.png) (*photo*)

View File

@ -1,5 +1,6 @@
const locale = require("locale");
const is12Hour = (require("Storage").readJSON("setting.json", 1) || {})["12hour"];
const CFG = require('Storage').readJSON("ffcniftya.json", 1) || {showWeekNum: true};
/* Clock *********************************************/
const scale = g.getWidth() / 176;
@ -16,6 +17,18 @@ const center = {
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) {
return ('0' + value).substr(-2);
}
@ -29,23 +42,26 @@ function draw() {
const minutes = d02(now.getMinutes());
const day = d02(now.getDate());
const month = d02(now.getMonth() + 1);
const year = now.getFullYear();
const month2 = locale.month(now, 3);
const day2 = locale.dow(now, 3);
const year = now.getFullYear(now);
const weekNum = d02(ISO8601_week_no(now));
const monthName = locale.month(now, 3);
const dayName = locale.dow(now, 3);
const centerTimeScaleX = center.x + 32 * scale;
g.setFontAlign(1, 0).setFont("Vector", 90 * scale);
g.drawString(hour, center.x + 32 * scale, center.y - 31 * scale);
g.drawString(minutes, center.x + 32 * scale, center.y + 46 * scale);
g.drawString(hour, centerTimeScaleX, center.y - 31 * 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);
const centerDatesScaleX = center.x + 40 * scale;
g.setFontAlign(-1, 0).setFont("Vector", 16 * scale);
g.drawString(year, center.x + 40 * scale, center.y - 62 * scale);
g.drawString(month, center.x + 40 * scale, center.y - 44 * scale);
g.drawString(day, center.x + 40 * scale, center.y - 26 * scale);
g.drawString(month2, center.x + 40 * scale, center.y + 48 * scale);
g.drawString(day2, center.x + 40 * scale, center.y + 66 * scale);
g.drawString(year, centerDatesScaleX, center.y - 62 * scale);
g.drawString(month, centerDatesScaleX, center.y - 44 * scale);
g.drawString(day, centerDatesScaleX, center.y - 26 * scale);
if (CFG.showWeekNum) g.drawString(d02(ISO8601_week_no(now)), centerDatesScaleX, center.y + 15 * scale);
g.drawString(monthName, centerDatesScaleX, center.y + 48 * scale);
g.drawString(dayName, centerDatesScaleX, center.y + 66 * scale);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,23 @@
(function(back) {
var FILE = "ffcniftya.json";
// Load settings
var cfg = require('Storage').readJSON(FILE, 1) || { showWeekNum: 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();
}
}
});
})