Skip to content

[API Proposal]: Add GetElapsedTime(long)  #84945

Closed

Description

@tarekgh

Background and motivation

We've added a useful feature called TimeProvider.GetElapsedTime(long startingTimestamp, long endingTimestamp). However, we've identified another frequently used scenario where users want to calculate the elapsed time from the starting timestamp to the current timestamp. To achieve this, users must currently call:

timeProvider.GetElapsedTime(startingTimestamp, timeProvider.GetTimestamp());

To simplify this process, we propose introducing an overload for GetElapsedTime that allows users to simply call timeProvider.GetElapsedTime(startingTimestamp) without having to manually call GetTimestamp() each time they want to calculate the elapsed time.

Also, will be consistent with Stopwatch.GetElapsedTime(system-int64)

API Proposal

namespace System
{
    public abstract class TimeProvider
    {
	    /// <summary>
	    /// Gets the elapsed time since the <paramref name="startingTimestamp"/> value retrieved using <see cref="GetTimestamp"/>.
	    /// </summary>
        public TimeSpan GetElapsedTime(long startingTimestamp)
    }
}

API Usage

long startingTimestamp = timeProvider.GetTimeStamp();

// .... do some work here

TimeSpan timeProvider.GetElapsedTime(startingTimestamp);

Alternative Designs

No response

Risks

No response

Activity

  1. added
    api-suggestion
    on Apr 17, 2023
  2. ghost added
    needs-area-label
    on Apr 17, 2023
  3. added and removed
    needs-area-label
    on Apr 17, 2023
  4. added this to the 8.0.0 milestone on Apr 17, 2023
  5. added
    partner-impact
    on Apr 17, 2023
  6. tarekgh commented on Apr 17, 2023

    @tarekgh
    MemberAuthor
  7. added
    api-ready-for-review
    blocked
    and removed
    api-suggestion
    on Apr 17, 2023
  8. added
    blocking
    and removed
    blocked
    on Apr 17, 2023
  9. bartonjs commented on Apr 18, 2023

    @bartonjs
    Member

    Video

    Looks good as proposed

    namespace System
    {
        public partial class TimeProvider
        {
    	    /// <summary>
    	    /// Gets the elapsed time since the <paramref name="startingTimestamp"/> value retrieved using <see cref="GetTimestamp"/>.
    	    /// </summary>
            public TimeSpan GetElapsedTime(long startingTimestamp)
        }
    }
  10. added
    api-approved
    and removed
    blocking
    api-ready-for-review
    on Apr 18, 2023
  11. ghost added
    in-pr
    on Apr 19, 2023
  12. ghost removed
    in-pr
    on Apr 20, 2023
  13. ghost locked as resolved and limited conversation to collaborators on May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.DateTimepartner-impact

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions