Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
69f1f173
Commit
69f1f173
authored
May 25, 2021
by
Thomas Randolph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix humanized size numbers for negative values
Changelog: fixed
parent
a44d81f1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
app/assets/javascripts/lib/utils/number_utils.js
app/assets/javascripts/lib/utils/number_utils.js
+5
-3
spec/frontend/lib/utils/number_utility_spec.js
spec/frontend/lib/utils/number_utility_spec.js
+4
-0
No files found.
app/assets/javascripts/lib/utils/number_utils.js
View file @
69f1f173
...
...
@@ -72,11 +72,13 @@ export function bytesToGiB(number) {
* @returns {String}
*/
export
function
numberToHumanSize
(
size
)
{
if
(
size
<
BYTES_IN_KIB
)
{
const
abs
=
Math
.
abs
(
size
);
if
(
abs
<
BYTES_IN_KIB
)
{
return
sprintf
(
__
(
'
%{size} bytes
'
),
{
size
});
}
else
if
(
size
<
BYTES_IN_KIB
*
BYTES_IN_KIB
)
{
}
else
if
(
abs
<
BYTES_IN_KIB
**
2
)
{
return
sprintf
(
__
(
'
%{size} KiB
'
),
{
size
:
bytesToKiB
(
size
).
toFixed
(
2
)
});
}
else
if
(
size
<
BYTES_IN_KIB
*
BYTES_IN_KIB
*
BYTES_IN_KIB
)
{
}
else
if
(
abs
<
BYTES_IN_KIB
**
3
)
{
return
sprintf
(
__
(
'
%{size} MiB
'
),
{
size
:
bytesToMiB
(
size
).
toFixed
(
2
)
});
}
return
sprintf
(
__
(
'
%{size} GiB
'
),
{
size
:
bytesToGiB
(
size
).
toFixed
(
2
)
});
...
...
spec/frontend/lib/utils/number_utility_spec.js
View file @
69f1f173
...
...
@@ -80,18 +80,22 @@ describe('Number Utils', () => {
describe
(
'
numberToHumanSize
'
,
()
=>
{
it
(
'
should return bytes
'
,
()
=>
{
expect
(
numberToHumanSize
(
654
)).
toEqual
(
'
654 bytes
'
);
expect
(
numberToHumanSize
(
-
654
)).
toEqual
(
'
-654 bytes
'
);
});
it
(
'
should return KiB
'
,
()
=>
{
expect
(
numberToHumanSize
(
1079
)).
toEqual
(
'
1.05 KiB
'
);
expect
(
numberToHumanSize
(
-
1079
)).
toEqual
(
'
-1.05 KiB
'
);
});
it
(
'
should return MiB
'
,
()
=>
{
expect
(
numberToHumanSize
(
10485764
)).
toEqual
(
'
10.00 MiB
'
);
expect
(
numberToHumanSize
(
-
10485764
)).
toEqual
(
'
-10.00 MiB
'
);
});
it
(
'
should return GiB
'
,
()
=>
{
expect
(
numberToHumanSize
(
10737418240
)).
toEqual
(
'
10.00 GiB
'
);
expect
(
numberToHumanSize
(
-
10737418240
)).
toEqual
(
'
-10.00 GiB
'
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment