-
Notifications
You must be signed in to change notification settings - Fork 190
/
index.js
48 lines (39 loc) · 932 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Component } from 'react'
import tinytime from 'tinytime'
import styled from 'styled-components'
import Widget from '../../widget'
const TimeItem = styled.div`
font-size: 4em;
text-align: center;
`
const DateItem = styled.div`
font-size: 1.5em;
text-align: center;
`
export default class DateTime extends Component {
static defaultProps = {
interval: 1000 * 10
}
state = {
date: new Date()
}
componentDidMount () {
const { interval } = this.props
this.interval = setInterval(() => this.updateTime(), interval)
}
updateTime () {
this.setState({ date: new Date() })
}
componentWillUnmount () {
clearInterval(this.interval)
}
render () {
const { date } = this.state
return (
<Widget>
<TimeItem>{tinytime('{H}:{mm}').render(date)}</TimeItem>
<DateItem>{tinytime('{DD}.{Mo}.{YYYY}').render(date)}</DateItem>
</Widget>
)
}
}