浏览代码

Move timeUtil.js out of features/base/util

Because timeUtil.js computes hours, minutes, and seconds out of a single
time/duration using three separate functions, I wouldn't recommend using
it, especially reusing it. That's why I'm even making the functions
private to their current use location.
master
Lyubo Marinov 8 年前
父节点
当前提交
a8b3177e20
共有 2 个文件被更改,包括 53 次插入46 次删除
  1. 0
    29
      react/features/base/util/timeUtils.js
  2. 53
    17
      react/features/speaker-stats/components/TimeElapsed.js

+ 0
- 29
react/features/base/util/timeUtils.js 查看文件

1
-/**
2
- * Counts how many whole hours are included in the given time total.
3
- *
4
- * @param {number} milliseconds - The millisecond total to get hours from.
5
- * @returns {number}
6
- */
7
-export function getHoursCount(milliseconds) {
8
-    return Math.floor(milliseconds / (60 * 60 * 1000));
9
-}
10
-
11
-/**
12
- * Counts how many whole minutes are included in the given time total.
13
- *
14
- * @param {number} milliseconds - The millisecond total to get minutes from.
15
- * @returns {number}
16
- */
17
-export function getMinutesCount(milliseconds) {
18
-    return Math.floor(milliseconds / (60 * 1000) % 60);
19
-}
20
-
21
-/**
22
- * Counts how many whole seconds are included in the given time total.
23
- *
24
- * @param {number} milliseconds - The millisecond total to get seconds from.
25
- * @returns {number}
26
- */
27
-export function getSecondsCount(milliseconds) {
28
-    return Math.floor(milliseconds / 1000 % 60);
29
-}

+ 53
- 17
react/features/speaker-stats/components/TimeElapsed.js 查看文件

1
 import React, { Component } from 'react';
1
 import React, { Component } from 'react';
2
 
2
 
3
 import { translate } from '../../base/i18n';
3
 import { translate } from '../../base/i18n';
4
-import {
5
-    getHoursCount,
6
-    getMinutesCount,
7
-    getSecondsCount
8
-} from '../../base/util/timeUtils';
9
 
4
 
10
 /**
5
 /**
11
  * React component for displaying total time elapsed. Converts a total count of
6
  * React component for displaying total time elapsed. Converts a total count of
27
         t: React.PropTypes.func,
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
         time: React.PropTypes.number
27
         time: React.PropTypes.number
33
     }
28
     }
39
      * @returns {ReactElement}
34
      * @returns {ReactElement}
40
      */
35
      */
41
     render() {
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
         const timeElapsed = [];
41
         const timeElapsed = [];
46
 
42
 
47
         if (hours) {
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
             timeElapsed.push(hourPassed);
47
             timeElapsed.push(hourPassed);
52
         }
48
         }
53
 
49
 
54
         if (hours || minutes) {
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
             timeElapsed.push(minutesPassed);
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
         timeElapsed.push(secondsPassed);
66
         timeElapsed.push(secondsPassed);
65
 
67
 
85
         const { t } = this.props;
87
         const { t } = this.props;
86
 
88
 
87
         return (
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
 export default translate(TimeElapsed);
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
+}

正在加载...
取消
保存