v0.1 #1

Merged
niklas merged 17 commits from develop into master 2020-04-22 14:53:02 +00:00
2 changed files with 24 additions and 5 deletions
Showing only changes of commit 8e185d9f98 - Show all commits

View File

@ -4,6 +4,7 @@ import "../style/clock.scss";
interface State {
time: string;
date: string;
}
class Clock extends React.Component<{}, State> {
@ -13,7 +14,8 @@ class Clock extends React.Component<{}, State> {
constructor(props) {
super(props);
this.state = {
time: "12:00"
time: "",
date: ""
};
}
@ -26,6 +28,13 @@ class Clock extends React.Component<{}, State> {
});
}
updateDate() {
const now = new Date();
this.setState({
date: `${now.toDateString()}`
});
}
zeroPad(number: number, pad: number): string {
const length = number.toString().length;
if (length < pad) {
@ -38,11 +47,15 @@ class Clock extends React.Component<{}, State> {
startTimer() {
this.interval = setInterval(()=>{
this.updateTime();
// This will change only if the tab stays open after midnight. But still, lets cover that
this.updateDate();
},1000);
}
componentDidMount() {
this.updateTime();
this.updateDate();
this.startTimer();
}
@ -55,6 +68,9 @@ class Clock extends React.Component<{}, State> {
<div className="time">
{this.state.time}
</div>
<div className="date">
{this.state.date}
</div>
</div>;
}

View File

@ -1,8 +1,11 @@
.clock-component{
text-align: center;
.time{
font-size: 10em;
text-align: center;
}
.date {
font-size: 1em;
margin-top: -1em;
}
}