-
Notifications
You must be signed in to change notification settings - Fork 384
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
Removing the operators with TimeSpan
in v6?
#1413
Comments
I think it's important that UnitsNet don't add unnecessary friction on this, so if some operator overloads don't work with implicit cast to Duration, then we should add the corresponding TimeSpan overload. |
This was discussed here: #1354 (comment) And implemented here: #1365 |
Yes, this will add 28 additional operators to the current set of units. I tested two ways of doing this:
var timeSpanQuantity = pseudoQuantity with { Name = "TimeSpan" };
relations.AddRange(relations
.Where(r => r.LeftQuantity.Name is "Duration")
.Select(r => r with { LeftQuantity = timeSpanQuantity, LeftUnit = r.LeftUnit with { PluralName = "Total" + r.LeftUnit.PluralName } })
.ToList());
if (relation.RightQuantity.Name is "Duration")
{
Writer.WL($@"
/// <summary>Get <see cref=""{relation.ResultQuantity.Name}""/> from <see cref=""TimeSpan""/> {relation.Operator} <see cref=""{relation.LeftQuantity.Name}""/>.</summary>
public static {relation.ResultQuantity.Name} operator {relation.Operator}(TimeSpan timeSpan, {relation.LeftQuantity.Name} {leftParameter}) => {leftParameter} {relation.Operator} timeSpan;
");
} |
Without fully groking the full context here, I think solution 1 feels natural? |
Nr2 seems the most straight forward though, but I was puzzled by |
Normally, if a quantity (say Power) has a relation with Duration, then Because implicit conversion only works for the right operand, we have to generate However, as we do a similar thing with relations involving |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was automatically closed due to inactivity. |
I just found minor breaking change between v5 and v6 that I don't believe was mentioned anywhere:
The
TimeSpan
overload has been removed (relying on the implicit conversion toDuration
), and while we have the inverse overload inDuration
(i.e.*(Duration duration, MassFlow massFlow)
) the following expression is no longer correctly inferred:Everything is fine if we inverted the order of operations:
I personally don't mind the removal (note that the implicit conversion from
TimeSpan
is lossless in my upcoming proposal for v6), but if we wanted - there would be no particular difficulty in having the operation overload added to theMassFlow.extra.cs
.I assume this affects all multiplications with
TimeSpan
(e.g.VolumeFlow
and such)..The text was updated successfully, but these errors were encountered: