Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operator to convert from TemperatureDelta to TemperatureChangeRate. #1370

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,19 @@ public void TemperatureDeltaTimesEntropyEqualsEnergy()
Energy energy = TemperatureDelta.FromKelvins(20) * Entropy.FromJoulesPerKelvin(4);
Assert.Equal(Energy.FromJoules(80), energy);
}

[Fact]
public void TemperatureDeltaDividedByTimeSpanEqualsTemperatureChangeRate()
{
TemperatureChangeRate changeRate = TemperatureDelta.FromKelvins(20) / TimeSpan.FromSeconds(2);
Assert.Equal(TemperatureChangeRate.FromDegreesCelsiusPerSecond(10), changeRate);
}

[Fact]
public void TemperatureDeltaDividedByDurationEqualsTemperatureChangeRate()
{
TemperatureChangeRate changeRate = TemperatureDelta.FromKelvins(20) / Duration.FromSeconds(2);
Assert.Equal(TemperatureChangeRate.FromDegreesCelsiusPerSecond(10), changeRate);
}
}
}
14 changes: 14 additions & 0 deletions UnitsNet/CustomCode/Quantities/TemperatureDelta.extra.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.

using System;

namespace UnitsNet
{
public partial struct TemperatureDelta
Expand Down Expand Up @@ -40,5 +42,17 @@ public partial struct TemperatureDelta
{
return temperatureDelta.Kelvins * cte.PerKelvin;
}

/// <summary> Get <see cref="TemperatureChangeRate"/> from <see cref="TemperatureDelta"/> divided by <see cref="TimeSpan"/>.</summary>
public static TemperatureChangeRate operator /(TemperatureDelta temperatureDelta, TimeSpan timespan)
{
return TemperatureChangeRate.FromDegreesCelsiusPerSecond(temperatureDelta.Kelvins / timespan.TotalSeconds);
}

/// <summary> Get <see cref="TemperatureChangeRate"/> from <see cref="TemperatureDelta"/> divided by <see cref="Duration"/>.</summary>
public static TemperatureChangeRate operator /(TemperatureDelta temperatureDelta, Duration duration)
{
return TemperatureChangeRate.FromDegreesCelsiusPerSecond(temperatureDelta.Kelvins / duration.Seconds);
}
}
}