diff --git a/src/NzbDrone.Common.Test/ExtensionTests/Int64ExtensionFixture.cs b/src/NzbDrone.Common.Test/ExtensionTests/Int64ExtensionFixture.cs index 40d78ed09..76e28f3f7 100644 --- a/src/NzbDrone.Common.Test/ExtensionTests/Int64ExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/ExtensionTests/Int64ExtensionFixture.cs @@ -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); diff --git a/src/NzbDrone.Common/Extensions/Int64Extensions.cs b/src/NzbDrone.Common/Extensions/Int64Extensions.cs index 43ec6c454..3da216ce9 100644 --- a/src/NzbDrone.Common/Extensions/Int64Extensions.cs +++ b/src/NzbDrone.Common/Extensions/Int64Extensions.cs @@ -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"; diff --git a/src/UI/Activity/Queue/TimeleftCell.js b/src/UI/Activity/Queue/TimeleftCell.js index 561fc8068..766d9df2d 100644 --- a/src/UI/Activity/Queue/TimeleftCell.js +++ b/src/UI/Activity/Queue/TimeleftCell.js @@ -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('-'); diff --git a/src/UI/Settings/Quality/Definition/QualityDefinitionItemView.js b/src/UI/Settings/Quality/Definition/QualityDefinitionItemView.js index d0b087d78..b663cf310 100644 --- a/src/UI/Settings/Quality/Definition/QualityDefinitionItemView.js +++ b/src/UI/Settings/Quality/Definition/QualityDefinitionItemView.js @@ -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); diff --git a/src/UI/Shared/FormatHelpers.js b/src/UI/Shared/FormatHelpers.js index 71f4faf8d..351501acd 100644 --- a/src/UI/Shared/FormatHelpers.js +++ b/src/UI/Shared/FormatHelpers.js @@ -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 }); },