Skip to content

Create World clock info app #3896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/worldclkinfo/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: New App, settings menu, clockInfos.
28 changes: 28 additions & 0 deletions apps/worldclkinfo/README.md
Original file line number Diff line number Diff line change
@@ -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)
Binary file added apps/worldclkinfo/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
363 changes: 363 additions & 0 deletions apps/worldclkinfo/clkinfo.js
Original file line number Diff line number Diff line change
@@ -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");
}
}



]
};
})
Loading