|
@@ -1,11 +1,6 @@
|
1
|
1
|
import React, { Component } from 'react';
|
2
|
2
|
|
3
|
3
|
import { translate } from '../../base/i18n';
|
4
|
|
-import {
|
5
|
|
- getHoursCount,
|
6
|
|
- getMinutesCount,
|
7
|
|
- getSecondsCount
|
8
|
|
-} from '../../base/util/timeUtils';
|
9
|
4
|
|
10
|
5
|
/**
|
11
|
6
|
* React component for displaying total time elapsed. Converts a total count of
|
|
@@ -27,7 +22,7 @@ class TimeElapsed extends Component {
|
27
|
22
|
t: React.PropTypes.func,
|
28
|
23
|
|
29
|
24
|
/**
|
30
|
|
- * The milliseconds to be converted into a humanized format.
|
|
25
|
+ * The milliseconds to be converted into a human-readable format.
|
31
|
26
|
*/
|
32
|
27
|
time: React.PropTypes.number
|
33
|
28
|
}
|
|
@@ -39,27 +34,34 @@ class TimeElapsed extends Component {
|
39
|
34
|
* @returns {ReactElement}
|
40
|
35
|
*/
|
41
|
36
|
render() {
|
42
|
|
- const hours = getHoursCount(this.props.time);
|
43
|
|
- const minutes = getMinutesCount(this.props.time);
|
44
|
|
- const seconds = getSecondsCount(this.props.time);
|
|
37
|
+ const { time } = this.props;
|
|
38
|
+ const hours = _getHoursCount(time);
|
|
39
|
+ const minutes = _getMinutesCount(time);
|
|
40
|
+ const seconds = _getSecondsCount(time);
|
45
|
41
|
const timeElapsed = [];
|
46
|
42
|
|
47
|
43
|
if (hours) {
|
48
|
|
- const hourPassed = this._createTimeDisplay(hours,
|
49
|
|
- 'speakerStats.hours', 'hours');
|
|
44
|
+ const hourPassed
|
|
45
|
+ = this._createTimeDisplay(hours, 'speakerStats.hours', 'hours');
|
50
|
46
|
|
51
|
47
|
timeElapsed.push(hourPassed);
|
52
|
48
|
}
|
53
|
49
|
|
54
|
50
|
if (hours || minutes) {
|
55
|
|
- const minutesPassed = this._createTimeDisplay(minutes,
|
56
|
|
- 'speakerStats.minutes', 'minutes');
|
|
51
|
+ const minutesPassed
|
|
52
|
+ = this._createTimeDisplay(
|
|
53
|
+ minutes,
|
|
54
|
+ 'speakerStats.minutes',
|
|
55
|
+ 'minutes');
|
57
|
56
|
|
58
|
57
|
timeElapsed.push(minutesPassed);
|
59
|
58
|
}
|
60
|
59
|
|
61
|
|
- const secondsPassed = this._createTimeDisplay(seconds,
|
62
|
|
- 'speakerStats.seconds', 'seconds');
|
|
60
|
+ const secondsPassed
|
|
61
|
+ = this._createTimeDisplay(
|
|
62
|
+ seconds,
|
|
63
|
+ 'speakerStats.seconds',
|
|
64
|
+ 'seconds');
|
63
|
65
|
|
64
|
66
|
timeElapsed.push(secondsPassed);
|
65
|
67
|
|
|
@@ -85,10 +87,44 @@ class TimeElapsed extends Component {
|
85
|
87
|
const { t } = this.props;
|
86
|
88
|
|
87
|
89
|
return (
|
88
|
|
- <span key = { countType } > { t(countNounKey, { count }) } </span>
|
|
90
|
+ <span key = { countType } >
|
|
91
|
+ { t(countNounKey, { count }) }
|
|
92
|
+ </span>
|
89
|
93
|
);
|
90
|
94
|
}
|
91
|
|
-
|
92
|
95
|
}
|
93
|
96
|
|
94
|
97
|
export default translate(TimeElapsed);
|
|
98
|
+
|
|
99
|
+/**
|
|
100
|
+ * Counts how many whole hours are included in the given time total.
|
|
101
|
+ *
|
|
102
|
+ * @param {number} milliseconds - The millisecond total to get hours from.
|
|
103
|
+ * @private
|
|
104
|
+ * @returns {number}
|
|
105
|
+ */
|
|
106
|
+function _getHoursCount(milliseconds) {
|
|
107
|
+ return Math.floor(milliseconds / (60 * 60 * 1000));
|
|
108
|
+}
|
|
109
|
+
|
|
110
|
+/**
|
|
111
|
+ * Counts how many whole minutes are included in the given time total.
|
|
112
|
+ *
|
|
113
|
+ * @param {number} milliseconds - The millisecond total to get minutes from.
|
|
114
|
+ * @private
|
|
115
|
+ * @returns {number}
|
|
116
|
+ */
|
|
117
|
+function _getMinutesCount(milliseconds) {
|
|
118
|
+ return Math.floor(milliseconds / (60 * 1000) % 60);
|
|
119
|
+}
|
|
120
|
+
|
|
121
|
+/**
|
|
122
|
+ * Counts how many whole seconds are included in the given time total.
|
|
123
|
+ *
|
|
124
|
+ * @param {number} milliseconds - The millisecond total to get seconds from.
|
|
125
|
+ * @private
|
|
126
|
+ * @returns {number}
|
|
127
|
+ */
|
|
128
|
+function _getSecondsCount(milliseconds) {
|
|
129
|
+ return Math.floor(milliseconds / 1000 % 60);
|
|
130
|
+}
|