Skip to content

Adopt TimeProvider instead of DateTime.UtcNow for testable time handling #1601

Open

Description

@BenjaminMichaelis

The codebase reads DateTime.UtcNow / DateTimeOffset.UtcNow directly in several places, which makes time-dependent behavior (expiry, retention, timestamps) hard to test deterministically.

Proposal: register TimeProvider.System in DI, inject TimeProvider where time is read, and use FakeTimeProvider (Microsoft.Extensions.TimeProvider.Testing) in tests.

Surfaced while reviewing #1267 (reading time tracker).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions