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

Update date.js #55

Merged
merged 1 commit into from
Aug 15, 2020
Merged

Update date.js #55

merged 1 commit into from
Aug 15, 2020

Conversation

lucasrla
Copy link
Contributor

@lucasrla lucasrla commented Aug 14, 2020

@ganevru, I am experiencing the same described here: #25

This tiny PR isn't the most elegant one, but it does prevent the issue from happening. (Since this is my first PR here, I decided to go as simple as possible.)

A solution to consider in the future (depending on your plans) is to add a timeZone option in siteMetadata (gatsby-config.js) and then parse it appropriately inside date.js.


The root cause of the issue is that in our frontmatters (as per the starters examples) we input dates in the following format:

date: 2020-08-13

When you insert that string into the Date constructor, Date objects are (implicitly) created with 00:00:00 time and UTC as their time zone:

// https://github.com/Chronoblog/gatsby-theme-chronoblog/blob/master/packages/gatsby-theme-chronoblog/src/components/date.js#L14
const newDate = new Date(date);

Then, when you convert the newDate using toLocaleString(language, options) to our local time zones, things can get weird.

Because @reallymello (Florida) and I live in time zones that are UTC-3 (or more) we noticed the issue. All our posts/notes/links are showed in the feed with the frontmatter day minus 1.

I assume you haven't noticed anything on your side because it seems you live in Moscow (which is UTC+3, give or take). Your days are never shifted!


Well, that's a very long explanation for such a tiny PR. 😅

In any case, thanks again for creating this great theme!

Add 'UTC' as a hardcoded timeZone.
@ganevdev ganevdev merged commit c0c3ca8 into Chronoblog:master Aug 15, 2020
@ganevdev
Copy link
Member

Thanks for the detailed explanation, this is a good practice even for small code changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants