1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Merge pull request #768 from kmcc049/fix-bug-709

Change to using 1024 over 1000
This commit is contained in:
Mark McDowall 2015-09-23 11:32:27 -07:00
commit 5dae0b24d3
5 changed files with 24 additions and 20 deletions

View File

@ -8,13 +8,15 @@ namespace NzbDrone.Common.Test.ExtensionTests
public class Int64ExtensionFixture
{
[TestCase(0, "0 B")]
[TestCase(1000, "1.0 KB")]
[TestCase(1000000, "1.0 MB")]
[TestCase(377487360, "377.5 MB")]
[TestCase(1255864686, "1.3 GB")]
[TestCase(-1000000, "-1.0 MB")]
[TestCase(-377487360, "-377.5 MB")]
[TestCase(-1255864686, "-1.3 GB")]
[TestCase(1000, "1,000.0 B")]
[TestCase(1024, "1.0 KB")]
[TestCase(1000000, "976.6 KB")]
[TestCase(377487360, "360.0 MB")]
[TestCase(1255864686, "1.2 GB")]
[TestCase(-1024, "-1.0 KB")]
[TestCase(-1000000, "-976.6 KB")]
[TestCase(-377487360, "-360.0 MB")]
[TestCase(-1255864686, "-1.2 GB")]
public void should_calculate_string_correctly(long bytes, string expected)
{
bytes.SizeSuffix().Should().Be(expected);

View File

@ -9,7 +9,7 @@ public static class Int64Extensions
public static string SizeSuffix(this Int64 bytes)
{
const int bytesInKb = 1000;
const int bytesInKb = 1024;
if (bytes < 0) return "-" + SizeSuffix(-bytes);
if (bytes == 0) return "0 B";

View File

@ -1,5 +1,4 @@
var NzbDroneCell = require('../../Cells/NzbDroneCell');
var fileSize = require('filesize');
var moment = require('moment');
var UiSettingsModel = require('../../Shared/UiSettingsModel');
var FormatHelpers = require('../../Shared/FormatHelpers');
@ -19,8 +18,8 @@ module.exports = NzbDroneCell.extend({
}
var timeleft = this.cellValue.get('timeleft');
var totalSize = fileSize(this.cellValue.get('size'), 1, false);
var remainingSize = fileSize(this.cellValue.get('sizeleft'), 1, false);
var totalSize = FormatHelpers.bytes(this.cellValue.get('size'), 2);
var remainingSize = FormatHelpers.bytes(this.cellValue.get('sizeleft'), 2);
if (timeleft === undefined) {
this.$el.html('-');

View File

@ -1,7 +1,7 @@
var Marionette = require('marionette');
var AsModelBoundView = require('../../../Mixins/AsModelBoundView');
var fileSize = require('filesize');
require('jquery-ui');
var FormatHelpers = require('../../../Shared/FormatHelpers');
var view = Marionette.ItemView.extend({
template : 'Settings/Quality/Definition/QualityDefinitionItemViewTemplate',
@ -27,7 +27,6 @@ var view = Marionette.ItemView.extend({
initialize : function(options) {
this.profileCollection = options.profiles;
this.filesize = fileSize;
},
onRender : function() {
@ -66,11 +65,10 @@ var view = Marionette.ItemView.extend({
_changeSize : function() {
var minSize = this.model.get('minSize') || this.slider.min;
var maxSize = this.model.get('maxSize') || null;
{
var minBytes = minSize * 1024 * 1024;
var minThirty = fileSize(minBytes * 30, 1, false);
var minSixty = fileSize(minBytes * 60, 1, false);
var minThirty = FormatHelpers.bytes(minBytes * 30, 2);
var minSixty = FormatHelpers.bytes(minBytes * 60, 2);
this.ui.thirtyMinuteMinSize.html(minThirty);
this.ui.sixtyMinuteMinSize.html(minSixty);
@ -82,8 +80,8 @@ var view = Marionette.ItemView.extend({
this.ui.sixtyMinuteMaxSize.html('Unlimited');
} else {
var maxBytes = maxSize * 1024 * 1024;
var maxThirty = fileSize(maxBytes * 30, 1, false);
var maxSixty = fileSize(maxBytes * 60, 1, false);
var maxThirty = FormatHelpers.bytes(maxBytes * 30, 2);
var maxSixty = FormatHelpers.bytes(maxBytes * 60, 2);
this.ui.thirtyMinuteMaxSize.html(maxThirty);
this.ui.sixtyMinuteMaxSize.html(maxSixty);

View File

@ -3,16 +3,21 @@ var filesize = require('filesize');
var UiSettings = require('./UiSettingsModel');
module.exports = {
bytes : function(sourceSize) {
bytes : function(sourceSize, sourceRounding) {
var size = Number(sourceSize);
var rounding = Number(sourceRounding);
if (isNaN(size)) {
return '';
}
if (isNaN(rounding)) {
rounding = 1;
}
return filesize(size, {
base : 2,
round : 1
round : rounding
});
},