Skip to content

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

Closed
@Xotic750

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues that look for answers.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