-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.DateTime
Milestone
Description
Background and motivation
TimeSpan is fundamentally a long, and has most of the semantics of being a long.
Yet, when adding the IMinMaxValue<T>, INumberBase<T> and so on, none of them were applied to TimeSpan.
This prevents making things like Math.Min (if it had an overload that used the new interfaces) work on TimeSpans.
API Proposal
namespace System;
public class TimeSpan
: IComparable,
IComparable<TimeSpan>,
IEquatable<TimeSpan>,
ISpanFormattable,
ISpanParsable<TimeSpan>,
//NEW
IMinMaxValue<TimeSpan>,
IAdditionOperators<TimeSpan, TimeSpan, TimeSpan>,
IAdditiveIdentity<TimeSpan, TimeSpan>,
IEqualityOperators<TimeSpan, TimeSpan, bool>,
ISubtractionOperators<TimeSpan, TimeSpan, TimeSpan>,
IUnaryPlusOperators<TimeSpan, TimeSpan>,
IUnaryNegationOperators<TimeSpan, TimeSpan>,
ISignedNumber<TimeSpan> //<-- problem with this, see below
{
...
}API Usage
var min = Math.Min(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1));Alternative Designs
No response
Risks
A few semantics of the new interfaces does not really make sense for TimeSpan, e.g. TimeSpan can be negative, but the concept of NegativeOne does not really make much sense outside being a unary operator. and for some reason ISignedNumber<T> assumes the entire INumberBase<T> is applicable.
aradalvand, Zintom, madelson, AlgorithmsAreCool, mikhail-khalizev and 18 more
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.DateTime