diff --git a/apps/worldclkinfo/ChangeLog b/apps/worldclkinfo/ChangeLog index fcaa5fb61f..3b7053b9dc 100644 --- a/apps/worldclkinfo/ChangeLog +++ b/apps/worldclkinfo/ChangeLog @@ -1 +1,2 @@ 0.01: New App, settings menu, clockInfos. +0.02: Rewrite to allow configuration of time zones diff --git a/apps/worldclkinfo/README.md b/apps/worldclkinfo/README.md index 137872364b..c36753163c 100644 --- a/apps/worldclkinfo/README.md +++ b/apps/worldclkinfo/README.md @@ -1,28 +1,47 @@ # World Clock Info + A clock info that creates a new ClockInfo list for world clocks, so you can see the time across the world. ## Usage -Use a clock with ClockInfo, then swipe left/right to get to the World Clock list. From there, swipe up/down to get to the city you want. To toggle between showing the city name and what time it is there, tap on the clock info when focused. - -## Cities -* London -* Mumbai -* New York City -* Tokyo -* Dubai -* Los Angeles -* Paris -* Hong Kong +Use a clock with ClockInfo, then swipe left/right to get to the World Clock list. From there, swipe up/down to get to the city you want. To toggle between display modes, tap on the clock info when focused. -To add any more, consider opening a feature request, contacting [RKBoss6](https://github.com/RKBoss6) on GitHub, or fork the espruino/BangleApps repo and modify the app to your needs. ## Settings + In app settings, there is a menu for World Clock Info + #### Shorten Cities + This shortens the city name (New York City --> NYC) to fit inside smaller ClockInfos. + #### Show Meridians + This shows meridians, if you enable them in locale. Otherwise, it will not show no matter what setting it is set to. + #### Shorten Meridians + This shortens the meridian and removes the space separating it from the time (3:50 pm --> 3:50p) to fit inside smaller ClockInfos. + +#### Simple Mode + +This makes only the time and city name modes available. + +## Display Modes + +With Simple Mode disabled, there are 5 available display modes: + +- `5:45` +- `London` +- `5:45 Mon` +- `London 5:45` +- `London 5:45 Mon` + + ## Creator + [RKBoss6](https://github.com/RKBoss6) + +## Contributors + +- [ChuckWagon Computing](https://github.com/chuckwagoncomputing) + diff --git a/apps/worldclkinfo/clkinfo.js b/apps/worldclkinfo/clkinfo.js index 87997e5e97..a78fd3257b 100644 --- a/apps/worldclkinfo/clkinfo.js +++ b/apps/worldclkinfo/clkinfo.js @@ -1,363 +1,112 @@ - (function() { - - - //read settings - var settings = Object.assign({ - // default values - shorten: true, - showMeridians: true, - shortenMeridians:false, - }, require("Storage").readJSON("worldclkinfosettings.json", true) || {}); - - //All offsets from UTC in minutes. Positive: behind UTC. Negative: Ahead of UTC. - - const londonTimeOffset=60; - const mumbaiTimeOffset=330; - const nycTimeOffset=-240; - const tokyoTimeOffset=540; - const dubaiTimeOffset=240; - const laTimeOffset=-420; - const parisTimeOffset=120; - const hongKongTimeOffset=480 + let config = require("Storage").readJSON("worldclkinfo.config.json") || {}; - var showCityName=false; - - function getWorldDateString(cityName){ - //Gets difference between UTC and local time - var date=new Date(); - var currOffset = date.getTimezoneOffset(); - - var timeOffset; - - switch (cityName) { - case "London": - timeOffset=londonTimeOffset; - break; - case "Mumbai": - timeOffset=mumbaiTimeOffset; - break; - case "New York": - timeOffset=nycTimeOffset; - break; - case "Tokyo": - timeOffset=tokyoTimeOffset; - break; - case "Dubai": - timeOffset=dubaiTimeOffset; - break; - case "Los Angeles": - timeOffset=laTimeOffset; - break; - case "Paris": - timeOffset=parisTimeOffset; - break; - case "Hong Kong": - timeOffset=hongKongTimeOffset; - break; - default: - //Nothing else matches - timeOffset=0 - - } - - //go to UTC time - date.setMinutes(date.getMinutes() + currOffset); - //from there, go to city time - date.setMinutes(date.getMinutes() + timeOffset); - - var meridian=require("locale").meridian(date); - - var clockStr; - if(settings.showMeridians==true){ - if(settings.shortenMeridians==true){ - //get A - am, or P - pm - clockStr = require("locale").time(date, 1 /*omit seconds*/)+meridian[0]; - - }else{ - clockStr = require("locale").time(date, 1 /*omit seconds*/)+" "+meridian; - } + // Read settings + var settings = Object.assign({ + // Default values + shorten: false, + showMeridians: true, + shortenMeridians: false, + simpleMode: true + }, require("Storage").readJSON("worldclkinfo.settings.json", true) || {}); - }else{ - - clockStr = require("locale").time(date, 1 /*omit seconds*/); - - } - - - var finalCityStr; - - if(settings.shorten==true){ - - switch (cityName) { - case "Los Angeles": - finalCityStr="LA"; - break; - case "New York": - finalCityStr="NYC"; - break; - case "Hong Kong": - finalCityStr="HK"; - break; - default: - //Nothing else matches - finalCityStr=cityName; - } - - }else{ - - finalCityStr=cityName; - - - } - - - - //var finalStr=finalCityStr+"\n"+clockStr+"\n"; - if(showCityName){ - //show city - var finalStr=finalCityStr; - }else{ - var finalStr=clockStr; - } - return finalStr; - - - } - - - - - - return { + let clocks = { name: "World Clocks", - items: [ - - { name : "London", - get : () => { - return { - text : getWorldDateString("London"), - //blank image - img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") - }; - }, - show : function() { - this.interval = setTimeout(()=>{ - this.emit("redraw"); - this.interval = setInterval(()=>{ - this.emit("redraw"); - }, 60000); - }, 60000 - (Date.now() % 60000)); - }, - hide : function() { - clearInterval(this.interval); - this.interval = undefined; - }, - run : function() { - //toggle showCityName - - showCityName=!showCityName; - this.emit("redraw"); - } - - }, - - { name : "Mumbai", - get : () => { - return { - text : getWorldDateString("Mumbai"), - //blank image - img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") - }; - }, - show : function() { - this.interval = setTimeout(()=>{ - this.emit("redraw"); - this.interval = setInterval(()=>{ - this.emit("redraw"); - }, 60000); - }, 60000 - (Date.now() % 60000)); - }, - hide : function() { - clearInterval(this.interval); - this.interval = undefined; - }, - run : function() { - //toggle showCityName - - showCityName=!showCityName; - this.emit("redraw"); - } - }, - - { name : "New York", - get : () => { - return { - text : getWorldDateString("New York"), - //blank image - img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") - }; - }, - show : function() { - this.interval = setTimeout(()=>{ - this.emit("redraw"); - this.interval = setInterval(()=>{ - this.emit("redraw"); - }, 60000); - }, 60000 - (Date.now() % 60000)); - }, - hide : function() { - clearInterval(this.interval); - this.interval = undefined; - }, - run : function() { - //toggle showCityName - - showCityName=!showCityName; - this.emit("redraw"); - } - }, - - { name : "Tokyo", - get : () => { - return { - text : getWorldDateString("Tokyo"), - //blank image - img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") - }; - }, - show : function() { - this.interval = setTimeout(()=>{ - this.emit("redraw"); - this.interval = setInterval(()=>{ - this.emit("redraw"); - }, 60000); - }, 60000 - (Date.now() % 60000)); - }, - hide : function() { - clearInterval(this.interval); - this.interval = undefined; - }, - run : function() { - //toggle showCityName - - showCityName=!showCityName; - this.emit("redraw"); - } - }, - - { name : "Dubai", - get : () => { - return { - text : getWorldDateString("Dubai"), - //blank image - img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") - }; - }, - show : function() { - this.interval = setTimeout(()=>{ - this.emit("redraw"); - this.interval = setInterval(()=>{ - this.emit("redraw"); - }, 60000); - }, 60000 - (Date.now() % 60000)); - }, - hide : function() { - clearInterval(this.interval); - this.interval = undefined; - }, - run : function() { - //toggle showCityName - - showCityName=!showCityName; - this.emit("redraw"); - } - }, - { name : "Los Angeles", - get : () => { - return { - text : getWorldDateString("Los Angeles"), - //blank image - img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") - }; - }, - show : function() { - this.interval = setTimeout(()=>{ - this.emit("redraw"); - this.interval = setInterval(()=>{ - this.emit("redraw"); - }, 60000); - }, 60000 - (Date.now() % 60000)); - }, - hide : function() { - clearInterval(this.interval); - this.interval = undefined; - }, - run : function() { - //toggle showCityName - - showCityName=!showCityName; - this.emit("redraw"); - } - }, - - { name : "Paris", - get : () => { - return { - text : getWorldDateString("Paris"), - //blank image - img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") - }; - }, - show : function() { - this.interval = setTimeout(()=>{ + items: [] + }; + + if (config.rows) { + config.rows.forEach((row, id) => { + clocks.items.push({ + // Use the short name if the user hasn't set a long name + name: "WC " + (row.name || row.shortname), + show: function() { + this.interval = setTimeout(() => { + // Request a re-draw this.emit("redraw"); - this.interval = setInterval(()=>{ - this.emit("redraw"); - }, 60000); + // Call ourself to request again in a minute + this.show(); + // Time between now and the next minute mark }, 60000 - (Date.now() % 60000)); }, - hide : function() { - clearInterval(this.interval); + hide : function() { + if (this.interval) clearInterval(this.interval); this.interval = undefined; }, - run : function() { - //toggle showCityName - - showCityName=!showCityName; + run: function() { + let cr = config.rows[id]; + if (settings.simpleMode) { + config.simpleRow = config.simpleRow || {}; + cr = config.simpleRow; + } + // Default to mode 1, and wrap when going past mode 5 + if ( ! cr.mode) { + cr.mode = 2; + } else if ( cr.mode == 5 || (settings.simpleMode && cr.mode == 2)) { + cr.mode = 1; + } else { + cr.mode += 1; + } + // Request a re-draw when tapped to display the new mode this.emit("redraw"); - } - }, - { name : "Hong Kong", - get : () => { + require("Storage").writeJSON("worldclkinfo.config.json", config); + }, + get: () => { + let d = new Date(); + // Get UTC/GMT by adding our current offset. + let gmt = new Date(d.getTime() + d.getTimezoneOffset() * 60 * 1000); + // Add the row's offset + let dx = new Date(gmt.getTime() + row.offset * 60 * 60 * 1000); + // Get the meridian if our locale has it (24h locales won't) + var meridian = require("locale").meridian(dx); + // Strip the extra spaces + let odx = require("locale").time(dx, 1).replace(" ", ""); + + // If the setting is enabled and our locale has a meridian text + if(settings.showMeridians && meridian){ + if(settings.shortenMeridians){ + //get A - am, or P - pm + odx = odx + meridian[0]; + } else { + odx = odx + " " + meridian; + } + } + + // Day of week + let odd = require('locale').dow(dx, 1); + // If we should shorten the cityname and a short version exists, or if only a short version exists, + // show the short version. + let ln = ((settings.shorten && row.shortname) || (row.shortname && !row.name)) ? row.shortname : row.name; + let txt = ""; + let cr = config.rows[id]; + if (settings.simpleMode) { + cr = config.simpleRow || {}; + } + switch (cr.mode) { + case 2: + txt = ln; + break; + case 3: + txt = odx + " " + odd; + break; + case 4: + txt = ln + " " + odx; + break; + case 5: + txt = ln + " " + odx + " " + odd; + break; + default: + txt = odx; + } return { - text : getWorldDateString("Hong Kong"), - //blank image - img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") + text: txt, + short: odx, + img: atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==") }; - }, - show : function() { - this.interval = setTimeout(()=>{ - this.emit("redraw"); - this.interval = setInterval(()=>{ - this.emit("redraw"); - }, 60000); - }, 60000 - (Date.now() % 60000)); - }, - hide : function() { - clearInterval(this.interval); - this.interval = undefined; - }, - run : function() { - //toggle showCityName - - showCityName=!showCityName; - this.emit("redraw"); } - } - - - - ] - }; + }); + }); + } + + return clocks; }) diff --git a/apps/worldclkinfo/custom.html b/apps/worldclkinfo/custom.html new file mode 100644 index 0000000000..8989cd586f --- /dev/null +++ b/apps/worldclkinfo/custom.html @@ -0,0 +1,144 @@ + + + + + + + + + + + + +
NameShort NameUTC Offset
+ + + +


+ + + + + + + + diff --git a/apps/worldclkinfo/metadata.json b/apps/worldclkinfo/metadata.json index d0caa1836c..690b278a3d 100644 --- a/apps/worldclkinfo/metadata.json +++ b/apps/worldclkinfo/metadata.json @@ -1,18 +1,20 @@ { "id": "worldclkinfo", "name": "World Clock Info", - "version": "0.01", - "description": "Creates a ClockInfo List to view times around the world (London, Hong Kong, Delhi, New York, etc.)", + "version": "0.02", + "description": "Create clockinfos for world clocks with a name and UTC offset", "icon": "app.png", "type": "clkinfo", "tags": "clkinfo", "author":"RKBoss6", "supports" : ["BANGLEJS2"], "readme": "README.md", + "custom": "custom.html", "storage": [ {"name":"worldclkinfo.clkinfo.js","url":"clkinfo.js"}, {"name":"worldclkinfo.settings.js","url":"settings.js"} ], "data": [ - {"name":"worldclkinfosettings.json"} + {"name":"worldclkinfo.settings.json"}, + {"name":"worldclkinfo.config.json"} ] } diff --git a/apps/worldclkinfo/settings.js b/apps/worldclkinfo/settings.js index 89d5041652..f8d641caff 100644 --- a/apps/worldclkinfo/settings.js +++ b/apps/worldclkinfo/settings.js @@ -1,10 +1,11 @@ (function(back) { - var FILE = "worldclkinfosettings.json"; + var FILE = "worldclkinfo.settings.json"; // Load settings var settings = Object.assign({ shorten: false, - showMeridians:true, - shortenMeridians:false, + showMeridians: true, + shortenMeridians: false, + simpleMode: true }, require('Storage').readJSON(FILE, true) || {}); function writeSettings() { @@ -15,14 +16,12 @@ E.showMenu({ "" : { "title" : "World ClockInfo" }, "< Back" : () => back(), - 'Shorten Cities ': { value: !!settings.shorten, // !! converts undefined to false onchange: v => { settings.shorten = v; writeSettings(); } - }, 'Show Meridians': { value: !!settings.showMeridians, // !! converts undefined to false @@ -30,7 +29,6 @@ settings.showMeridians = v; writeSettings(); } - }, 'Shorten Meridians': { value: !!settings.shortenMeridians, // !! converts undefined to false @@ -38,8 +36,13 @@ settings.shortenMeridians = v; writeSettings(); } - }, - + 'Simple Mode': { + value: !!settings.simpleMode, // !! converts undefined to false + onchange: v => { + settings.simpleMode = v; + writeSettings(); + } + }, }); })