1
- ' use strict '
1
+
2
2
hsl = require (' hsl' )
3
3
React = require (' react' )
4
4
reset = require (' ../util/reset' )
@@ -7,9 +7,12 @@ now = new Date
7
7
thisYear = now .getFullYear ()
8
8
thisMonth = now .getMonth ()
9
9
thisDay = now .getDate ()
10
- module .exports = React .createClass (
10
+
11
+ module .exports = React .createClass
11
12
displayName : ' app-time'
12
- propTypes : time : React .PropTypes .string .isRequired
13
+ propTypes :
14
+ time : React .PropTypes .string .isRequired
15
+
13
16
getTime : ->
14
17
thatTime = new Date (@props .time )
15
18
current = new Date
@@ -20,28 +23,29 @@ module.exports = React.createClass(
20
23
thatMin = thatTime .getMinutes ()
21
24
currentHour = current .getHours ()
22
25
currentMin = current .getMinutes ()
23
- if thatYear != thisYear
24
- return thatYear + ' /' + thatMonth + ' /' + thatDay
25
- if thatMonth != thisMonth
26
- return thisMonth + ' /' + thatDay
27
- if thatDay != thisDay
28
- return ' ' + thisDay - thatDay + ' ' + ' days'
29
- if thatHour != currentHour
30
- return thatHour + ' :' + thatMin
31
- if thatMin != currentMin
32
- return thatHour + ' :' + thatMin
33
- ' now'
26
+
27
+ switch
28
+ when thatYear isnt thisYear
29
+ " #{ thatYear} /#{ thatMonth} /#{ thatDay} "
30
+ when thatMonth isnt thisMonth
31
+ " #{ thisMonth} /#{ thatDay} "
32
+ when thatDay isnt thisDay
33
+ " #{ thisDay - thatDay} days"
34
+ when thatHour isnt currentHour
35
+ " #{ thatHour} :#{ thatMin} "
36
+ when thatMin isnt currentMin
37
+ " #{ thatHour} :#{ thatMin} "
38
+ else ' now'
39
+
34
40
render : ->
35
- div { style : @ styleRoot () }, @ getTime ()
41
+ div style : @ styleRoot (), @ getTime ()
42
+
36
43
styleRoot : ->
37
- {
38
- color : hsl (0 , 0 , 86 )
39
- fontFamily : reset .fashionFonts
40
- padding : ' 0 0px'
41
- lineHeight : ' 18px'
42
- height : ' 18px'
43
- fontSize : ' 12px'
44
- borderRadius : 2
45
- whiteSpace : ' nowrap'
46
- }
47
- )
44
+ color : hsl (0 , 0 , 86 )
45
+ fontFamily : reset .fashionFonts
46
+ padding : ' 0 0px'
47
+ lineHeight : ' 18px'
48
+ height : ' 18px'
49
+ fontSize : ' 12px'
50
+ borderRadius : 2
51
+ whiteSpace : ' nowrap'
0 commit comments