-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
[API Proposal]: Expose the remaining const values in TimeSpan #94545
Comments
Tagging subscribers to this area: @dotnet/area-system-datetime Issue DetailsBackground and motivationIn the There are also a bunch more that are These values should be exposed publicly on the TimeSpan class. Note: NOT suggesting we expose the truly API Proposalnamespace System.Collections.Generic;
public class TimeSpan: // elided details
{
// more elision
public const long MicrosecondsPerMillisecond = TicksPerMillisecond / TicksPerMicrosecond; // 1,000
public const long MicrosecondsPerSecond = TicksPerSecond / TicksPerMicrosecond; // 1,000,000
public const long MicrosecondsPerMinute = TicksPerMinute / TicksPerMicrosecond; // 60,000,000
public const long MicrosecondsPerHour = TicksPerHour / TicksPerMicrosecond; // 3,600,000,000
public const long MicrosecondsPerDay = TicksPerDay / TicksPerMicrosecond; // 86,400,000,000
public const long MillisecondsPerSecond = TicksPerSecond / TicksPerMillisecond; // 1,000
public const long MillisecondsPerMinute = TicksPerMinute / TicksPerMillisecond; // 60,000
public const long MillisecondsPerHour = TicksPerHour / TicksPerMillisecond; // 3,600,000
public const long MillisecondsPerDay = TicksPerDay / TicksPerMillisecond; // 86,400,000
public const long SecondsPerMinute = TicksPerMinute / TicksPerSecond; // 60
public const long SecondsPerHour = TicksPerHour / TicksPerSecond; // 3,600
public const long SecondsPerDay = TicksPerDay / TicksPerSecond; // 86,400
public const long MinutesPerHour = TicksPerHour / TicksPerMinute; // 60
public const long MinutesPerDay = TicksPerDay / TicksPerMinute; // 1,440
public const long HoursPerDay = TicksPerDay / TicksPerHour; // 24
} API Usageif (TimeSpan.MinutesPerHour * numHours) > TimeSpan.MinutesPerDay * 7)
Console.WriteLine("That's really weeks"); Alternative DesignsN/A RisksSince these are compile-time constant values, there would be no runtime cost in either memory or execution overhead. Additionally they would centralize basic real-world facts to one logical location (TimeSpan).
|
Make the useful constants that TimeSpan has internally declare public because they're rooted in hard reality and not changeable, and quite useful elsewhere. Fixes dotnet#94545
Make the useful constants that TimeSpan has internally declare public because they're rooted in hard reality and not changeable, and quite useful elsewhere. Fixes dotnet#94545
Is this something we can add to the API review? |
CC. @tarekgh, this is a relatively simple ask and I know I've had to redefine such constants myself in personal projects to help with various extension methods or other time related structs used (such as a |
I am fine to proceed with the proposal. I don't have any feedback as the proposal looks good to me as it is. I'll mark this as ready for review. |
Should I reopen the PR or start a new one? :) |
@IDisposable please wait till the issue gets reviewed by the design committee and then we can reopen the PR. Thanks! |
Background and motivation
In the
TimeSpan
class there are a fewpublic const
values that are generally applicable that are usefully exposed.There are also a bunch more that are
internal const
but would be generally useful for other code and are not more implementation driven than the already exposed const values.These values should be exposed publicly on the TimeSpan class.
Note: NOT suggesting we expose the truly
internal const
values that are related toMinTicks
andMaxTicks
. They could be included but are just not as naturally useful elsewhere.API Proposal
API Usage
Alternative Designs
N/A
Risks
Since these are compile-time constant values, there would be no runtime cost in either memory or execution overhead. Additionally they would centralize basic real-world facts to one logical location (TimeSpan).
The text was updated successfully, but these errors were encountered: