hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.49k stars 4.86k forks source link

Possible dates bug lib/plugins/processor/post.js #3397

Open tcrowe opened 5 years ago

tcrowe commented 5 years ago

In this issue we found that if the user sets timezone: in their _config.yml the date is modified and can be different than what they expect. https://github.com/hexojs/hexo/issues/3365

See this code here: https://github.com/hexojs/hexo/blame/master/lib/plugins/processor/post.js#L78

https://github.com/hexojs/hexo/blame/90b107c8b0bd8b386f64463403391f67eb1b2535/lib/plugins/processor/post.ts#L123

if timezone then change date

I'm not certain if this is a bug or not so I need help to understand.

How to test

1.

hexo init
npm install
hexo new post one
hexo new post two
hexo new post three
hexo serve
  1. View markdown dates and then view post dates in browser

  2. Set timezone: Asia/Shanghai inside ./_config.yml

  3. hexo clean && hexo serve

  4. Repeat 2


If you do that you should notice the same date changes reported in #3365. Is this a bug or should hexo be changing the date relative to GMT or location?

Thanks for taking a look

puremana commented 5 years ago

Was just about to post an issue regarding this, glad to see it's probably because of my timezone (Pacific/Auckland).

A post made on the 19th of November is showing the post.date being 4th of November, all other dates are off too, although most are just off by one.

Here's a link to my repo - https://github.com/puremana/personal-blog Affected post - https://github.com/puremana/personal-blog/blob/master/source/_posts/CORS-And-Hiding-Api-Keys.md

tcrowe commented 5 years ago

@puremana Thank you for adding your experience with this as I am investigating the dates and timezones!

yoshinorin commented 5 years ago

I'm not yet investigate, but #3282 is possibility that same problem.

tcrowe commented 5 years ago

Thank you, @YoshinoriN. I will search for all the places with timezone and see what else it's used for. Then I will make a PR to fix it. It's actually been there since the beginning. lol

tcrowe commented 5 years ago

I tried for a while but I did not come to a solution. I will try again tomorrow.

puremana commented 5 years ago

@tcrowe any luck?

tcrowe commented 5 years ago

No, @puremana. For now all we can do is ask people to disable(comment or delete) the timezone: configuration which will render the dates in the timezone of the machine generating the output source.

When I was looking at the code I couldn't figure out the original intention so I need to think about the implications.

Was it true that if you disable the timezone: that the dates show up as you expect?

puremana commented 5 years ago

Sorry, it turns out timezone doesn't change anything at all in my project, even when it should be. My bug was something else, thanks for all of your help