Repository: dotnet/aspnetcore
File: src/Identity/Extensions.Core/src/UserManager.cs (C#)

Code before:
            _metrics?.UpdateUser(typeof(TUser).FullName!, result: null, UserUpdateType.SetTwoFactorEnabled, ex);
            throw;
        }
    }

    /// <summary>
    /// Returns a flag indicating whether the specified <paramref name="user"/> is locked out,
    /// as an asynchronous operation.
    /// </summary>
    /// <param name="user">The user whose locked out status should be retrieved.</param>
    /// <returns>
    /// The <see cref="Task"/> that represents the asynchronous operation, true if the specified <paramref name="user "/>
    /// is locked out, otherwise false.
    /// </returns>
    public virtual async Task<bool> IsLockedOutAsync(TUser user)
    {
        ThrowIfDisposed();
        var store = GetUserLockoutStore();
        ArgumentNullThrowHelper.ThrowIfNull(user);
        if (!await store.GetLockoutEnabledAsync(user, CancellationToken).ConfigureAwait(false))
        {
            return false;
        }
        var lockoutTime = await store.GetLockoutEndDateAsync(user, CancellationToken).ConfigureAwait(false);
#if NET8_0_OR_GREATER
        var utcNow = UtcNow();
#else
        var utcNow = DateTimeOffset.UtcNow;
#endif
        return lockoutTime >= utcNow;
    }

    /// <summary>
    /// Sets a flag indicating whether the specified <paramref name="user"/> can be locked out,
    /// as an asynchronous operation.
    /// </summary>
    /// <param name="user">The user whose locked out status should be set.</param>
    /// <param name="enabled">Flag indicating whether the user can be locked out or not.</param>
    /// <returns>
    /// The <see cref="Task"/> that represents the asynchronous operation, the <see cref="IdentityResult"/> of the operation
    /// </returns>
    public virtual async Task<IdentityResult> SetLockoutEnabledAsync(TUser user, bool enabled)
    {
        try
        {
            ThrowIfDisposed();
            var store = GetUserLockoutStore();
            ArgumentNullThrowHelper.ThrowIfNull(user);

            await store.SetLockoutEnabledAsync(user, enabled, CancellationToken).ConfigureAwait(false);
            return await UpdateUserAndRecordMetricAsync(user, UserUpdateType.SetLockoutEnabled).ConfigureAwait(false);

Review comment (suggestion):
If you made the `#if` just change the behaviour of `UtcNow()` you could do it in just one place and then use the method everywhere.

Code after:
            _metrics?.UpdateUser(typeof(TUser).FullName!, result: null, UserUpdateType.SetTwoFactorEnabled, ex);
            throw;
        }
    }

    /// <summary>
    /// Returns a flag indicating whether the specified <paramref name="user"/> is locked out,
    /// as an asynchronous operation.
    /// </summary>
    /// <param name="user">The user whose locked out status should be retrieved.</param>
    /// <returns>
    /// The <see cref="Task"/> that represents the asynchronous operation, true if the specified <paramref name="user "/>
    /// is locked out, otherwise false.
    /// </returns>
    public virtual async Task<bool> IsLockedOutAsync(TUser user)
    {
        ThrowIfDisposed();
        var store = GetUserLockoutStore();
        ArgumentNullThrowHelper.ThrowIfNull(user);
        if (!await store.GetLockoutEnabledAsync(user, CancellationToken).ConfigureAwait(false))
        {
            return false;
        }
        var lockoutTime = await store.GetLockoutEndDateAsync(user, CancellationToken).ConfigureAwait(false);
        return lockoutTime >= UtcNow();
    }

    /// <summary>
    /// Sets a flag indicating whether the specified <paramref name="user"/> can be locked out,
    /// as an asynchronous operation.
    /// </summary>
    /// <param name="user">The user whose locked out status should be set.</param>
    /// <param name="enabled">Flag indicating whether the user can be locked out or not.</param>
    /// <returns>
    /// The <see cref="Task"/> that represents the asynchronous operation, the <see cref="IdentityResult"/> of the operation
    /// </returns>
    public virtual async Task<IdentityResult> SetLockoutEnabledAsync(TUser user, bool enabled)
    {
        try
        {
            ThrowIfDisposed();
            var store = GetUserLockoutStore();
            ArgumentNullThrowHelper.ThrowIfNull(user);

            await store.SetLockoutEnabledAsync(user, enabled, CancellationToken).ConfigureAwait(false);
            return await UpdateUserAndRecordMetricAsync(user, UserUpdateType.SetLockoutEnabled).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            _metrics?.UpdateUser(typeof(TUser).FullName!, result: null, UserUpdateType.SetLockoutEnabled, ex);
            throw;