From 4b8ea604f048ac4edccff752176bc3d62cbfae76 Mon Sep 17 00:00:00 2001 From: Michiel van Oudheusden Date: Sat, 23 Feb 2019 21:55:26 +0100 Subject: [PATCH 1/2] Add TeraWh --- Common/UnitDefinitions/Energy.json | 4 ++-- .../Quantities/Energy.NetFramework.g.cs | 16 ++++++++++++++++ .../GeneratedCode/UnitAbbreviationsCache.g.cs | 10 ++++++---- UnitsNet/GeneratedCode/Units/EnergyUnit.g.cs | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Common/UnitDefinitions/Energy.json b/Common/UnitDefinitions/Energy.json index c699ae038e..18f2a85f37 100644 --- a/Common/UnitDefinitions/Energy.json +++ b/Common/UnitDefinitions/Energy.json @@ -88,14 +88,14 @@ "PluralName": "WattHours", "FromUnitToBaseFunc": "x*3600d", "FromBaseToUnitFunc": "x/3600d", - "Prefixes": [ "Kilo", "Mega", "Giga" ], + "Prefixes": [ "Kilo", "Mega", "Giga", "Tera" ], "Localization": [ { "Culture": "en-US", "Abbreviations": [ "Wh" ] }, { - "Culture": "en-US", + "Culture": "ru-RU", "Abbreviations": [ "Вт/ч" ] } ] diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs index 45b185b837..e0fff37867 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs @@ -248,6 +248,11 @@ public Energy(double numericValue, EnergyUnit unit) /// public double MegawattHours => As(EnergyUnit.MegawattHour); + /// + /// Get Energy in TerawattHours. + /// + public double TerawattHours => As(EnergyUnit.TerawattHour); + /// /// Get Energy in ThermsEc. /// @@ -460,6 +465,15 @@ public static Energy FromMegawattHours(QuantityValue megawatthours) return new Energy(value, EnergyUnit.MegawattHour); } /// + /// Get Energy from TerawattHours. + /// + /// If value is NaN or Infinity. + public static Energy FromTerawattHours(QuantityValue terawatthours) + { + double value = (double) terawatthours; + return new Energy(value, EnergyUnit.TerawattHour); + } + /// /// Get Energy from ThermsEc. /// /// If value is NaN or Infinity. @@ -871,6 +885,7 @@ private double AsBaseUnit() case EnergyUnit.MegabritishThermalUnit: return (_value*1055.05585262) * 1e6d; case EnergyUnit.Megajoule: return (_value) * 1e6d; case EnergyUnit.MegawattHour: return (_value*3600d) * 1e6d; + case EnergyUnit.TerawattHour: return (_value*3600d) * 1e12d; case EnergyUnit.ThermEc: return _value*1.05505585262e8; case EnergyUnit.ThermImperial: return _value*1.05505585257348e8; case EnergyUnit.ThermUs: return _value*1.054804e8; @@ -907,6 +922,7 @@ private double AsBaseNumericType(EnergyUnit unit) case EnergyUnit.MegabritishThermalUnit: return (baseUnitValue/1055.05585262) / 1e6d; case EnergyUnit.Megajoule: return (baseUnitValue) / 1e6d; case EnergyUnit.MegawattHour: return (baseUnitValue/3600d) / 1e6d; + case EnergyUnit.TerawattHour: return (baseUnitValue/3600d) / 1e12d; case EnergyUnit.ThermEc: return baseUnitValue/1.05505585262e8; case EnergyUnit.ThermImperial: return baseUnitValue/1.05505585257348e8; case EnergyUnit.ThermUs: return baseUnitValue/1.054804e8; diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index 6bf7d0e29a..0c153614e5 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -328,17 +328,19 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(EnergyUnit), (int)EnergyUnit.FootPound, new string[]{"ft·lb"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.GigabritishThermalUnit, new string[]{"GBTU"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.GigawattHour, new string[]{"GWh"}), - ("en-US", typeof(EnergyUnit), (int)EnergyUnit.GigawattHour, new string[]{"GВт/ч"}), + ("ru-RU", typeof(EnergyUnit), (int)EnergyUnit.GigawattHour, new string[]{"GВт/ч"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.Joule, new string[]{"J"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.KilobritishThermalUnit, new string[]{"kBTU"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.Kilocalorie, new string[]{"kcal"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.Kilojoule, new string[]{"kJ"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.KilowattHour, new string[]{"kWh"}), - ("en-US", typeof(EnergyUnit), (int)EnergyUnit.KilowattHour, new string[]{"kВт/ч"}), + ("ru-RU", typeof(EnergyUnit), (int)EnergyUnit.KilowattHour, new string[]{"kВт/ч"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.MegabritishThermalUnit, new string[]{"MBTU"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.Megajoule, new string[]{"MJ"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.MegawattHour, new string[]{"MWh"}), - ("en-US", typeof(EnergyUnit), (int)EnergyUnit.MegawattHour, new string[]{"MВт/ч"}), + ("ru-RU", typeof(EnergyUnit), (int)EnergyUnit.MegawattHour, new string[]{"MВт/ч"}), + ("en-US", typeof(EnergyUnit), (int)EnergyUnit.TerawattHour, new string[]{"TWh"}), + ("ru-RU", typeof(EnergyUnit), (int)EnergyUnit.TerawattHour, new string[]{"TВт/ч"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.ThermEc, new string[]{"th (E.C.)"}), ("ru-RU", typeof(EnergyUnit), (int)EnergyUnit.ThermEc, new string[]{"Европейский терм"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.ThermImperial, new string[]{"th (imp.)"}), @@ -346,7 +348,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(EnergyUnit), (int)EnergyUnit.ThermUs, new string[]{"th (U.S.)"}), ("ru-RU", typeof(EnergyUnit), (int)EnergyUnit.ThermUs, new string[]{"Американский терм"}), ("en-US", typeof(EnergyUnit), (int)EnergyUnit.WattHour, new string[]{"Wh"}), - ("en-US", typeof(EnergyUnit), (int)EnergyUnit.WattHour, new string[]{"Вт/ч"}), + ("ru-RU", typeof(EnergyUnit), (int)EnergyUnit.WattHour, new string[]{"Вт/ч"}), ("en-US", typeof(EntropyUnit), (int)EntropyUnit.CaloriePerKelvin, new string[]{"cal/K"}), ("en-US", typeof(EntropyUnit), (int)EntropyUnit.JoulePerDegreeCelsius, new string[]{"J/C"}), ("en-US", typeof(EntropyUnit), (int)EntropyUnit.JoulePerKelvin, new string[]{"J/K"}), diff --git a/UnitsNet/GeneratedCode/Units/EnergyUnit.g.cs b/UnitsNet/GeneratedCode/Units/EnergyUnit.g.cs index d29480b5e8..a54293d2ea 100644 --- a/UnitsNet/GeneratedCode/Units/EnergyUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/EnergyUnit.g.cs @@ -62,6 +62,7 @@ public enum EnergyUnit MegabritishThermalUnit, Megajoule, MegawattHour, + TerawattHour, ThermEc, ThermImperial, ThermUs, From 5c590e4ba5f7121114784eaefedb22820b2a6965 Mon Sep 17 00:00:00 2001 From: Michiel van Oudheusden Date: Sat, 23 Feb 2019 22:08:55 +0100 Subject: [PATCH 2/2] And the unit test --- UnitsNet.Tests/CustomCode/EnergyTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UnitsNet.Tests/CustomCode/EnergyTests.cs b/UnitsNet.Tests/CustomCode/EnergyTests.cs index 3febc639e3..09807e8df2 100644 --- a/UnitsNet.Tests/CustomCode/EnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/EnergyTests.cs @@ -49,6 +49,8 @@ public class EnergyTests : EnergyTestsBase protected override double ErgsInOneJoule => 10000000; + protected override double TerawattHoursInOneJoule => 2.77777778e-16; + protected override double ThermsEcInOneJoule => 9.4781712031331720001278504447561e-9; protected override double FootPoundsInOneJoule => 0.737562149;