Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 7ed87f8

Browse files
committed
added night time theme
1 parent 2504dfe commit 7ed87f8

File tree

8 files changed

+109
-57
lines changed

8 files changed

+109
-57
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"trailingComma": "none",
3-
"singleQuote": true,
3+
"singleQuote": false,
44
"tabWidth": 4,
55
"overrides": [
66
{

docs/app-de4e187b7364886c19cc.js renamed to docs/app-e84733b83675f92bac6c.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!doctype html><html lang="en"><head><meta charset="utf-8"/><title>Multiple Timezones Clock</title><style>body {
22
font-family: Arial, Helvetica, sans-serif;
3-
}</style><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"/><link rel="shortcut icon" href="./resources/favicon.ico"/><script defer="defer" src="./app-de4e187b7364886c19cc.js"></script></head><body><div id="main"></div></body></html>
3+
}</style><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"/><link rel="shortcut icon" href="./resources/favicon.ico"/><script defer="defer" src="./app-e84733b83675f92bac6c.js"></script></head><body><div id="main"></div></body></html>

src/modules/my/app/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h1 class="slds-text-heading_large slds-p-around_x-small">{title}</h1>
88
<div key={clock.timeZone}
99
class="slds-col slds-p-around_x-small slds-size_1-of-1 slds-medium-size_3-of-12 slds-large-size_3-of-12">
1010
<my-child time-zone={clock.timeZone} city={clock.city} time={time}
11-
refresh-interval={refreshInterval} is12-hours={clock.is12Hours}>
11+
refresh-interval={refreshInterval} footer-note={clock.footerNote} is12-hours={clock.is12Hours}>
1212
</my-child>
1313
</div>
1414
</template>

src/modules/my/app/app.js

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,95 @@
11
//import { LightningElement } from 'lwc';
2-
import SLDSLightningElement from 'my/sldsLightningElement';
2+
import SLDSLightningElement from "my/sldsLightningElement";
33
export default class App extends SLDSLightningElement {
44
time = new Date();
55

6-
title = 'Multiple Timezones Clock';
7-
refreshInterval = 'minute';
6+
title = "Multiple Timezones Clock";
7+
refreshInterval = "minute";
88

99
/**
1010
* Getter for the features property
1111
*/
1212
get clocks() {
1313
return [
1414
{
15-
timeZone: 'America/New_York',
16-
city: 'New York',
17-
is12Hours: false
15+
timeZone: "America/New_York",
16+
city: "New York",
17+
is12Hours: false,
18+
footerNote: "America/New York"
1819
},
1920
{
20-
timeZone: 'Etc/GMT',
21-
city: 'London/GMT',
22-
is12Hours: false
21+
timeZone: "US/Central",
22+
city: "Chicago",
23+
is12Hours: false,
24+
footerNote: "America/Chicago"
2325
},
2426
{
25-
timeZone: 'US/Central',
26-
city: 'Chicago',
27-
is12Hours: false
27+
timeZone: "America/Hermosillo",
28+
city: "Denver",
29+
is12Hours: false,
30+
footerNote: "America/Denver"
2831
},
2932
{
30-
timeZone: 'HST',
31-
city: 'Hawaii',
32-
is12Hours: false
33+
timeZone: "America/Los_Angeles",
34+
city: "San Francisco",
35+
is12Hours: false,
36+
footerNote: "America/San Francisco"
3337
},
3438
{
35-
timeZone: 'Asia/Chongqing',
36-
city: 'Philippines',
37-
is12Hours: false
39+
timeZone: "HST",
40+
city: "Honolulu",
41+
is12Hours: false,
42+
footerNote: "Hawaii/Honolulu"
3843
},
3944
{
40-
timeZone: 'Asia/Kolkata',
41-
city: 'Pune',
42-
is12Hours: false
45+
timeZone: "Asia/Tokyo",
46+
city: "Tokyo",
47+
is12Hours: false,
48+
footerNote: "Japan/Tokyo"
4349
},
4450
{
45-
timeZone: 'Etc/GMT+2',
46-
city: 'South Africa/Johannesburg',
47-
is12Hours: false
51+
timeZone: "Asia/Hong_Kong",
52+
city: "Hong Kong",
53+
is12Hours: false,
54+
footerNote: "Honk Kong"
4855
},
4956
{
50-
timeZone: 'Etc/GMT+1',
51-
city: 'Frankfurt',
52-
is12Hours: false
57+
timeZone: "Africa/Maputo",
58+
city: "Manila",
59+
is12Hours: false,
60+
footerNote: "Philippines/Manila"
61+
},
62+
{
63+
timeZone: "Asia/Kolkata",
64+
city: "Pune",
65+
is12Hours: false,
66+
footerNote: "India/Pune"
67+
},
68+
{
69+
timeZone: "Etc/GMT+2",
70+
city: "Johannesburg",
71+
is12Hours: false,
72+
footerNote: "South Africa/Johannesburg"
73+
},
74+
{
75+
timeZone: "Etc/GMT+1",
76+
city: "Frankfurt",
77+
is12Hours: false,
78+
footerNote: "Germany/Frankfurt"
79+
},
80+
{
81+
timeZone: "GMT",
82+
city: "London",
83+
is12Hours: false,
84+
footerNote: "UK/London"
5385
}
5486
];
5587
}
5688

5789
intervalId;
5890

5991
get interval() {
60-
return this.refreshInterval === 'minute' ? 60000 : 1000;
92+
return this.refreshInterval === "minute" ? 60000 : 1000;
6193
}
6294

6395
connectedCallback() {

src/modules/my/child/child.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
.clock {
22
font-size: 3rem;
33
text-align: center;
4-
color: grey;
54
}
65

76
.date {
87
text-align: center;
9-
color: grey;
108
font-size: 1rem;
119
}
1210

1311
.footer {
14-
color: grey;
1512
font-size: 1rem;
1613
}
14+
15+
.dayTime {
16+
color: grey;
17+
}
18+
.nightTime {
19+
background: gray;
20+
color: white;
21+
}

src/modules/my/child/child.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<template>
22
<my-card title={city}>
3-
<div class="clock">{time}</div>
4-
<div class="date slds-m-around_xxx-small">{weekday}</div>
5-
<div class="date slds-m-around_xxx-small">{date}</div>
3+
<div class={themeClass}>
4+
<div class="clock">{time}</div>
5+
<div class="date slds-m-around_xxx-small">{weekday}</div>
6+
<div class="date slds-m-around_xxx-small">{date}</div>
7+
</div>
68
<div slot="footer" class="footer">
7-
{timeZone}
9+
{footerNote}
810
</div>
911
</my-card>
1012
</template>

src/modules/my/child/child.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
import { /* LightningElement, */ api } from 'lwc';
2-
import SLDSLightningElement from 'my/sldsLightningElement';
1+
import { /* LightningElement, */ api } from "lwc";
2+
import SLDSLightningElement from "my/sldsLightningElement";
33
/**
44
* Show an item
55
*/
66
export default class Child extends SLDSLightningElement {
77
@api
8-
timeZone = '';
8+
timeZone = "";
99

1010
@api
11-
city = '';
11+
city = "";
1212

1313
@api
1414
is12Hours = false;
1515

1616
@api
1717
refreshInterval;
1818

19+
@api
20+
footerNote;
21+
1922
_time;
2023
date;
2124
weekday;
25+
themeClass;
2226

2327
@api
2428
get time() {
@@ -27,42 +31,51 @@ export default class Child extends SLDSLightningElement {
2731
set time(value) {
2832
let optionsMilitary = {
2933
hour12: this.is12Hours,
30-
hour: 'numeric',
31-
minute: '2-digit'
34+
hour: "numeric",
35+
minute: "2-digit"
3236
};
3337

34-
if (this.refreshInterval === 'second') {
35-
optionsMilitary.second = '2-digit';
38+
if (this.refreshInterval === "second") {
39+
optionsMilitary.second = "2-digit";
3640
}
3741

3842
let [hh, mm] = value
39-
.toLocaleString('en-US', {
43+
.toLocaleString("en-US", {
4044
...optionsMilitary,
4145
timeZone: this.timeZone
4246
})
43-
.split(':');
47+
.split(":");
4448

4549
if (parseInt(hh, 10) === 24) {
46-
hh = '00';
50+
hh = "00";
51+
}
52+
53+
let hoursNow = parseInt(hh, 10);
54+
if (hoursNow >= 20 || hoursNow <= 8) {
55+
this.themeClass = "slds-p-around_xx-small nightTime";
56+
} else {
57+
this.themeClass = "slds-p-around_xx-small dayTime";
4758
}
4859

4960
this._time =
50-
hh === '00' && mm === '00' ? '24:00' : (hh +":"+ mm).replace(/^24/, '00');
61+
hh === "00" && mm === "00"
62+
? "24:00"
63+
: (hh + ":" + mm).replace(/^24/, "00");
5164

5265
let dateOptions = {
53-
year: 'numeric',
54-
month: '2-digit',
55-
day: '2-digit'
66+
year: "numeric",
67+
month: "2-digit",
68+
day: "2-digit"
5669
};
57-
this.date = value.toLocaleString('en-US', {
70+
this.date = value.toLocaleString("en-US", {
5871
...dateOptions,
5972
timeZone: this.timeZone
6073
});
6174

6275
let weekdayOptions = {
63-
weekday: 'long'
76+
weekday: "long"
6477
};
65-
this.weekday = value.toLocaleString('en-US', {
78+
this.weekday = value.toLocaleString("en-US", {
6679
...weekdayOptions,
6780
timeZone: this.timeZone
6881
});

0 commit comments

Comments
 (0)