Skip to content
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
7 changes: 7 additions & 0 deletions UnitsNet.Tests/CustomCode/DurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,12 @@ public void DurationTimesAcceleration()
Speed speed = Duration.FromSeconds(10) * Acceleration.FromMetersPerSecondSquared(10);
Assert.Equal(Speed.FromMetersPerSecond(100), speed);
}

[Fact]
public void DurationTimesForceChangeRate()
{
Force force = Duration.FromSeconds(10) * ForceChangeRate.FromNewtonsPerSecond(100);
Assert.Equal(Force.FromNewtons(1000), force);
}
}
}
9 changes: 9 additions & 0 deletions UnitsNet.Tests/CustomCode/ForceChangeRateTests.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 (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using Xunit;

namespace UnitsNet.Tests.CustomCode
{
public class ForceChangeRateTests : ForceChangeRateTestsBase
Expand All @@ -21,5 +23,12 @@ public class ForceChangeRateTests : ForceChangeRateTestsBase
protected override double MillinewtonsPerSecondInOneNewtonPerSecond => 1E3;
protected override double MicronewtonsPerSecondInOneNewtonPerSecond => 1E6;
protected override double NanonewtonsPerSecondInOneNewtonPerSecond => 1E9;

[Fact]
public void DurationTimesForceChangeRate()
{
Force force = ForceChangeRate.FromNewtonsPerSecond(100) * Duration.FromSeconds(10);
Assert.Equal(Force.FromNewtons(1000), force);
}
}
}
7 changes: 7 additions & 0 deletions UnitsNet.Tests/CustomCode/ForceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,12 @@ public void ForceTimesReciprocalAreaEqualsPressure()
Pressure pressure = Force.FromNewtons(2) * ReciprocalArea.FromInverseSquareMeters(25);
Assert.Equal(pressure, Pressure.FromNewtonsPerSquareMeter(50));
}

[Fact]
public void ForceDividedByForceChangeRateEqualsDuration()
{
Duration duration = Force.FromNewtons(200) / ForceChangeRate.FromNewtonsPerSecond(50);
Assert.Equal(duration, Duration.FromSeconds(4));
}
}
}
17 changes: 11 additions & 6 deletions UnitsNet/CustomCode/Quantities/Duration.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using System;
using UnitsNet.Units;

namespace UnitsNet
{
Expand Down Expand Up @@ -92,24 +93,28 @@ public static explicit operator Duration(TimeSpan duration)
return timeSpan.TotalSeconds >= duration.Seconds;
}

/// <summary>Get <see cref="Volume"/> from <see cref="Duration"/> times <see cref="VolumeFlow"/>.</summary>
/// <summary>Get <see cref="Volume"/> from <see cref="Duration"/> multiplied by <see cref="VolumeFlow"/>.</summary>
public static Volume operator *(Duration duration, VolumeFlow volumeFlow)
{
return Volume.FromCubicMeters(volumeFlow.CubicMetersPerSecond * duration.Seconds);
}

/// <summary>Calculate <see cref="ElectricCharge"/> from <see cref="Duration"/> multiplied by <see cref="ElectricCurrent"/>.</summary>
/// <summary>Get <see cref="ElectricCharge"/> from <see cref="Duration"/> multiplied by <see cref="ElectricCurrent"/>.</summary>
public static ElectricCharge operator *(Duration time, ElectricCurrent current)
{
return ElectricCharge.FromAmpereHours(current.Amperes * time.Hours);
}

/// <summary>
/// Multiply <see cref="Duration"/> and <see cref="Acceleration"/> to get <see cref="Speed"/>.
/// </summary>
/// <summary>Get <see cref="Speed"/> from <see cref="Duration"/> multiplied by <see cref="Acceleration"/>.</summary>
public static Speed operator *(Duration duration, Acceleration acceleration)
{
return new Speed(acceleration.MetersPerSecondSquared * duration.Seconds, UnitsNet.Units.SpeedUnit.MeterPerSecond);
return new Speed(acceleration.MetersPerSecondSquared * duration.Seconds, SpeedUnit.MeterPerSecond);
}

/// <summary>Get <see cref="Force"/> from <see cref="Duration"/> multiplied by <see cref="ForceChangeRate"/>.</summary>
public static Force operator *(Duration duration, ForceChangeRate forceChangeRate)
{
return new Force(forceChangeRate.NewtonsPerSecond * duration.Seconds, ForceUnit.Newton);
}
}
}
6 changes: 6 additions & 0 deletions UnitsNet/CustomCode/Quantities/Force.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@ public static Force FromMassByAcceleration(Mass mass, Acceleration acceleration)
{
return ForcePerLength.FromNewtonsPerMeter(force.Newtons / length.Meters);
}

/// <summary>Get <see cref="Duration"/> from <see cref="Force"/> divided by <see cref="ForceChangeRate"/>.</summary>
public static Duration operator /(Force force, ForceChangeRate forceChangeRate)
{
return new Duration(force.Newtons / forceChangeRate.NewtonsPerSecond, DurationUnit.Second);
}
}
}
16 changes: 16 additions & 0 deletions UnitsNet/CustomCode/Quantities/ForceChangeRate.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using UnitsNet.Units;

namespace UnitsNet
{
public partial struct ForceChangeRate
{
/// <summary>Get <see cref="Force"/> from <see cref="ForcePerLength"/> multiplied by <see cref="Length"/>.</summary>
public static Force operator *(ForceChangeRate forceChangeRate, Duration duration)
{
return new Force(forceChangeRate.NewtonsPerSecond * duration.Seconds, ForceUnit.Newton);
}
}
}