Skip to content

Recommend using DateTime.timestamp() over DateTime.now().toUtc() #60786

Open
@Mr-Pepe

Description

@Mr-Pepe

From my understanding, DateTime.timestamp() does the same as DateTime.now().toUtc(). One of my codebases contains a lot of the latter because I did not know that the former existed. In all cases, I actually needed a timestamp and was sometimes worried that I'd forget the toUtc().

A quick GitHub code search yielded 12k results for DateTime.now().toUtc() and in most of those cases DateTime.timestamp() would be the better alternative.

Is this worth a lint rule? Having this rule would make DateTime.timestamp() more discoverable for developers, potentially preventing bugs where devs forget a toUtc() after DateTime.now().

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-uxA user experience or user interface related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions