Last active
May 31, 2019 20:16
-
-
Save leetheguy/b3dffaf49232b939f23640d5238ebda0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, State, Listen } from '@stencil/core'; | |
@Component({ | |
tag: 'analog-clock', | |
}) | |
export class AnalogClock { | |
timer: number; | |
@State() time: number = Date.now(); | |
@State() timeZone: number = 0; | |
@Listen('timeZoneChanged') | |
timeZoneChangedHandler(event: CustomEvent) { | |
this.timeZone = event.detail; | |
} | |
componentDidLoad() { | |
this.timer = window.setInterval(() => { | |
this.time = Date.now(); | |
}, 250); | |
} | |
componentDidUnload() { | |
clearInterval(this.timer); | |
} | |
get hour(): number { | |
return new Date(this.time).getHours(); | |
} | |
get minute(): number { | |
return new Date(this.time).getMinutes(); | |
} | |
get second(): number { | |
return new Date(this.time).getSeconds(); | |
} | |
render() { | |
return ( | |
<div> | |
<clock-face hour={this.hour + this.timeZone} minute={this.minute} second={this.second}/> | |
<time-zone-slider offset={this.timeZone}/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment