Skip to content

Roslyn analyzers for bug-prone usage of DateTime/DateTimeOffset #79105

Open
@timmydo

Description

@timmydo

I recently ran into two separate bugs related to time handling in our code and thought roslyn analyzers might be able to assist.

The two instances were:

DateTimeOffset.Parse("2020-01-02").ToString(...)
and
if (DateTimeOffset.TryParse(expiryString, out var expiry) && now < expiry) // expiry is a utc YYYY-MM-DD date

in both of these usages, I should have used something like DateTimeOffset.TryParse(expiryString, null, System.Globalization.DateTimeStyles.AssumeUniversal, out var expiry)

I see this as similar to requiring explicit usage of culture objects in string comparisons. Is there an analyzer that could recommend the version of the function with the explicit default behavior request like we have for string comparison functions?

Semi-related #43956

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions