Skip to content

Commit 7ace5bd

Browse files
authored
Merge pull request #3896 from RKBoss6/WorldClockInfo
Create World clock info app
2 parents 2ec2a83 + 2fd2f8b commit 7ace5bd

File tree

6 files changed

+454
-0
lines changed

6 files changed

+454
-0
lines changed

apps/worldclkinfo/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.01: New App, settings menu, clockInfos.

apps/worldclkinfo/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# World Clock Info
2+
A clock info that creates a new ClockInfo list for world clocks, so you can see the time across the world.
3+
4+
## Usage
5+
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.
6+
7+
## Cities
8+
* London
9+
* Mumbai
10+
* New York City
11+
* Tokyo
12+
* Dubai
13+
* Los Angeles
14+
* Paris
15+
* Hong Kong
16+
17+
18+
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.
19+
## Settings
20+
In app settings, there is a menu for World Clock Info
21+
#### Shorten Cities
22+
This shortens the city name (New York City --> NYC) to fit inside smaller ClockInfos.
23+
#### Show Meridians
24+
This shows meridians, <i>if you enable them in locale</i>. Otherwise, it will not show no matter what setting it is set to.
25+
#### Shorten Meridians
26+
This shortens the meridian and removes the space separating it from the time (3:50 pm --> 3:50p) to fit inside smaller ClockInfos.
27+
## Creator
28+
[RKBoss6](https://github.com/RKBoss6)

apps/worldclkinfo/app.png

7.04 KB
Loading

apps/worldclkinfo/clkinfo.js

Lines changed: 363 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,363 @@
1+
2+
(function() {
3+
4+
5+
//read settings
6+
var settings = Object.assign({
7+
// default values
8+
shorten: true,
9+
showMeridians: true,
10+
shortenMeridians:false,
11+
}, require("Storage").readJSON("worldclkinfosettings.json", true) || {});
12+
13+
//All offsets from UTC in minutes. Positive: behind UTC. Negative: Ahead of UTC.
14+
15+
const londonTimeOffset=60;
16+
const mumbaiTimeOffset=330;
17+
const nycTimeOffset=-240;
18+
const tokyoTimeOffset=540;
19+
const dubaiTimeOffset=240;
20+
const laTimeOffset=-420;
21+
const parisTimeOffset=120;
22+
const hongKongTimeOffset=480
23+
24+
var showCityName=false;
25+
26+
function getWorldDateString(cityName){
27+
//Gets difference between UTC and local time
28+
var date=new Date();
29+
var currOffset = date.getTimezoneOffset();
30+
31+
var timeOffset;
32+
33+
switch (cityName) {
34+
case "London":
35+
timeOffset=londonTimeOffset;
36+
break;
37+
case "Mumbai":
38+
timeOffset=mumbaiTimeOffset;
39+
break;
40+
case "New York":
41+
timeOffset=nycTimeOffset;
42+
break;
43+
case "Tokyo":
44+
timeOffset=tokyoTimeOffset;
45+
break;
46+
case "Dubai":
47+
timeOffset=dubaiTimeOffset;
48+
break;
49+
case "Los Angeles":
50+
timeOffset=laTimeOffset;
51+
break;
52+
case "Paris":
53+
timeOffset=parisTimeOffset;
54+
break;
55+
case "Hong Kong":
56+
timeOffset=hongKongTimeOffset;
57+
break;
58+
default:
59+
//Nothing else matches
60+
timeOffset=0
61+
62+
}
63+
64+
//go to UTC time
65+
date.setMinutes(date.getMinutes() + currOffset);
66+
//from there, go to city time
67+
date.setMinutes(date.getMinutes() + timeOffset);
68+
69+
var meridian=require("locale").meridian(date);
70+
71+
var clockStr;
72+
if(settings.showMeridians==true){
73+
if(settings.shortenMeridians==true){
74+
//get A - am, or P - pm
75+
clockStr = require("locale").time(date, 1 /*omit seconds*/)+meridian[0];
76+
77+
}else{
78+
clockStr = require("locale").time(date, 1 /*omit seconds*/)+" "+meridian;
79+
}
80+
81+
}else{
82+
83+
clockStr = require("locale").time(date, 1 /*omit seconds*/);
84+
85+
}
86+
87+
88+
var finalCityStr;
89+
90+
if(settings.shorten==true){
91+
92+
switch (cityName) {
93+
case "Los Angeles":
94+
finalCityStr="LA";
95+
break;
96+
case "New York":
97+
finalCityStr="NYC";
98+
break;
99+
case "Hong Kong":
100+
finalCityStr="HK";
101+
break;
102+
default:
103+
//Nothing else matches
104+
finalCityStr=cityName;
105+
}
106+
107+
}else{
108+
109+
finalCityStr=cityName;
110+
111+
112+
}
113+
114+
115+
116+
//var finalStr=finalCityStr+"\n"+clockStr+"\n";
117+
if(showCityName){
118+
//show city
119+
var finalStr=finalCityStr;
120+
}else{
121+
var finalStr=clockStr;
122+
}
123+
return finalStr;
124+
125+
126+
}
127+
128+
129+
130+
131+
132+
return {
133+
name: "World Clocks",
134+
items: [
135+
136+
{ name : "London",
137+
get : () => {
138+
return {
139+
text : getWorldDateString("London"),
140+
//blank image
141+
img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==")
142+
};
143+
},
144+
show : function() {
145+
this.interval = setTimeout(()=>{
146+
this.emit("redraw");
147+
this.interval = setInterval(()=>{
148+
this.emit("redraw");
149+
}, 60000);
150+
}, 60000 - (Date.now() % 60000));
151+
},
152+
hide : function() {
153+
clearInterval(this.interval);
154+
this.interval = undefined;
155+
},
156+
run : function() {
157+
//toggle showCityName
158+
159+
showCityName=!showCityName;
160+
this.emit("redraw");
161+
}
162+
163+
},
164+
165+
{ name : "Mumbai",
166+
get : () => {
167+
return {
168+
text : getWorldDateString("Mumbai"),
169+
//blank image
170+
img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==")
171+
};
172+
},
173+
show : function() {
174+
this.interval = setTimeout(()=>{
175+
this.emit("redraw");
176+
this.interval = setInterval(()=>{
177+
this.emit("redraw");
178+
}, 60000);
179+
}, 60000 - (Date.now() % 60000));
180+
},
181+
hide : function() {
182+
clearInterval(this.interval);
183+
this.interval = undefined;
184+
},
185+
run : function() {
186+
//toggle showCityName
187+
188+
showCityName=!showCityName;
189+
this.emit("redraw");
190+
}
191+
},
192+
193+
{ name : "New York",
194+
get : () => {
195+
return {
196+
text : getWorldDateString("New York"),
197+
//blank image
198+
img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==")
199+
};
200+
},
201+
show : function() {
202+
this.interval = setTimeout(()=>{
203+
this.emit("redraw");
204+
this.interval = setInterval(()=>{
205+
this.emit("redraw");
206+
}, 60000);
207+
}, 60000 - (Date.now() % 60000));
208+
},
209+
hide : function() {
210+
clearInterval(this.interval);
211+
this.interval = undefined;
212+
},
213+
run : function() {
214+
//toggle showCityName
215+
216+
showCityName=!showCityName;
217+
this.emit("redraw");
218+
}
219+
},
220+
221+
{ name : "Tokyo",
222+
get : () => {
223+
return {
224+
text : getWorldDateString("Tokyo"),
225+
//blank image
226+
img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==")
227+
};
228+
},
229+
show : function() {
230+
this.interval = setTimeout(()=>{
231+
this.emit("redraw");
232+
this.interval = setInterval(()=>{
233+
this.emit("redraw");
234+
}, 60000);
235+
}, 60000 - (Date.now() % 60000));
236+
},
237+
hide : function() {
238+
clearInterval(this.interval);
239+
this.interval = undefined;
240+
},
241+
run : function() {
242+
//toggle showCityName
243+
244+
showCityName=!showCityName;
245+
this.emit("redraw");
246+
}
247+
},
248+
249+
{ name : "Dubai",
250+
get : () => {
251+
return {
252+
text : getWorldDateString("Dubai"),
253+
//blank image
254+
img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==")
255+
};
256+
},
257+
show : function() {
258+
this.interval = setTimeout(()=>{
259+
this.emit("redraw");
260+
this.interval = setInterval(()=>{
261+
this.emit("redraw");
262+
}, 60000);
263+
}, 60000 - (Date.now() % 60000));
264+
},
265+
hide : function() {
266+
clearInterval(this.interval);
267+
this.interval = undefined;
268+
},
269+
run : function() {
270+
//toggle showCityName
271+
272+
showCityName=!showCityName;
273+
this.emit("redraw");
274+
}
275+
},
276+
{ name : "Los Angeles",
277+
get : () => {
278+
return {
279+
text : getWorldDateString("Los Angeles"),
280+
//blank image
281+
img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==")
282+
};
283+
},
284+
show : function() {
285+
this.interval = setTimeout(()=>{
286+
this.emit("redraw");
287+
this.interval = setInterval(()=>{
288+
this.emit("redraw");
289+
}, 60000);
290+
}, 60000 - (Date.now() % 60000));
291+
},
292+
hide : function() {
293+
clearInterval(this.interval);
294+
this.interval = undefined;
295+
},
296+
run : function() {
297+
//toggle showCityName
298+
299+
showCityName=!showCityName;
300+
this.emit("redraw");
301+
}
302+
},
303+
304+
{ name : "Paris",
305+
get : () => {
306+
return {
307+
text : getWorldDateString("Paris"),
308+
//blank image
309+
img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==")
310+
};
311+
},
312+
show : function() {
313+
this.interval = setTimeout(()=>{
314+
this.emit("redraw");
315+
this.interval = setInterval(()=>{
316+
this.emit("redraw");
317+
}, 60000);
318+
}, 60000 - (Date.now() % 60000));
319+
},
320+
hide : function() {
321+
clearInterval(this.interval);
322+
this.interval = undefined;
323+
},
324+
run : function() {
325+
//toggle showCityName
326+
327+
showCityName=!showCityName;
328+
this.emit("redraw");
329+
}
330+
},
331+
{ name : "Hong Kong",
332+
get : () => {
333+
return {
334+
text : getWorldDateString("Hong Kong"),
335+
//blank image
336+
img : atob("GBiBAAD/AAPnwAbDYBiBGBEAiD///H///kMAwsIAQ4IAQYIAQf///////4IAQYIAQcIAQ0MAwn///j///BEAiBiBGAbDYAPnwAD/AA==")
337+
};
338+
},
339+
show : function() {
340+
this.interval = setTimeout(()=>{
341+
this.emit("redraw");
342+
this.interval = setInterval(()=>{
343+
this.emit("redraw");
344+
}, 60000);
345+
}, 60000 - (Date.now() % 60000));
346+
},
347+
hide : function() {
348+
clearInterval(this.interval);
349+
this.interval = undefined;
350+
},
351+
run : function() {
352+
//toggle showCityName
353+
354+
showCityName=!showCityName;
355+
this.emit("redraw");
356+
}
357+
}
358+
359+
360+
361+
]
362+
};
363+
})

0 commit comments

Comments
 (0)