Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Xotic750 opened this issue Dec 16, 2015 · 3 comments
Closed

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

Xotic750 opened this issue Dec 16, 2015 · 3 comments
Labels
question Issues that look for answers. util Issues and PRs related to the built-in util module.

Comments

@Xotic750
Copy link

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.

@mscdex mscdex added question Issues that look for answers. util Issues and PRs related to the built-in util module. labels Dec 16, 2015
@jasnell
Copy link
Member

jasnell commented Dec 16, 2015

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?

@Xotic750
Copy link
Author

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

@indutny
Copy link
Member

indutny commented Dec 17, 2015

Landed in 04af258, thank you!

Xotic750 added a commit to Xotic750/node that referenced this issue Dec 17, 2015
Re: nodejs#4314
`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".

./configure
make test
Total errors found: 0
cjihrig pushed a commit that referenced this issue Dec 17, 2015
Fix: #4314
PR-URL: #4318
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
scovetta pushed a commit to scovetta/node that referenced this issue Apr 2, 2016
Fix: nodejs#4314
PR-URL: nodejs#4318
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

4 participants