From 4653ffc07b876a75e6f2fe4f9de64a0423a9afc3 Mon Sep 17 00:00:00 2001 From: David Peer Date: Thu, 8 Sep 2022 16:00:46 +0200 Subject: [PATCH] Show calendar week --- apps/bwclk/ChangeLog | 3 ++- apps/bwclk/app.js | 16 +++++++++++++++- apps/bwclk/metadata.json | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/bwclk/ChangeLog b/apps/bwclk/ChangeLog index 81aab5050..59bf9eb96 100644 --- a/apps/bwclk/ChangeLog +++ b/apps/bwclk/ChangeLog @@ -17,4 +17,5 @@ 0.17: Fix - Step count was no more shown in the menu. 0.18: Set timer for an agenda entry by simply clicking in the middle of the screen. Only one timer can be set. 0.19: Fix - Compatibility with "Digital clock widget" -0.20: Better handling of async data such as getPressure. \ No newline at end of file +0.20: Better handling of async data such as getPressure. +0.21: On the default menu the week of year can be shown. \ No newline at end of file diff --git a/apps/bwclk/app.js b/apps/bwclk/app.js index 0a955cf7f..cd1979e98 100644 --- a/apps/bwclk/app.js +++ b/apps/bwclk/app.js @@ -198,6 +198,7 @@ function imgMountain() { var menu = [ [ function(){ return [ null, null ] }, + function(){ return [ "Week " + weekOfYear(), null ] }, ], [ function(){ return [ "Bangle", imgWatch() ] }, @@ -423,6 +424,19 @@ function getWeather(){ }; } +// From https://weeknumber.com/how-to/javascript +function weekOfYear() { + var date = new Date(); + date.setHours(0, 0, 0, 0); + // Thursday in current week decides the year. + date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); + // January 4 is always in week 1. + var week1 = new Date(date.getFullYear(), 0, 4); + // Adjust to Thursday in week 1 and count number of weeks from date to week1. + return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 + - 3 + (week1.getDay() + 6) % 7) / 7); +} + function isAlarmEnabled(idx){ try{ @@ -600,7 +614,7 @@ function drawTime(){ } var imgWidth = 0; - if(menuImg !== undefined){ + if(menuImg){ imgWidth = 24.0; var strWidth = g.stringWidth(menuText); var scale = imgWidth / menuImg.width; diff --git a/apps/bwclk/metadata.json b/apps/bwclk/metadata.json index 919ecad13..b6896ab5e 100644 --- a/apps/bwclk/metadata.json +++ b/apps/bwclk/metadata.json @@ -1,7 +1,7 @@ { "id": "bwclk", "name": "BW Clock", - "version": "0.20", + "version": "0.21", "description": "A very minimalistic clock to mainly show date and time.", "readme": "README.md", "icon": "app.png",