@@ -10,16 +10,16 @@ function intToString(v) {
10
10
11
11
// Convert a plain text to an html escaped string.
12
12
function plainToHtml ( t ) {
13
- var escaped = t . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) // escape text
14
- return escaped . replace ( / \n / g, '<br>' ) // replace line breaks
13
+ var escaped = t . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) // escape text
14
+ return escaped . replace ( / \n / g, '<br>' ) // replace line breaks
15
15
}
16
16
17
17
function divmod ( x , y ) {
18
18
// Perform the division and get the quotient
19
- const quotient = Math . floor ( x / y ) ;
19
+ const quotient = Math . floor ( x / y )
20
20
// Compute the remainder
21
- const remainder = x % y ;
22
- return [ quotient , remainder ] ;
21
+ const remainder = x % y
22
+ return [ quotient , remainder ]
23
23
}
24
24
25
25
function sec2timeHMS ( totalSeconds ) {
@@ -30,7 +30,7 @@ function sec2timeHMS(totalSeconds) {
30
30
hours : hours ,
31
31
minutes : minutes ,
32
32
seconds : seconds
33
- } ;
33
+ }
34
34
}
35
35
36
36
function sec2timecode ( timeSeconds ) {
@@ -43,22 +43,22 @@ function sec2timecode(timeSeconds) {
43
43
function sec2timeStr ( timeSeconds ) {
44
44
// Need to decide the rounding precision first
45
45
// to propagate the right values
46
- if ( timeSeconds >= 60.0 ) {
46
+ if ( timeSeconds >= 60.0 ) {
47
47
timeSeconds = Math . round ( timeSeconds )
48
48
} else {
49
49
timeSeconds = parseFloat ( timeSeconds . toFixed ( 2 ) )
50
50
}
51
51
var timeObj = sec2timeHMS ( timeSeconds )
52
52
var timeStr = ""
53
- if ( timeObj . hours > 0 ) {
53
+ if ( timeObj . hours > 0 ) {
54
54
timeStr += timeObj . hours + "h"
55
55
}
56
- if ( timeObj . hours > 0 || timeObj . minutes > 0 ) {
56
+ if ( timeObj . hours > 0 || timeObj . minutes > 0 ) {
57
57
timeStr += timeObj . minutes + "m"
58
58
}
59
- if ( timeObj . hours === 0 ) {
59
+ if ( timeObj . hours === 0 ) {
60
60
// seconds only matter if the elapsed time is less than 1 hour
61
- if ( timeObj . minutes === 0 ) {
61
+ if ( timeObj . minutes === 0 ) {
62
62
// If less than a minute, keep millisecond precision
63
63
timeStr += timeObj . seconds . toFixed ( 2 ) + "s"
64
64
} else {
@@ -68,3 +68,39 @@ function sec2timeStr(timeSeconds) {
68
68
}
69
69
return timeStr
70
70
}
71
+
72
+ function GB2GBMBKB ( GB ) {
73
+ // Convert GB to GB, MB, KB
74
+ var GBInt = Math . floor ( GB )
75
+ var MB = Math . floor ( ( GB - GBInt ) * 1024 )
76
+ var KB = Math . floor ( ( ( GB - GBInt ) * 1024 - MB ) * 1024 )
77
+ return {
78
+ GB : GBInt ,
79
+ MB : MB ,
80
+ KB : KB
81
+ }
82
+ }
83
+
84
+ function GB2SizeStr ( GB ) {
85
+ // Convert GB to a human readable size string
86
+ // e.g. 1.23GB, 456MB, 789KB
87
+ // We only use one unit at a time
88
+ var sizeObj = GB2GBMBKB ( GB )
89
+ var sizeStr = ""
90
+ if ( sizeObj . GB > 0 ) {
91
+ sizeStr += sizeObj . GB
92
+ if ( sizeObj . MB > 0 && sizeObj . GB < 10 ) {
93
+ sizeStr += "." + Math . floor ( sizeObj . MB / 1024 * 1000 )
94
+ }
95
+ sizeStr += "GB"
96
+ } else if ( sizeObj . MB > 0 ) {
97
+ sizeStr = sizeObj . MB
98
+ if ( sizeObj . KB > 0 && sizeObj . MB < 10 ) {
99
+ sizeStr += "." + Math . floor ( sizeObj . KB / 1024 * 1000 )
100
+ }
101
+ sizeStr += "MB"
102
+ } else if ( sizeObj . GB === 0 && sizeObj . MB === 0 ) {
103
+ sizeStr += sizeObj . KB + "KB"
104
+ }
105
+ return sizeStr
106
+ }
0 commit comments