diff --git a/readme.md b/readme.md index 6359380af..329b04f41 100644 --- a/readme.md +++ b/readme.md @@ -999,12 +999,18 @@ Here are a few examples of how you can convert from numbers to byte sizes and be ```c# var fileSize = (10).Kilobytes(); -fileSize.Bits => 81920 -fileSize.Bytes => 10240 -fileSize.Kilobytes => 10 -fileSize.Megabytes => 0.009765625 -fileSize.Gigabytes => 9.53674316e-6 -fileSize.Terabytes => 9.31322575e-9 +fileSize.Bits => 81920 +fileSize.Bytes => 10240 +fileSize.Kilobytes => 10 +fileSize.Megabytes => 0.009765625 +fileSize.Gigabytes => 9.53674316e-6 +fileSize.Terabytes => 9.31322575e-9 +fileSize.Petabytes => 9.09494701e-12 +fileSize.Exabytes => 8.88178419e-15 +fileSize.Zettabytes => 8.67361737e-18 +fileSize.Yottabytes => 8.47032947e-21 +fileSize.Ronnabytes => 8.27180612e-24 +fileSize.Quettabytes => 8.07793566e-27 ``` There are a few extension methods that allow you to turn a number into a ByteSize instance: @@ -1016,6 +1022,11 @@ There are a few extension methods that allow you to turn a number into a ByteSiz (2.5).Megabytes(); (10.2).Gigabytes(); (4.7).Terabytes(); +(8.3d).Petabytes(); +(17.38).Exabytes(); +(7.9).Yottabytes(); +(59.3).Ronnabytes(); +(10).Quettabytes(); ``` You can also add/subtract the values using +/- operators and Add/Subtract methods: diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt index bb3920e7f..089e94794 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.DotNet8_0.verified.txt @@ -18,37 +18,67 @@ namespace Humanizer public const long BitsInByte = 8; public const string Byte = "byte"; public const string ByteSymbol = "B"; + public const long BytesInExabyte = 1152921504606846976; public const long BytesInGigabyte = 1073741824; public const long BytesInKilobyte = 1024; public const long BytesInMegabyte = 1048576; + public const long BytesInPetabyte = 1125899906842624; + public const double BytesInQuettabyte = 1.2676506002282294E+30D; + public const double BytesInRonnabyte = 1.2379400392853803E+27D; public const long BytesInTerabyte = 1099511627776; + public const double BytesInYottabyte = 1.2089258196146292E+24D; + public const double BytesInZettabyte = 1.1805916207174113E+21D; + public const string Exabyte = "exabyte"; + public const string ExabyteSymbol = "EB"; public const string Gigabyte = "gigabyte"; public const string GigabyteSymbol = "GB"; public const string Kilobyte = "kilobyte"; public const string KilobyteSymbol = "KB"; public const string Megabyte = "megabyte"; public const string MegabyteSymbol = "MB"; + public const string Petabyte = "petabyte"; + public const string PetabyteSymbol = "PB"; + public const string Quettabyte = "quettabyte"; + public const string QuettabyteSymbol = "QB"; + public const string Ronnabyte = "ronnabyte"; + public const string RonnabyteSymbol = "RB"; public const string Terabyte = "terabyte"; public const string TerabyteSymbol = "TB"; + public const string Yottabyte = "yottabyte"; + public const string YottabyteSymbol = "YB"; + public const string Zettabyte = "zettabyte"; + public const string ZettabyteSymbol = "ZB"; public static readonly Humanizer.ByteSize MaxValue; public static readonly Humanizer.ByteSize MinValue; public ByteSize(double byteSize) { } - public long Bits { get; } + public double Bits { get; } public double Bytes { get; } + public double Exabytes { get; } public double Gigabytes { get; } public double Kilobytes { get; } public string LargestWholeNumberFullWord { get; } public string LargestWholeNumberSymbol { get; } public double LargestWholeNumberValue { get; } public double Megabytes { get; } + public double Petabytes { get; } + public double Quettabytes { get; } + public double Ronnabytes { get; } public double Terabytes { get; } + public double Yottabytes { get; } + public double Zettabytes { get; } public Humanizer.ByteSize Add(Humanizer.ByteSize bs) { } public Humanizer.ByteSize AddBits(long value) { } public Humanizer.ByteSize AddBytes(double value) { } + public Humanizer.ByteSize AddExabytes(double value) { } public Humanizer.ByteSize AddGigabytes(double value) { } public Humanizer.ByteSize AddKilobytes(double value) { } public Humanizer.ByteSize AddMegabytes(double value) { } + public Humanizer.ByteSize AddPetabytes(double value) { } + public Humanizer.ByteSize AddQuettabytes(double value) { } + public Humanizer.ByteSize AddRonnabytes(double value) { } public Humanizer.ByteSize AddTerabytes(double value) { } + public Humanizer.ByteSize AddYottabytes(double value) { } + public Humanizer.ByteSize AddZettabytes(double value) { } public int CompareTo(Humanizer.ByteSize other) { } public int CompareTo(object? obj) { } public bool Equals(Humanizer.ByteSize value) { } @@ -64,10 +94,16 @@ namespace Humanizer public string ToString(string? format, System.IFormatProvider? provider) { } public static Humanizer.ByteSize FromBits(long value) { } public static Humanizer.ByteSize FromBytes(double value) { } + public static Humanizer.ByteSize FromExabytes(double value) { } public static Humanizer.ByteSize FromGigabytes(double value) { } public static Humanizer.ByteSize FromKilobytes(double value) { } public static Humanizer.ByteSize FromMegabytes(double value) { } + public static Humanizer.ByteSize FromPetabytes(double value) { } + public static Humanizer.ByteSize FromQuettabytes(double value) { } + public static Humanizer.ByteSize FromRonnabytes(double value) { } public static Humanizer.ByteSize FromTerabytes(double value) { } + public static Humanizer.ByteSize FromYottabytes(double value) { } + public static Humanizer.ByteSize FromZettabytes(double value) { } public static Humanizer.ByteSize Parse(string s) { } public static Humanizer.ByteSize Parse(string s, System.IFormatProvider? formatProvider) { } public static bool TryParse(System.ReadOnlySpan s, out Humanizer.ByteSize result) { } @@ -103,6 +139,14 @@ namespace Humanizer public static Humanizer.ByteSize Bytes(this short input) { } public static Humanizer.ByteSize Bytes(this uint input) { } public static Humanizer.ByteSize Bytes(this ushort input) { } + public static Humanizer.ByteSize Exabytes(this byte input) { } + public static Humanizer.ByteSize Exabytes(this double input) { } + public static Humanizer.ByteSize Exabytes(this int input) { } + public static Humanizer.ByteSize Exabytes(this long input) { } + public static Humanizer.ByteSize Exabytes(this sbyte input) { } + public static Humanizer.ByteSize Exabytes(this short input) { } + public static Humanizer.ByteSize Exabytes(this uint input) { } + public static Humanizer.ByteSize Exabytes(this ushort input) { } public static Humanizer.ByteSize Gigabytes(this byte input) { } public static Humanizer.ByteSize Gigabytes(this double input) { } public static Humanizer.ByteSize Gigabytes(this int input) { } @@ -131,6 +175,30 @@ namespace Humanizer public static Humanizer.ByteSize Megabytes(this uint input) { } public static Humanizer.ByteSize Megabytes(this ushort input) { } public static Humanizer.ByteRate Per(this Humanizer.ByteSize size, System.TimeSpan interval) { } + public static Humanizer.ByteSize Petabytes(this byte input) { } + public static Humanizer.ByteSize Petabytes(this double input) { } + public static Humanizer.ByteSize Petabytes(this int input) { } + public static Humanizer.ByteSize Petabytes(this long input) { } + public static Humanizer.ByteSize Petabytes(this sbyte input) { } + public static Humanizer.ByteSize Petabytes(this short input) { } + public static Humanizer.ByteSize Petabytes(this uint input) { } + public static Humanizer.ByteSize Petabytes(this ushort input) { } + public static Humanizer.ByteSize Quettabytes(this byte input) { } + public static Humanizer.ByteSize Quettabytes(this double input) { } + public static Humanizer.ByteSize Quettabytes(this int input) { } + public static Humanizer.ByteSize Quettabytes(this long input) { } + public static Humanizer.ByteSize Quettabytes(this sbyte input) { } + public static Humanizer.ByteSize Quettabytes(this short input) { } + public static Humanizer.ByteSize Quettabytes(this uint input) { } + public static Humanizer.ByteSize Quettabytes(this ushort input) { } + public static Humanizer.ByteSize Ronnabytes(this byte input) { } + public static Humanizer.ByteSize Ronnabytes(this double input) { } + public static Humanizer.ByteSize Ronnabytes(this int input) { } + public static Humanizer.ByteSize Ronnabytes(this long input) { } + public static Humanizer.ByteSize Ronnabytes(this sbyte input) { } + public static Humanizer.ByteSize Ronnabytes(this short input) { } + public static Humanizer.ByteSize Ronnabytes(this uint input) { } + public static Humanizer.ByteSize Ronnabytes(this ushort input) { } public static Humanizer.ByteSize Terabytes(this byte input) { } public static Humanizer.ByteSize Terabytes(this double input) { } public static Humanizer.ByteSize Terabytes(this int input) { } @@ -139,6 +207,22 @@ namespace Humanizer public static Humanizer.ByteSize Terabytes(this short input) { } public static Humanizer.ByteSize Terabytes(this uint input) { } public static Humanizer.ByteSize Terabytes(this ushort input) { } + public static Humanizer.ByteSize Yottabytes(this byte input) { } + public static Humanizer.ByteSize Yottabytes(this double input) { } + public static Humanizer.ByteSize Yottabytes(this int input) { } + public static Humanizer.ByteSize Yottabytes(this long input) { } + public static Humanizer.ByteSize Yottabytes(this sbyte input) { } + public static Humanizer.ByteSize Yottabytes(this short input) { } + public static Humanizer.ByteSize Yottabytes(this uint input) { } + public static Humanizer.ByteSize Yottabytes(this ushort input) { } + public static Humanizer.ByteSize Zettabytes(this byte input) { } + public static Humanizer.ByteSize Zettabytes(this double input) { } + public static Humanizer.ByteSize Zettabytes(this int input) { } + public static Humanizer.ByteSize Zettabytes(this long input) { } + public static Humanizer.ByteSize Zettabytes(this sbyte input) { } + public static Humanizer.ByteSize Zettabytes(this short input) { } + public static Humanizer.ByteSize Zettabytes(this uint input) { } + public static Humanizer.ByteSize Zettabytes(this ushort input) { } } public static class CasingExtensions { @@ -181,6 +265,12 @@ namespace Humanizer Megabyte = 3, Gigabyte = 4, Terabyte = 5, + Petabyte = 6, + Exabyte = 7, + Zettabyte = 8, + Yottabyte = 9, + Ronnabyte = 10, + Quettabyte = 11, } public static class DateHumanizeExtensions { diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt index 44794d215..06c3939cb 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.Approve_Public_Api.Net4_8.verified.txt @@ -17,37 +17,67 @@ namespace Humanizer public const long BitsInByte = 8; public const string Byte = "byte"; public const string ByteSymbol = "B"; + public const long BytesInExabyte = 1152921504606846976; public const long BytesInGigabyte = 1073741824; public const long BytesInKilobyte = 1024; public const long BytesInMegabyte = 1048576; + public const long BytesInPetabyte = 1125899906842624; + public const double BytesInQuettabyte = 1.2676506002282294E+30D; + public const double BytesInRonnabyte = 1.2379400392853803E+27D; public const long BytesInTerabyte = 1099511627776; + public const double BytesInYottabyte = 1.2089258196146292E+24D; + public const double BytesInZettabyte = 1.1805916207174113E+21D; + public const string Exabyte = "exabyte"; + public const string ExabyteSymbol = "EB"; public const string Gigabyte = "gigabyte"; public const string GigabyteSymbol = "GB"; public const string Kilobyte = "kilobyte"; public const string KilobyteSymbol = "KB"; public const string Megabyte = "megabyte"; public const string MegabyteSymbol = "MB"; + public const string Petabyte = "petabyte"; + public const string PetabyteSymbol = "PB"; + public const string Quettabyte = "quettabyte"; + public const string QuettabyteSymbol = "QB"; + public const string Ronnabyte = "ronnabyte"; + public const string RonnabyteSymbol = "RB"; public const string Terabyte = "terabyte"; public const string TerabyteSymbol = "TB"; + public const string Yottabyte = "yottabyte"; + public const string YottabyteSymbol = "YB"; + public const string Zettabyte = "zettabyte"; + public const string ZettabyteSymbol = "ZB"; public static readonly Humanizer.ByteSize MaxValue; public static readonly Humanizer.ByteSize MinValue; public ByteSize(double byteSize) { } - public long Bits { get; } + public double Bits { get; } public double Bytes { get; } + public double Exabytes { get; } public double Gigabytes { get; } public double Kilobytes { get; } public string LargestWholeNumberFullWord { get; } public string LargestWholeNumberSymbol { get; } public double LargestWholeNumberValue { get; } public double Megabytes { get; } + public double Petabytes { get; } + public double Quettabytes { get; } + public double Ronnabytes { get; } public double Terabytes { get; } + public double Yottabytes { get; } + public double Zettabytes { get; } public Humanizer.ByteSize Add(Humanizer.ByteSize bs) { } public Humanizer.ByteSize AddBits(long value) { } public Humanizer.ByteSize AddBytes(double value) { } + public Humanizer.ByteSize AddExabytes(double value) { } public Humanizer.ByteSize AddGigabytes(double value) { } public Humanizer.ByteSize AddKilobytes(double value) { } public Humanizer.ByteSize AddMegabytes(double value) { } + public Humanizer.ByteSize AddPetabytes(double value) { } + public Humanizer.ByteSize AddQuettabytes(double value) { } + public Humanizer.ByteSize AddRonnabytes(double value) { } public Humanizer.ByteSize AddTerabytes(double value) { } + public Humanizer.ByteSize AddYottabytes(double value) { } + public Humanizer.ByteSize AddZettabytes(double value) { } public int CompareTo(Humanizer.ByteSize other) { } public int CompareTo(object? obj) { } public bool Equals(Humanizer.ByteSize value) { } @@ -63,10 +93,16 @@ namespace Humanizer public string ToString(string? format, System.IFormatProvider? provider) { } public static Humanizer.ByteSize FromBits(long value) { } public static Humanizer.ByteSize FromBytes(double value) { } + public static Humanizer.ByteSize FromExabytes(double value) { } public static Humanizer.ByteSize FromGigabytes(double value) { } public static Humanizer.ByteSize FromKilobytes(double value) { } public static Humanizer.ByteSize FromMegabytes(double value) { } + public static Humanizer.ByteSize FromPetabytes(double value) { } + public static Humanizer.ByteSize FromQuettabytes(double value) { } + public static Humanizer.ByteSize FromRonnabytes(double value) { } public static Humanizer.ByteSize FromTerabytes(double value) { } + public static Humanizer.ByteSize FromYottabytes(double value) { } + public static Humanizer.ByteSize FromZettabytes(double value) { } public static Humanizer.ByteSize Parse(string s) { } public static Humanizer.ByteSize Parse(string s, System.IFormatProvider? formatProvider) { } public static bool TryParse(System.ReadOnlySpan s, out Humanizer.ByteSize result) { } @@ -102,6 +138,14 @@ namespace Humanizer public static Humanizer.ByteSize Bytes(this short input) { } public static Humanizer.ByteSize Bytes(this uint input) { } public static Humanizer.ByteSize Bytes(this ushort input) { } + public static Humanizer.ByteSize Exabytes(this byte input) { } + public static Humanizer.ByteSize Exabytes(this double input) { } + public static Humanizer.ByteSize Exabytes(this int input) { } + public static Humanizer.ByteSize Exabytes(this long input) { } + public static Humanizer.ByteSize Exabytes(this sbyte input) { } + public static Humanizer.ByteSize Exabytes(this short input) { } + public static Humanizer.ByteSize Exabytes(this uint input) { } + public static Humanizer.ByteSize Exabytes(this ushort input) { } public static Humanizer.ByteSize Gigabytes(this byte input) { } public static Humanizer.ByteSize Gigabytes(this double input) { } public static Humanizer.ByteSize Gigabytes(this int input) { } @@ -130,6 +174,30 @@ namespace Humanizer public static Humanizer.ByteSize Megabytes(this uint input) { } public static Humanizer.ByteSize Megabytes(this ushort input) { } public static Humanizer.ByteRate Per(this Humanizer.ByteSize size, System.TimeSpan interval) { } + public static Humanizer.ByteSize Petabytes(this byte input) { } + public static Humanizer.ByteSize Petabytes(this double input) { } + public static Humanizer.ByteSize Petabytes(this int input) { } + public static Humanizer.ByteSize Petabytes(this long input) { } + public static Humanizer.ByteSize Petabytes(this sbyte input) { } + public static Humanizer.ByteSize Petabytes(this short input) { } + public static Humanizer.ByteSize Petabytes(this uint input) { } + public static Humanizer.ByteSize Petabytes(this ushort input) { } + public static Humanizer.ByteSize Quettabytes(this byte input) { } + public static Humanizer.ByteSize Quettabytes(this double input) { } + public static Humanizer.ByteSize Quettabytes(this int input) { } + public static Humanizer.ByteSize Quettabytes(this long input) { } + public static Humanizer.ByteSize Quettabytes(this sbyte input) { } + public static Humanizer.ByteSize Quettabytes(this short input) { } + public static Humanizer.ByteSize Quettabytes(this uint input) { } + public static Humanizer.ByteSize Quettabytes(this ushort input) { } + public static Humanizer.ByteSize Ronnabytes(this byte input) { } + public static Humanizer.ByteSize Ronnabytes(this double input) { } + public static Humanizer.ByteSize Ronnabytes(this int input) { } + public static Humanizer.ByteSize Ronnabytes(this long input) { } + public static Humanizer.ByteSize Ronnabytes(this sbyte input) { } + public static Humanizer.ByteSize Ronnabytes(this short input) { } + public static Humanizer.ByteSize Ronnabytes(this uint input) { } + public static Humanizer.ByteSize Ronnabytes(this ushort input) { } public static Humanizer.ByteSize Terabytes(this byte input) { } public static Humanizer.ByteSize Terabytes(this double input) { } public static Humanizer.ByteSize Terabytes(this int input) { } @@ -138,6 +206,22 @@ namespace Humanizer public static Humanizer.ByteSize Terabytes(this short input) { } public static Humanizer.ByteSize Terabytes(this uint input) { } public static Humanizer.ByteSize Terabytes(this ushort input) { } + public static Humanizer.ByteSize Yottabytes(this byte input) { } + public static Humanizer.ByteSize Yottabytes(this double input) { } + public static Humanizer.ByteSize Yottabytes(this int input) { } + public static Humanizer.ByteSize Yottabytes(this long input) { } + public static Humanizer.ByteSize Yottabytes(this sbyte input) { } + public static Humanizer.ByteSize Yottabytes(this short input) { } + public static Humanizer.ByteSize Yottabytes(this uint input) { } + public static Humanizer.ByteSize Yottabytes(this ushort input) { } + public static Humanizer.ByteSize Zettabytes(this byte input) { } + public static Humanizer.ByteSize Zettabytes(this double input) { } + public static Humanizer.ByteSize Zettabytes(this int input) { } + public static Humanizer.ByteSize Zettabytes(this long input) { } + public static Humanizer.ByteSize Zettabytes(this sbyte input) { } + public static Humanizer.ByteSize Zettabytes(this short input) { } + public static Humanizer.ByteSize Zettabytes(this uint input) { } + public static Humanizer.ByteSize Zettabytes(this ushort input) { } } public static class CasingExtensions { @@ -176,6 +260,12 @@ namespace Humanizer Megabyte = 3, Gigabyte = 4, Terabyte = 5, + Petabyte = 6, + Exabyte = 7, + Zettabyte = 8, + Yottabyte = 9, + Ronnabyte = 10, + Quettabyte = 11, } public static class DateHumanizeExtensions { diff --git a/src/Humanizer.Tests/Bytes/ArithmeticTests.cs b/src/Humanizer.Tests/Bytes/ArithmeticTests.cs index 4d3f5fe59..169951d24 100644 --- a/src/Humanizer.Tests/Bytes/ArithmeticTests.cs +++ b/src/Humanizer.Tests/Bytes/ArithmeticTests.cs @@ -1,4 +1,4 @@ -public class ArithmeticTests +public class ArithmeticTests { [Fact] public void Add() @@ -86,6 +86,122 @@ public void AddTerabytes() Assert.Equal(4d, size.Terabytes); } + [Fact] + public void AddPetabytes() + { + var size = ByteSize + .FromPetabytes(2) + .AddPetabytes(2); + + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 8, size.Bits); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024, size.Bytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Kilobytes); + Assert.Equal(4d * 1024 * 1024 * 1024, size.Megabytes); + Assert.Equal(4d * 1024 * 1024, size.Gigabytes); + Assert.Equal(4d * 1024, size.Terabytes); + Assert.Equal(4d, size.Petabytes); + } + + [Fact] + public void AddExabytes() + { + var size = ByteSize + .FromExabytes(2) + .AddExabytes(2); + + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 8, size.Bits); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Bytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024, size.Kilobytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Megabytes); + Assert.Equal(4d * 1024 * 1024 * 1024, size.Gigabytes); + Assert.Equal(4d * 1024 * 1024, size.Terabytes); + Assert.Equal(4d * 1024, size.Petabytes); + Assert.Equal(4d, size.Exabytes); + } + + + [Fact] + public void AddZettabytes() + { + var size = ByteSize + .FromZettabytes(2) + .AddZettabytes(2); + + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 8, size.Bits); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Bytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Kilobytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024, size.Megabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Gigabytes); + Assert.Equal(4d * 1024 * 1024 * 1024, size.Terabytes); + Assert.Equal(4d * 1024 * 1024, size.Petabytes); + Assert.Equal(4d * 1024, size.Exabytes); + Assert.Equal(4d, size.Zettabytes); + } + + + [Fact] + public void AddYottabytes() + { + var size = ByteSize + .FromYottabytes(2) + .AddYottabytes(2); + + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 8, size.Bits); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Bytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Kilobytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Megabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024, size.Gigabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Terabytes); + Assert.Equal(4d * 1024 * 1024 * 1024, size.Petabytes); + Assert.Equal(4d * 1024 * 1024, size.Exabytes); + Assert.Equal(4d * 1024, size.Zettabytes); + Assert.Equal(4d, size.Yottabytes); + } + + + [Fact] + public void AddRonnabytes() + { + var size = ByteSize + .FromRonnabytes(2) + .AddRonnabytes(2); + + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 8, size.Bits); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Bytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Kilobytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Megabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Gigabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024, size.Terabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Petabytes); + Assert.Equal(4d * 1024 * 1024 * 1024, size.Exabytes); + Assert.Equal(4d * 1024 * 1024, size.Zettabytes); + Assert.Equal(4d * 1024, size.Yottabytes); + Assert.Equal(4d, size.Ronnabytes); + } + + + [Fact] + public void AddQuettabytes() + { + var size = ByteSize + .FromQuettabytes(2) + .AddQuettabytes(2); + + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 8, size.Bits); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Bytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Kilobytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Megabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Gigabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, size.Terabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 1024, size.Petabytes); + Assert.Equal(4d * 1024 * 1024 * 1024 * 1024, size.Exabytes); + Assert.Equal(4d * 1024 * 1024 * 1024, size.Zettabytes); + Assert.Equal(4d * 1024 * 1024, size.Yottabytes); + Assert.Equal(4d * 1024, size.Ronnabytes); + Assert.Equal(4d, size.Quettabytes); + + } + [Fact] public void Subtract() { diff --git a/src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs b/src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs index 834050129..721e9ddaf 100644 --- a/src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs +++ b/src/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs @@ -1,6 +1,449 @@ -[UseCulture("en")] +using Humanizer; + +[UseCulture("en")] public class ByteSizeExtensionsTests { + [Fact] + public void ByteQuettabytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromQuettabytes(size), size.Quettabytes()); + } + + [Fact] + public void SbyteQuettabytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromQuettabytes(size), size.Quettabytes()); + } + + [Fact] + public void ShortQuettabytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromQuettabytes(size), size.Quettabytes()); + } + + [Fact] + public void UshortQuettabytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromQuettabytes(size), size.Quettabytes()); + } + + [Fact] + public void IntQuettabytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromQuettabytes(size), size.Quettabytes()); + } + + [Fact] + public void UintQuettabytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromQuettabytes(size), size.Quettabytes()); + } + + [Fact] + public void DoubleQuettabytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromQuettabytes(size), size.Quettabytes()); + } + + [Fact] + public void LongQuettabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromQuettabytes(size), size.Quettabytes()); + } + + [Theory] + [InlineData(2, null, "en", "2 QB")] + [InlineData(2, "RB", "en", "2048 RB")] + [InlineData(2.1, null, "en", "2.1 QB")] + [InlineData(2.123, "#.#", "en", "2.1 QB")] + [InlineData(2.1, null, "ru-RU", "2,1 QB")] + [InlineData(2.123, "#.#", "ru-RU", "2,1 QB")] + public void HumanizesQuettabytes(double input, string? format, string cultureName, string expectedValue) + { + var culture = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input + .Quettabytes() + .Humanize(format, culture)); + } + + + [Fact] + public void ByteRonnabytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromRonnabytes(size), size.Ronnabytes()); + } + + [Fact] + public void SbyteRonnabytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromRonnabytes(size), size.Ronnabytes()); + } + + [Fact] + public void ShortRonnabytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromRonnabytes(size), size.Ronnabytes()); + } + + [Fact] + public void UshortRonnabytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromRonnabytes(size), size.Ronnabytes()); + } + + [Fact] + public void IntRonnabytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromRonnabytes(size), size.Ronnabytes()); + } + + [Fact] + public void UintRonnabytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromRonnabytes(size), size.Ronnabytes()); + } + + [Fact] + public void DoubleRonnabytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromRonnabytes(size), size.Ronnabytes()); + } + + [Fact] + public void LongRonnabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromRonnabytes(size), size.Ronnabytes()); + } + + [Theory] + [InlineData(2, null, "en", "2 RB")] + [InlineData(2, "YB", "en", "2048 YB")] + [InlineData(2.1, null, "en", "2.1 RB")] + [InlineData(2.123, "#.#", "en", "2.1 RB")] + [InlineData(2.1, null, "ru-RU", "2,1 RB")] + [InlineData(2.123, "#.#", "ru-RU", "2,1 RB")] + public void HumanizesRonnabytes(double input, string? format, string cultureName, string expectedValue) + { + var culture = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input + .Ronnabytes() + .Humanize(format, culture)); + } + + + [Fact] + public void ByteYottabytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromYottabytes(size), size.Yottabytes()); + } + + [Fact] + public void SbyteYottabytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromYottabytes(size), size.Yottabytes()); + } + + [Fact] + public void ShortYottabytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromYottabytes(size), size.Yottabytes()); + } + + [Fact] + public void UshortYottabytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromYottabytes(size), size.Yottabytes()); + } + + [Fact] + public void IntYottabytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromYottabytes(size), size.Yottabytes()); + } + + [Fact] + public void UintYottabytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromYottabytes(size), size.Yottabytes()); + } + + [Fact] + public void DoubleYottabytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromYottabytes(size), size.Yottabytes()); + } + + [Fact] + public void LongYottabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromYottabytes(size), size.Yottabytes()); + } + + [Theory] + [InlineData(2, null, "en", "2 YB")] + [InlineData(2, null, "fr", "2 Yo")] + [InlineData(2, "ZB", "en", "2048 ZB")] + [InlineData(2.1, null, "en", "2.1 YB")] + [InlineData(2.123, "#.#", "en", "2.1 YB")] + [InlineData(2.1, null, "ru-RU", "2,1 YB")] + [InlineData(2.123, "#.#", "ru-RU", "2,1 YB")] + public void HumanizesYottabytes(double input, string? format, string cultureName, string expectedValue) + { + var culture = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input + .Yottabytes() + .Humanize(format, culture)); + } + + + [Fact] + public void ByteZettabytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromZettabytes(size), size.Zettabytes()); + } + + [Fact] + public void SbyteZettabytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromZettabytes(size), size.Zettabytes()); + } + + [Fact] + public void ShortZettabytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromZettabytes(size), size.Zettabytes()); + } + + [Fact] + public void UshortZettabytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromZettabytes(size), size.Zettabytes()); + } + + [Fact] + public void IntZettabytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromZettabytes(size), size.Zettabytes()); + } + + [Fact] + public void UintZettabytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromZettabytes(size), size.Zettabytes()); + } + + [Fact] + public void DoubleZettabytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromZettabytes(size), size.Zettabytes()); + } + + [Fact] + public void LongZettabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromZettabytes(size), size.Zettabytes()); + } + + [Theory] + [InlineData(2, null, "en", "2 ZB")] + [InlineData(2, null, "fr", "2 Zo")] + [InlineData(2, "EB", "en", "2048 EB")] + [InlineData(2.1, null, "en", "2.1 ZB")] + [InlineData(2.123, "#.#", "en", "2.1 ZB")] + [InlineData(2.1, null, "ru-RU", "2,1 ZB")] + [InlineData(2.123, "#.#", "ru-RU", "2,1 ZB")] + public void HumanizesZettabytes(double input, string? format, string cultureName, string expectedValue) + { + var culture = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input + .Zettabytes() + .Humanize(format, culture)); + } + + + [Fact] + public void ByteExabytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromExabytes(size), size.Exabytes()); + } + + [Fact] + public void SbyteExabytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromExabytes(size), size.Exabytes()); + } + + [Fact] + public void ShortExabytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromExabytes(size), size.Exabytes()); + } + + [Fact] + public void UshortExabytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromExabytes(size), size.Exabytes()); + } + + [Fact] + public void IntExabytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromExabytes(size), size.Exabytes()); + } + + [Fact] + public void UintExabytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromExabytes(size), size.Exabytes()); + } + + [Fact] + public void DoubleExabytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromExabytes(size), size.Exabytes()); + } + + [Fact] + public void LongExabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromExabytes(size), size.Exabytes()); + } + + [Theory] + [InlineData(2, null, "en", "2 EB")] + [InlineData(2, null, "fr", "2 Eo")] + [InlineData(2, "PB", "en", "2048 PB")] + [InlineData(2.1, null, "en", "2.1 EB")] + [InlineData(2.123, "#.#", "en", "2.1 EB")] + [InlineData(2.1, null, "ru-RU", "2,1 EB")] + [InlineData(2.123, "#.#", "ru-RU", "2,1 EB")] + public void HumanizesExabytes(double input, string? format, string cultureName, string expectedValue) + { + var culture = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input + .Exabytes() + .Humanize(format, culture)); + } + + + [Fact] + public void BytePetabytes() + { + const byte size = 2; + Assert.Equal(ByteSize.FromPetabytes(size), size.Petabytes()); + } + + [Fact] + public void SbytePetabytes() + { + const sbyte size = 2; + Assert.Equal(ByteSize.FromPetabytes(size), size.Petabytes()); + } + + [Fact] + public void ShortPetabytes() + { + const short size = 2; + Assert.Equal(ByteSize.FromPetabytes(size), size.Petabytes()); + } + + [Fact] + public void UshortPetabytes() + { + const ushort size = 2; + Assert.Equal(ByteSize.FromPetabytes(size), size.Petabytes()); + } + + [Fact] + public void IntPetabytes() + { + const int size = 2; + Assert.Equal(ByteSize.FromPetabytes(size), size.Petabytes()); + } + + [Fact] + public void UintPetabytes() + { + const uint size = 2; + Assert.Equal(ByteSize.FromPetabytes(size), size.Petabytes()); + } + + [Fact] + public void DoublePetabytes() + { + const double size = 2; + Assert.Equal(ByteSize.FromPetabytes(size), size.Petabytes()); + } + + [Fact] + public void LongPetabytes() + { + const long size = 2; + Assert.Equal(ByteSize.FromPetabytes(size), size.Petabytes()); + } + + [Theory] + [InlineData(2, null, "en", "2 PB")] + [InlineData(2, null, "fr", "2 Po")] + [InlineData(2, "TB", "en", "2048 TB")] + [InlineData(2.1, null, "en", "2.1 PB")] + [InlineData(2.123, "#.#", "en", "2.1 PB")] + [InlineData(2.1, null, "ru-RU", "2,1 PB")] + [InlineData(2.123, "#.#", "ru-RU", "2,1 PB")] + public void HumanizesPetabytes(double input, string? format, string cultureName, string expectedValue) + { + var culture = new CultureInfo(cultureName); + + Assert.Equal(expectedValue, input + .Petabytes() + .Humanize(format, culture)); + } + [Fact] public void ByteTerabytes() { diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index bdbea8f2e..a886d1532 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -21,6 +21,7 @@ //THE SOFTWARE. using System.Diagnostics; +using System.Numerics; using static System.Globalization.NumberStyles; namespace Humanizer; @@ -39,6 +40,13 @@ public struct ByteSize(double byteSize) : public const long BytesInMegabyte = 1048576; public const long BytesInGigabyte = 1073741824; public const long BytesInTerabyte = 1099511627776; + public const long BytesInPetabyte = 1125899906842624; + public const long BytesInExabyte = 1152921504606846976; + public const double BytesInZettabyte = 1180591620717411303424d; + public const double BytesInYottabyte = 1208925819614629174706176d; + public const double BytesInRonnabyte = 1237940039285380274899124224d; + public const double BytesInQuettabyte = 1267650600228229401496703205376d; + public const string BitSymbol = "b"; public const string Bit = "bit"; @@ -52,13 +60,35 @@ public struct ByteSize(double byteSize) : public const string Gigabyte = "gigabyte"; public const string TerabyteSymbol = "TB"; public const string Terabyte = "terabyte"; - - public long Bits { get; } = (long) Math.Ceiling(byteSize * BitsInByte); + public const string PetabyteSymbol = "PB"; + public const string Petabyte = "petabyte"; + public const string ExabyteSymbol = "EB"; + public const string Exabyte = "exabyte"; + public const string ZettabyteSymbol = "ZB"; + public const string Zettabyte = "zettabyte"; + public const string YottabyteSymbol = "YB"; + public const string Yottabyte = "yottabyte"; + public const string RonnabyteSymbol = "RB"; + public const string Ronnabyte = "ronnabyte"; + public const string QuettabyteSymbol = "QB"; + public const string Quettabyte = "quettabyte"; + + + + public double Bits { get; } = (double) Math.Ceiling(byteSize * BitsInByte); public double Bytes { get; } = byteSize; public double Kilobytes { get; } = byteSize / BytesInKilobyte; public double Megabytes { get; } = byteSize / BytesInMegabyte; public double Gigabytes { get; } = byteSize / BytesInGigabyte; public double Terabytes { get; } = byteSize / BytesInTerabyte; + public double Petabytes { get; } = byteSize / BytesInPetabyte; + public double Exabytes { get; } = byteSize / BytesInExabyte; + public double Zettabytes { get; } = byteSize / BytesInZettabyte; + public double Yottabytes { get; } = byteSize / BytesInYottabyte; + public double Ronnabytes { get; } = byteSize / BytesInRonnabyte; + public double Quettabytes { get; } = byteSize / BytesInQuettabyte; + + public string LargestWholeNumberSymbol => GetLargestWholeNumberSymbol(); @@ -67,6 +97,36 @@ public string GetLargestWholeNumberSymbol(IFormatProvider? provider = null) var cultureFormatter = Configurator.GetFormatter(provider as CultureInfo); // Absolute value is used to deal with negative values + if (Math.Abs(Quettabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Quettabyte, Quettabytes, toSymbol: true); + } + + if (Math.Abs(Ronnabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Ronnabyte, Ronnabytes, toSymbol: true); + } + + if (Math.Abs(Yottabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Yottabyte, Yottabytes, toSymbol: true); + } + + if (Math.Abs(Zettabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Zettabyte, Zettabytes, toSymbol: true); + } + + if (Math.Abs(Exabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Exabyte, Exabytes, toSymbol: true); + } + + if (Math.Abs(Petabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Petabyte, Petabytes, toSymbol: true); + } + if (Math.Abs(Terabytes) >= 1) { return cultureFormatter.DataUnitHumanize(DataUnit.Terabyte, Terabytes, toSymbol: true); @@ -102,6 +162,36 @@ public string GetLargestWholeNumberFullWord(IFormatProvider? provider = null) var cultureFormatter = Configurator.GetFormatter(provider as CultureInfo); // Absolute value is used to deal with negative values + if (Math.Abs(Quettabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Quettabyte, Quettabytes, toSymbol: false); + } + + if (Math.Abs(Ronnabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Ronnabyte, Ronnabytes, toSymbol: false); + } + + if (Math.Abs(Yottabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Yottabyte, Yottabytes, toSymbol: false); + } + + if (Math.Abs(Zettabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Zettabyte, Zettabytes, toSymbol: false); + } + + if (Math.Abs(Exabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Exabyte, Exabytes, toSymbol: false); + } + + if (Math.Abs(Petabytes) >= 1) + { + return cultureFormatter.DataUnitHumanize(DataUnit.Petabyte, Petabytes, toSymbol: false); + } + if (Math.Abs(Terabytes) >= 1) { return cultureFormatter.DataUnitHumanize(DataUnit.Terabyte, Terabytes, toSymbol: false); @@ -135,6 +225,36 @@ public double LargestWholeNumberValue get { // Absolute value is used to deal with negative values + if (Math.Abs(Quettabytes) >= 1) + { + return Quettabytes; + } + + if (Math.Abs(Ronnabytes) >= 1) + { + return Ronnabytes; + } + + if (Math.Abs(Yottabytes) >= 1) + { + return Yottabytes; + } + + if (Math.Abs(Zettabytes) >= 1) + { + return Zettabytes; + } + + if (Math.Abs(Exabytes) >= 1) + { + return Exabytes; + } + + if (Math.Abs(Petabytes) >= 1) + { + return Petabytes; + } + if (Math.Abs(Terabytes) >= 1) { return Terabytes; @@ -184,6 +304,25 @@ public static ByteSize FromGigabytes(double value) => public static ByteSize FromTerabytes(double value) => new(value * BytesInTerabyte); + public static ByteSize FromPetabytes(double value) => + new(value * BytesInPetabyte); + + public static ByteSize FromExabytes(double value) => + new(value * BytesInExabyte); + + public static ByteSize FromZettabytes(double value) => + new(value * BytesInZettabyte); + + public static ByteSize FromYottabytes(double value) => + new(value * BytesInYottabyte); + + public static ByteSize FromRonnabytes(double value) => + new(value * BytesInRonnabyte); + + public static ByteSize FromQuettabytes(double value) => + new(value * BytesInQuettabyte); + + /// /// Converts the value of the current ByteSize object to a string. /// The metric prefix symbol (bit, byte, kilo, mega, giga, tera) used is @@ -228,6 +367,43 @@ string ToString(string? format, IFormatProvider? provider, bool toSymbol) var cultureFormatter = Configurator.GetFormatter(provider as CultureInfo); + + if (has(QuettabyteSymbol)) + { + format = format.Replace(QuettabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Quettabyte, Quettabytes, toSymbol)); + return output(Quettabytes); + } + + if (has(RonnabyteSymbol)) + { + format = format.Replace(RonnabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Ronnabyte, Ronnabytes, toSymbol)); + return output(Ronnabytes); + } + + if (has(YottabyteSymbol)) + { + format = format.Replace(YottabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Yottabyte, Yottabytes, toSymbol)); + return output(Yottabytes); + } + + if (has(ZettabyteSymbol)) + { + format = format.Replace(ZettabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Zettabyte, Zettabytes, toSymbol)); + return output(Zettabytes); + } + + if (has(ExabyteSymbol)) + { + format = format.Replace(ExabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Exabyte, Exabytes, toSymbol)); + return output(Exabytes); + } + + if (has(PetabyteSymbol)) + { + format = format.Replace(PetabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Petabyte, Petabytes, toSymbol)); + return output(Petabytes); + } + if (has(TerabyteSymbol)) { format = format.Replace(TerabyteSymbol, cultureFormatter.DataUnitHumanize(DataUnit.Terabyte, Terabytes, toSymbol)); @@ -348,6 +524,24 @@ public ByteSize AddGigabytes(double value) => public ByteSize AddTerabytes(double value) => this + FromTerabytes(value); + public ByteSize AddPetabytes(double value) => + this + FromPetabytes(value); + + public ByteSize AddExabytes(double value) => + this + FromExabytes(value); + + public ByteSize AddZettabytes(double value) => + this + FromZettabytes(value); + + public ByteSize AddYottabytes(double value) => + this + FromYottabytes(value); + + public ByteSize AddRonnabytes(double value) => + this + FromRonnabytes(value); + + public ByteSize AddQuettabytes(double value) => + this + FromQuettabytes(value); + public ByteSize Subtract(ByteSize bs) => new(Bytes - bs.Bytes); @@ -499,6 +693,30 @@ public static bool TryParse(CharSpan s, IFormatProvider? formatProvider, out Byt result = FromTerabytes(number); break; + case PetabyteSymbol: + result = FromPetabytes(number); + break; + + case ExabyteSymbol: + result = FromExabytes(number); + break; + + case ZettabyteSymbol: + result = FromZettabytes(number); + break; + + case YottabyteSymbol: + result = FromYottabytes(number); + break; + + case RonnabyteSymbol: + result = FromRonnabytes(number); + break; + + case QuettabyteSymbol: + result = FromQuettabytes(number); + break; + default: return false; } diff --git a/src/Humanizer/Bytes/ByteSizeExtensions.cs b/src/Humanizer/Bytes/ByteSizeExtensions.cs index d9494604a..d30f2c1cc 100644 --- a/src/Humanizer/Bytes/ByteSizeExtensions.cs +++ b/src/Humanizer/Bytes/ByteSizeExtensions.cs @@ -1,4 +1,4 @@ -// ReSharper disable once CheckNamespace +// ReSharper disable once CheckNamespace namespace Humanizer; /// @@ -288,6 +288,299 @@ public static ByteSize Terabytes(this double input) => public static ByteSize Terabytes(this long input) => ByteSize.FromTerabytes(input); + /// + /// Considers input as petabyte + /// + public static ByteSize Petabytes(this byte input) => + ByteSize.FromPetabytes(input); + + /// + /// Considers input as petabyte + /// + public static ByteSize Petabytes(this sbyte input) => + ByteSize.FromPetabytes(input); + + /// + /// Considers input as petabyte + /// + public static ByteSize Petabytes(this short input) => + ByteSize.FromPetabytes(input); + + /// + /// Considers input as petabyte + /// + public static ByteSize Petabytes(this ushort input) => + ByteSize.FromPetabytes(input); + + /// + /// Considers input as petabyte + /// + public static ByteSize Petabytes(this int input) => + ByteSize.FromPetabytes(input); + + /// + /// Considers input as petabyte + /// + public static ByteSize Petabytes(this uint input) => + ByteSize.FromPetabytes(input); + + /// + /// Considers input as petabyte + /// + public static ByteSize Petabytes(this double input) => + ByteSize.FromPetabytes(input); + + /// + /// Considers input as petabyte + /// + public static ByteSize Petabytes(this long input) => + ByteSize.FromPetabytes(input); + + /// + /// Considers input as exabyte + /// + public static ByteSize Exabytes(this byte input) => + ByteSize.FromExabytes(input); + + /// + /// Considers input as exabyte + /// + public static ByteSize Exabytes(this sbyte input) => + ByteSize.FromExabytes(input); + + /// + /// Considers input as exabyte + /// + public static ByteSize Exabytes(this short input) => + ByteSize.FromExabytes(input); + + /// + /// Considers input as exabyte + /// + public static ByteSize Exabytes(this ushort input) => + ByteSize.FromExabytes(input); + + /// + /// Considers input as exabyte + /// + public static ByteSize Exabytes(this int input) => + ByteSize.FromExabytes(input); + + /// + /// Considers input as exabyte + /// + public static ByteSize Exabytes(this uint input) => + ByteSize.FromExabytes(input); + + /// + /// Considers input as exabyte + /// + public static ByteSize Exabytes(this double input) => + ByteSize.FromExabytes(input); + + /// + /// Considers input as exabyte + /// + public static ByteSize Exabytes(this long input) => + ByteSize.FromExabytes(input); + + + /// + /// Considers input as zettabyte + /// + public static ByteSize Zettabytes(this byte input) => + ByteSize.FromZettabytes(input); + + /// + /// Considers input as zettabyte + /// + public static ByteSize Zettabytes(this sbyte input) => + ByteSize.FromZettabytes(input); + + /// + /// Considers input as zettabyte + /// + public static ByteSize Zettabytes(this short input) => + ByteSize.FromZettabytes(input); + + /// + /// Considers input as zettabyte + /// + public static ByteSize Zettabytes(this ushort input) => + ByteSize.FromZettabytes(input); + + /// + /// Considers input as zettabyte + /// + public static ByteSize Zettabytes(this int input) => + ByteSize.FromZettabytes(input); + + /// + /// Considers input as zettabyte + /// + public static ByteSize Zettabytes(this uint input) => + ByteSize.FromZettabytes(input); + + /// + /// Considers input as zettabyte + /// + public static ByteSize Zettabytes(this double input) => + ByteSize.FromZettabytes(input); + + /// + /// Considers input as zettabyte + /// + public static ByteSize Zettabytes(this long input) => + ByteSize.FromZettabytes(input); + + + /// + /// Considers input as yottabyte + /// + public static ByteSize Yottabytes(this byte input) => + ByteSize.FromYottabytes(input); + + /// + /// Considers input as yottabyte + /// + public static ByteSize Yottabytes(this sbyte input) => + ByteSize.FromYottabytes(input); + + /// + /// Considers input as yottabyte + /// + public static ByteSize Yottabytes(this short input) => + ByteSize.FromYottabytes(input); + + /// + /// Considers input as yottabyte + /// + public static ByteSize Yottabytes(this ushort input) => + ByteSize.FromYottabytes(input); + + /// + /// Considers input as yottabyte + /// + public static ByteSize Yottabytes(this int input) => + ByteSize.FromYottabytes(input); + + /// + /// Considers input as yottabyte + /// + public static ByteSize Yottabytes(this uint input) => + ByteSize.FromYottabytes(input); + + /// + /// Considers input as yottabyte + /// + public static ByteSize Yottabytes(this double input) => + ByteSize.FromYottabytes(input); + + /// + /// Considers input as yottabyte + /// + public static ByteSize Yottabytes(this long input) => + ByteSize.FromYottabytes(input); + + + /// + /// Considers input as ronnabyte + /// + public static ByteSize Ronnabytes(this byte input) => + ByteSize.FromRonnabytes(input); + + /// + /// Considers input as ronnabyte + /// + public static ByteSize Ronnabytes(this sbyte input) => + ByteSize.FromRonnabytes(input); + + /// + /// Considers input as ronnabyte + /// + public static ByteSize Ronnabytes(this short input) => + ByteSize.FromRonnabytes(input); + + /// + /// Considers input as ronnabyte + /// + public static ByteSize Ronnabytes(this ushort input) => + ByteSize.FromRonnabytes(input); + + /// + /// Considers input as ronnabyte + /// + public static ByteSize Ronnabytes(this int input) => + ByteSize.FromRonnabytes(input); + + /// + /// Considers input as ronnabyte + /// + public static ByteSize Ronnabytes(this uint input) => + ByteSize.FromRonnabytes(input); + + /// + /// Considers input as ronnabyte + /// + public static ByteSize Ronnabytes(this double input) => + ByteSize.FromRonnabytes(input); + + /// + /// Considers input as ronnabyte + /// + public static ByteSize Ronnabytes(this long input) => + ByteSize.FromRonnabytes(input); + + + /// + /// Considers input as quettabyte + /// + public static ByteSize Quettabytes(this byte input) => + ByteSize.FromQuettabytes(input); + + /// + /// Considers input as quettabyte + /// + public static ByteSize Quettabytes(this sbyte input) => + ByteSize.FromQuettabytes(input); + + /// + /// Considers input as quettabyte + /// + public static ByteSize Quettabytes(this short input) => + ByteSize.FromQuettabytes(input); + + /// + /// Considers input as quettabyte + /// + public static ByteSize Quettabytes(this ushort input) => + ByteSize.FromQuettabytes(input); + + /// + /// Considers input as quettabyte + /// + public static ByteSize Quettabytes(this int input) => + ByteSize.FromQuettabytes(input); + + /// + /// Considers input as quettabyte + /// + public static ByteSize Quettabytes(this uint input) => + ByteSize.FromQuettabytes(input); + + /// + /// Considers input as quettabyte + /// + public static ByteSize Quettabytes(this double input) => + ByteSize.FromQuettabytes(input); + + /// + /// Considers input as quettabyte + /// + public static ByteSize Quettabytes(this long input) => + ByteSize.FromQuettabytes(input); + + /// /// Turns a byte quantity into human readable form, eg 2 GB /// diff --git a/src/Humanizer/Localisation/DataUnit.cs b/src/Humanizer/Localisation/DataUnit.cs index f336284c9..93f8988ce 100644 --- a/src/Humanizer/Localisation/DataUnit.cs +++ b/src/Humanizer/Localisation/DataUnit.cs @@ -1,4 +1,4 @@ -namespace Humanizer; +namespace Humanizer; public enum DataUnit { @@ -7,5 +7,11 @@ public enum DataUnit Kilobyte, Megabyte, Gigabyte, - Terabyte + Terabyte, + Petabyte, + Exabyte, + Zettabyte, + Yottabyte, + Ronnabyte, + Quettabyte } \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.fr.resx b/src/Humanizer/Properties/Resources.fr.resx index 3b53300d5..21add3c38 100644 --- a/src/Humanizer/Properties/Resources.fr.resx +++ b/src/Humanizer/Properties/Resources.fr.resx @@ -336,6 +336,30 @@ To + + pétaoctet + + + Po + + + exaoctet + + + Eo + + + zettaoctet + + + Zo + + + yottaoctet + + + Yo + ms diff --git a/src/Humanizer/Properties/Resources.resx b/src/Humanizer/Properties/Resources.resx index 87813a734..56dae3053 100644 --- a/src/Humanizer/Properties/Resources.resx +++ b/src/Humanizer/Properties/Resources.resx @@ -582,6 +582,42 @@ TB + + petabyte + + + PB + + + exabyte + + + EB + + + zettabyte + + + ZB + + + yottabyte + + + YB + + + ronnabyte + + + RB + + + quettabyte + + + QB + ms