From e7c3e983b2978b71b73cb6071e7e39a6db9132ec Mon Sep 17 00:00:00 2001 From: computermacgyver Date: Sun, 23 Aug 2020 23:49:08 +0100 Subject: [PATCH] First go --- apps/worldclock/ChangeLog | 1 + apps/worldclock/app.js | 98 +++++++++++++++++++++++++++++++++++++ apps/worldclock/custom.html | 76 ++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 apps/worldclock/ChangeLog create mode 100644 apps/worldclock/app.js create mode 100644 apps/worldclock/custom.html diff --git a/apps/worldclock/ChangeLog b/apps/worldclock/ChangeLog new file mode 100644 index 000000000..1c7f88a87 --- /dev/null +++ b/apps/worldclock/ChangeLog @@ -0,0 +1 @@ +0.01 First try diff --git a/apps/worldclock/app.js b/apps/worldclock/app.js new file mode 100644 index 000000000..cdbc29cd8 --- /dev/null +++ b/apps/worldclock/app.js @@ -0,0 +1,98 @@ +/* jshint esversion: 6 */ +const timeFontSize = 6; +const dateFontSize = 3; +const gmtFontSize = 2; +const font = "6x8"; + +const xyCenter = g.getWidth() / 2; +const xcol1=10; +const xcol2=g.getWidth()-xcol1; +const yposTime = 75; +const yposDate = 130; +//const yposYear = 175; +//const yposGMT = 220; +const yposWorld=170; + + +var offsets = require("Storage").readJSON("worldclock.settings.json"); + +// Check settings for what type our clock should be +//var is12Hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]; +var secondInterval = undefined; + +function doublenum(x) { + return x<10? "0"+x : ""+x; +} + +function offset(dt,offset) { + return new Date(dt.getTime() + (offset*60*60*1000)); +} + +function drawSimpleClock() { + // get date + var d = new Date(); + var da = d.toString().split(" "); + + g.reset(); // default draw styles + // drawSting centered + g.setFontAlign(0, 0); + + // draw time + var time = da[4].substr(0, 5).split(":"); + var hours = time[0], minutes = time[1]; + + g.setFont(font, timeFontSize); + g.drawString(`${hours}:${minutes}`, xyCenter, yposTime, true); + + // draw Day, name of month, Date + var date = [da[0], da[1], da[2]].join(" "); + g.setFont(font, dateFontSize); + + g.drawString(date, xyCenter, yposDate, true); + + // draw year + //g.setFont(font, dateFontSize); + //g.drawString(d.getFullYear(), xyCenter, yposYear, true); + + // draw gmt + //console.log(d.getTimezoneOffset());//offset to GMT in minutes + var gmt = new Date(d.getTime()+(d.getTimezoneOffset()*60*1000)); + //gmt is now UTC+0 + + for (var i=0; i{ + if (secondInterval) clearInterval(secondInterval); + secondInterval = undefined; + if (on) { + secondInterval = setInterval(drawSimpleClock, 15E3); + drawSimpleClock(); // draw immediately + } +}); + +// draw now and every 15 sec until display goes off +drawSimpleClock(); +if (Bangle.isLCDOn()) { + secondInterval = setInterval(drawSimpleClock, 15E3); +} + +// Show launcher when middle button pressed +setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"}); + diff --git a/apps/worldclock/custom.html b/apps/worldclock/custom.html new file mode 100644 index 000000000..34d77c806 --- /dev/null +++ b/apps/worldclock/custom.html @@ -0,0 +1,76 @@ + + + + + + +

You can add up to 4 timezones. Please give a name and UTC offset in hours. + If you want less than 4, clear the checkbox to the left.

+ + + + + + + +
Enabled?NameUTC Offset
+ +

Click

+ + + + + + \ No newline at end of file