"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7550/react/features/speaker-stats/components/timeFunctions.ts" (26 Sep 2023, 2336 Bytes) of package /linux/misc/jitsi-meet-7550.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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 * @private
6 * @returns {number}
7 */
8 function getHoursCount(milliseconds: number) {
9 return Math.floor(milliseconds / (60 * 60 * 1000));
10 }
11
12 /**
13 * Counts how many whole minutes are included in the given time total.
14 *
15 * @param {number} milliseconds - The millisecond total to get minutes from.
16 * @private
17 * @returns {number}
18 */
19 function getMinutesCount(milliseconds: number) {
20 return Math.floor(milliseconds / (60 * 1000) % 60);
21 }
22
23 /**
24 * Counts how many whole seconds are included in the given time total.
25 *
26 * @param {number} milliseconds - The millisecond total to get seconds from.
27 * @private
28 * @returns {number}
29 */
30 function getSecondsCount(milliseconds: number) {
31 return Math.floor(milliseconds / 1000 % 60);
32 }
33
34 /**
35 * Creates human readable localized time string.
36 *
37 * @param {number} time - Value in milliseconds.
38 * @param {Function} t - Translate function.
39 * @returns {string}
40 */
41 export function createLocalizedTime(time: number, t: Function) {
42 const hours = getHoursCount(time);
43 const minutes = getMinutesCount(time);
44 const seconds = getSecondsCount(time);
45 const timeElapsed = [];
46
47 if (hours) {
48 const hourPassed
49 = createTimeDisplay(hours, 'speakerStats.hours', t);
50
51 timeElapsed.push(hourPassed);
52 }
53
54 if (hours || minutes) {
55 const minutesPassed
56 = createTimeDisplay(
57 minutes,
58 'speakerStats.minutes',
59 t);
60
61 timeElapsed.push(minutesPassed);
62 }
63
64 const secondsPassed
65 = createTimeDisplay(
66 seconds,
67 'speakerStats.seconds',
68 t);
69
70 timeElapsed.push(secondsPassed);
71
72 return timeElapsed;
73 }
74
75 /**
76 * Returns a string to display the passed in count and a count noun.
77 *
78 * @private
79 * @param {number} count - The number used for display and to check for
80 * count noun plurality.
81 * @param {string} countNounKey - Translation key for the time's count noun.
82 * @param {Function} t - What is being counted. Used as the element's
83 * key for react to iterate upon.
84 * @returns {string}
85 */
86 function createTimeDisplay(count: number, countNounKey: string, t: Function) {
87 return t(countNounKey, { count });
88 }