@@ -5,6 +5,12 @@ import mergeClassNames from 'merge-class-names';
55import Hand from './Hand' ;
66import Mark from './Mark' ;
77
8+ import {
9+ getHours ,
10+ getMinutes ,
11+ getSeconds ,
12+ } from './shared/dates' ;
13+
814export default class Clock extends Component {
915 renderFace ( ) {
1016 const {
@@ -63,11 +69,11 @@ export default class Clock extends Component {
6369 value,
6470 } = this . props ;
6571
66- const angle = (
67- ( value . getHours ( ) * 30 ) +
68- ( value . getMinutes ( ) / 2 ) +
69- ( value . getSeconds ( ) / 600 )
70- ) ;
72+ const angle = value ? (
73+ ( getHours ( value ) * 30 ) +
74+ ( getMinutes ( value ) / 2 ) +
75+ ( getSeconds ( value ) / 600 )
76+ ) : 0 ;
7177
7278 return (
7379 < Hand
@@ -92,11 +98,11 @@ export default class Clock extends Component {
9298 value,
9399 } = this . props ;
94100
95- const angle = (
96- ( value . getHours ( ) * 360 ) +
97- ( value . getMinutes ( ) * 6 ) +
98- ( value . getSeconds ( ) / 10 )
99- ) ;
101+ const angle = value ? (
102+ ( getHours ( value ) * 360 ) +
103+ ( getMinutes ( value ) * 6 ) +
104+ ( getSeconds ( value ) / 10 )
105+ ) : 0 ;
100106
101107 return (
102108 < Hand
@@ -121,10 +127,10 @@ export default class Clock extends Component {
121127 value,
122128 } = this . props ;
123129
124- const angle = (
125- ( value . getMinutes ( ) * 360 ) +
126- ( value . getSeconds ( ) * 6 )
127- ) ;
130+ const angle = value ? (
131+ ( getMinutes ( value ) * 360 ) +
132+ ( getSeconds ( value ) * 6 )
133+ ) : 0 ;
128134
129135 return (
130136 < Hand
@@ -143,7 +149,7 @@ export default class Clock extends Component {
143149 return (
144150 < time
145151 className = { mergeClassNames ( 'react-clock' , this . props . className ) }
146- dateTime = { value . toISOString ( ) }
152+ dateTime = { value instanceof Date ? value . toISOString ( ) : value }
147153 style = { {
148154 width : `${ size } px` ,
149155 height : `${ size } px` ,
@@ -199,5 +205,8 @@ Clock.propTypes = {
199205 secondHandOppositeLength : PropTypes . number ,
200206 secondHandWidth : PropTypes . number ,
201207 size : PropTypes . number ,
202- value : PropTypes . instanceOf ( Date ) ,
208+ value : PropTypes . oneOfType ( [
209+ PropTypes . string ,
210+ PropTypes . instanceOf ( Date ) ,
211+ ] ) ,
203212} ;
0 commit comments