Skip to content

Question: Date formatting in util.js/inspect #4314

Description

@Xotic750

Inspect formats dates in two different ways, depending on whether it has properties or not.

No properties and it uses toString
https://github.com/nodejs/node/blob/master/lib/util.js#L272

The toString() method always returns a string representation of the date in American English.

While when properties are present it uses toUTCString
https://github.com/nodejs/node/blob/master/lib/util.js#L393

The format of the return value may vary according to the platform. The most common return value is a RFC-1123 formatted date stamp, which is a slightly updated version of RFC-822 date stamps.

I am wondering why two different representations are used?

And being 2015, it would seem sensible to use toISOString

The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 characters long: YYYY-MM-DDTHH:mm:ss.sssZ. The timezone is always zero UTC offset, as denoted by the suffix "Z".

Anyway, I look forward to hearing the logic behind the decision and better my understanding.

Activity

  1. added
    questionIssues asking questions about Node.js.
    utilIssues and PRs related to the built-in util module.
    on Dec 16, 2015
  2. jasnell commented on Dec 16, 2015

    @jasnell
    Member

    Good question. That is rather wacky. Personally I'd prefer using the toISOString() but using either the toUTCString to toString methods consistently for both would be good. /cc @nodejs/ctc ... thoughts?

    @Xotic750 ... interested in opening a PR with a possible fix that can be reviewed?

  3. Xotic750 commented on Dec 16, 2015

    @Xotic750
    Author

    I think I could do that, I will go with toISOString for review.

  4. indutny commented on Dec 17, 2015

    @indutny
    Member

    Landed in 04af258, thank you!

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

    questionIssues asking questions about Node.js.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions