From 223f6b6b8120f34e5063e7fa4ccde04deeb22f83 Mon Sep 17 00:00:00 2001 From: Danny <31635744+DDDanny@users.noreply.github.com> Date: Wed, 12 Jan 2022 23:57:44 +0100 Subject: [PATCH] fixes #1271 & some code rework + moved settings-helper method def to load settings method + settingsfile as const + isBangle1 via HWVERSION==1 --- apps.json | 2 +- apps/antonclk/ChangeLog | 5 ++++- apps/antonclk/README.md | 6 +++--- apps/antonclk/app.js | 36 +++++++++++++++++++++++------------- apps/antonclk/settings.js | 4 ++-- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/apps.json b/apps.json index 4c6f3bdcf..dd2ddbcb3 100644 --- a/apps.json +++ b/apps.json @@ -4279,7 +4279,7 @@ { "id": "antonclk", "name": "Anton Clock", - "version": "0.05", + "version": "0.06", "description": "A clock using the bold Anton font, optionally showing seconds and date in ISO-8601 format.", "readme":"README.md", "icon": "app.png", diff --git a/apps/antonclk/ChangeLog b/apps/antonclk/ChangeLog index fdf20c175..4dca8053e 100644 --- a/apps/antonclk/ChangeLog +++ b/apps/antonclk/ChangeLog @@ -4,4 +4,7 @@ 0.04: Clock can optionally show seconds, date optionally in ISO-8601 format, weekdays and uppercase configurable, too. 0.05: Clock can optionally show ISO-8601 calendar weeknumber (default: Off) when weekday name "Off": week #: - when weekday name "On": weekday name is cut at 6th position and .# is added \ No newline at end of file + when weekday name "On": weekday name is cut at 6th position and .# is added +0.06: fixes #1271 - wrong settings name + when weekday name and calendar weeknumber are on then display is # + week is buffered until date or timezone changes \ No newline at end of file diff --git a/apps/antonclk/README.md b/apps/antonclk/README.md index 85c03788d..28a38f5fd 100644 --- a/apps/antonclk/README.md +++ b/apps/antonclk/README.md @@ -40,9 +40,9 @@ The main menu contains several settings covering Anton clock in general. * **Show Weekday** - Weekday is shown in the time presentation without seconds. Weekday name depends on the current locale. If seconds are shown, the weekday is never shown as there is not enough space on the watch face. -* **Show Weeknumber** - Week-number (ISO-8601) is shown. (default: Off) -If "Show Weekday" is "Off" the week-number is displayed as "week #:". -If "Show Weekday" is "On" the weekday name is cut at 6th position and suffixed with ".#". +* **Show CalWeek** - Week-number (ISO-8601) is shown. (default: Off) +If "Show Weekday" is "Off" displays the week-number as "week #". +If "Show Weekday" is "On" displays "weekday name short" with " #" . If seconds are shown, the week number is never shown as there is not enough space on the watch face. * **Vector font** - Use the built-in vector font for dates and weekday. This can improve readability. diff --git a/apps/antonclk/app.js b/apps/antonclk/app.js index 05758cbfd..7d8c8ce89 100644 --- a/apps/antonclk/app.js +++ b/apps/antonclk/app.js @@ -1,6 +1,6 @@ // Clock with large digits using the "Anton" bold font -var SETTINGSFILE = "antonclk.json"; +const SETTINGSFILE = "antonclk.json"; Graphics.prototype.setFontAnton = function(scale) { // Actual height 69 (68 - 0) @@ -28,7 +28,7 @@ var drawTimeout; var queueMillis = 1000; var secondsScreen = true; -var isBangle1 = (g.getWidth() == 240); +var isBangle1 = (process.env.HWVERSION == 1); //For development purposes /* @@ -50,13 +50,11 @@ require('Storage').writeJSON(SETTINGSFILE, { require('Storage').erase(SETTINGSFILE); */ -// Helper method for loading the settings -function def(value, def) { - return (value !== undefined ? value : def); -} - // Load settings function loadSettings() { + // Helper function default setting + function def (value, def) {return value !== undefined ? value : def;} + var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; secondsMode = def(settings.secondsMode, "Never"); secondsColoured = def(settings.secondsColoured, true); @@ -104,7 +102,14 @@ function isoStr(date) { return date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).substr(-2) + "-" + ("0" + date.getDate()).substr(-2); } +var calWeekBuffer = [false,false,false]; //buffer tz, date, week no (once calculated until other tz or date is requested) function ISO8601calWeek(date) { //copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480 + console.log(date); + dateNoTime = date; dateNoTime.setHours(0,0,0,0); + console.log(dateNoTime); + if (calWeekBuffer[0] === date.getTimezoneOffset() && calWeekBuffer[1] === dateNoTime) return calWeekBuffer[2]; + calWeekBuffer[0] = date.getTimezoneOffset(); + calWeekBuffer[1] = dateNoTime; var tdt = new Date(date.valueOf()); var dayn = (date.getDay() + 6) % 7; tdt.setDate(tdt.getDate() - dayn + 3); @@ -113,7 +118,8 @@ function ISO8601calWeek(date) { //copied from: https://gist.github.com/IamSilviu if (tdt.getDay() !== 4) { tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7); } - return 1 + Math.ceil((firstThursday - tdt) / 604800000); + calWeekBuffer[2] = 1 + Math.ceil((firstThursday - tdt) / 604800000); + return calWeekBuffer[2]; } function doColor() { @@ -186,13 +192,17 @@ function draw() { else g.setFont("6x8", 2); g.drawString(dateStr, x, y); - if (weekDay || calWeek) { - var dowwumStr = require("locale").dow(date); + if (calWeek || weekDay) { + var dowcwStr = ""; if (calWeek) - dowwumStr = (weekDay ? dowwumStr.substr(0,Math.min(dowwumStr.length,6)) + (dowwumStr.length>=6 ? "." : "") : "week ") + "#" + ISO8601calWeek(date); //TODO: locale for "week" + dowcwStr = " #" + ("0" + ISO8601calWeek(date)).substring(-2); + if (weekDay) + dowcwStr = require("locale").dow(date, calWeek ? 1 : 0) + dowcwStr; //weekDay e.g. Monday or weekDayShort # e.g. Mon #01 + else //week #01 + dowcwStr = /*LANG*/"week" + dowcwStr; if (upperCase) - dowwumStr = dowwumStr.toUpperCase(); - g.drawString(dowwumStr, x, y + (vectorFont ? 26 : 16)); + dowcwStr = dowcwStr.toUpperCase(); + g.drawString(dowcwStr, x, y + (vectorFont ? 26 : 16)); } } diff --git a/apps/antonclk/settings.js b/apps/antonclk/settings.js index 293aa0438..45c89f0a4 100644 --- a/apps/antonclk/settings.js +++ b/apps/antonclk/settings.js @@ -48,10 +48,10 @@ } }, "Show Weeknumber": { - value: (settings.weekNum !== undefined ? settings.weekNum : true), + value: (settings.calWeek !== undefined ? settings.calWeek : false), format: v => v ? "On" : "Off", onchange: v => { - settings.weekNum = v; + settings.calWeek = v; writeSettings(); } },