Merge pull request #3896 from RKBoss6/WorldClockInfo

Create World clock info app
master
thyttan 2025-06-26 23:33:55 +02:00 committed by GitHub
commit 7ace5bd00d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 454 additions and 0 deletions

View File

@ -0,0 +1 @@
0.01: New App, settings menu, clockInfos.

View File

@ -0,0 +1,28 @@
# 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
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, <i>if you enable them in locale</i>. 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.
## Creator
[RKBoss6](https://github.com/RKBoss6)

BIN
apps/worldclkinfo/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -0,0 +1,363 @@
(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
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;
}
}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 {
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(()=>{
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 : "Hong Kong",
get : () => {
return {
text : getWorldDateString("Hong Kong"),
//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");
}
}
]
};
})

View File

@ -0,0 +1,17 @@
{ "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.)",
"icon": "app.png",
"type": "clkinfo",
"tags": "clkinfo",
"supports" : ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name":"worldclkinfo.clkinfo.js","url":"clkinfo.js"},
{"name":"worldclkinfo.settings.js","url":"settings.js"}
],
"data": [
{"name":"worldclkinfosettings.json"}
]
}

View File

@ -0,0 +1,45 @@
(function(back) {
var FILE = "worldclkinfosettings.json";
// Load settings
var settings = Object.assign({
shorten: false,
showMeridians:true,
shortenMeridians:false,
}, require('Storage').readJSON(FILE, true) || {});
function writeSettings() {
require('Storage').writeJSON(FILE, settings);
}
// Show the menu
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
onchange: v => {
settings.showMeridians = v;
writeSettings();
}
},
'Shorten Meridians': {
value: !!settings.shortenMeridians, // !! converts undefined to false
onchange: v => {
settings.shortenMeridians = v;
writeSettings();
}
},
});
})