Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Events dates are off by one day when running locally #17

Closed
sebsto opened this issue May 4, 2019 · 10 comments · Fixed by #298
Closed

Events dates are off by one day when running locally #17

sebsto opened this issue May 4, 2019 · 10 comments · Fixed by #298
Assignees
Labels
bug Something isn't working

Comments

@sebsto
Copy link

sebsto commented May 4, 2019

When running the web site locally, all events are off by one day.
I guess this is a due to a local timezone, my laptop is running in

Central European Summer Time
Time zone in Paris, France (GMT+2) 

Here is a screenshot of the hosted version :
image

Here is a screenshot of my local version :
image

@harrysolovay
Copy link
Contributor

@sebsto thank you for calling attention to this. We'll hopefully be able to internationalize soon. Incase you wanted to take a crack at it, a PR would be tremendous (& if not, no worries 👍 ).

Any library recommendations? react-intl and react-i18next seem to be popular solutions. It would be great to hear your thoughts.

Thanks again for submitting this issue!

@harrysolovay
Copy link
Contributor

@sebsto I'm curious if you're still running into this problem––seems like the problem was in part caused by the way newsletters were being generated. We re-created the generation mechanism last week. Hoping this is now resolved.

@sebsto
Copy link
Author

sebsto commented May 31, 2019

Thanks for getting back to me. Yes, I still observe the same with latest code in master branch.
Here are two screenshots. First from local version and second from hosted version.
Screenshot 2019-05-31 at 10 17 11
Screenshot 2019-05-31 at 10 17 17

I am on Mac OS X 10.14.5
I don't have any TZ related env variable set
I just have LANG=en_GB.UTF-8

$ date +%z
+0200

Note that I also tested on a Cloud9 machine running in Ireland (TZ=GMT) and it works correctly. Problems seems only with TZ > GMT

@sebsto
Copy link
Author

sebsto commented May 31, 2019

I changed my Cloud9 machine's TZ (following instructions at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html)

$ date 
Fri May 31 12:00:52 CEST 2019

$ date +%z
+0200

And can reproduce the problem.
image

So, it is pretty easy for you to reproduce, just spawn a Cloud9 or EC2 instance, change the timezone and voila ! :-)

@harrysolovay
Copy link
Contributor

@sebsto this is extremely helpful. Will get back to you about this soon.

@sebsto
Copy link
Author

sebsto commented Jun 1, 2019

I am trying to nail down the root cause, but I am new to Gatsby and I am slow on this :-)
Looks like the data returned the Gatsby GraphQL API is incorrect. So I think this is not a rendering issue as I initially supposed, but the root cause lies probably in the module (a Gatsby module?) that reads the Markdown and exposes it through GraphQL.

Here is my GraphQL query executed in GraphiQL :

fragment Contributor on MarkdownRemark {
    fields {
      key
      slug
    }
    frontmatter {
      name
      bio
      github
      twitter
      website
    }
  }
  
  fragment SharedBetweenPostsAndEvents on MarkdownRemark {
    fields {
      key
      slug
      date(formatString: "MMMM D, YYYY")
    }
    frontmatter {
      href
      title
      description
      tags
    }
  }

fragment Event on MarkdownRemark {
    ...SharedBetweenPostsAndEvents
    fields {
      attendants {
        ...Contributor
      }
    }
    frontmatter {
      city
      country
    }
  }
 
  query($currentDate: Date!) {
    allMarkdownRemark(
      sort: {fields: [fields___date], order: ASC}
      filter: {fields: {category: {eq: "events"}, date: {gt: $currentDate}}}
    ) {
      edges {
        node {
          ...Event
          frontmatter {
            platforms
          }
        }
      }
    }
  }

with

{ "currentDate": "2019-06-01" }

And here is a result extract :

{
          "node": {
            "fields": {
              "key": "uActwvwBgN5",
              "slug": "events/2019/06/11/devdays",
              "date": "June 10, 2019",
              "attendants": [
                {
                  "fields": {
                    "key": "2vIVgGdj121",
                    "slug": "contributors/sebastien-stormacq"
                  },
                  "frontmatter": {
                    "name": "Sébastien Stormacq",
                    "bio": "Technical Evangelist @ AWS France.  Talk about frontend, serverless and identity.  https://stormacq.com",
                    "github": "sebsto",
                    "twitter": "sebsto",
                    "website": null
                  }
                }
              ]
            }

As you can see :

"slug": "events/2019/06/11/devdays",
"date": "June 10, 2019",

The directory name is correctly parsed as 2019/06/11 but the date returned is 2019/06/10

@sebsto
Copy link
Author

sebsto commented Jun 1, 2019

BTW, I don't think it is related, but most of the onCreateNode code is never executed because this condition is always false https://github.com/aws-amplify/community/blob/master/gatsby-node/onCreateNode.js#L13 It looks like the whole onCreateNode code is not used and can safely be removed from https://github.com/aws-amplify/community/blob/master/gatsby-node/constants.js#L4 without any visible effect on the rendering. Is this correct ?

But the date received here is already incorrect :

"context": {
    "slug": "events/2019/07/26/addc",
    "date": "2019-07-25T22:00:00.000Z"
  },

@sammartinez sammartinez added the bug Something isn't working label Jun 28, 2019
@harrysolovay
Copy link
Contributor

harrysolovay commented Jun 28, 2019

@sebsto I don't believe so; node.internal.type === 'MarkdownRemark' is often true... can you please describe the problem another way?––I don't think I understand.

Also, in regards to the timezone problem, the solution would probably be to generate many builds for different time zones and feed them up depending on the client. This could be tough to implement. I can't find pre-existing conversations about this problem in Gatsby projects. Feels like a problem with the build paradigm itself. Any other ideas on how we might be able to solve this issue without doing anything at runtime?

@sebsto
Copy link
Author

sebsto commented Jun 29, 2019

Regarding the date : Gatsby is returning an incorrect date. It takes the date from the slug : 2019-07-26) in this example. It considers the time as being 00:00am GMT. Then it applies the timezone conversion according to client's timezone (for me GMT+2) to calculate the GMT / Zulu time (so minus 2h in this example), which produce a date 2h before the previous day (2019-07-25 22:00 Zulu time)

"context": {
    "slug": "events/2019/07/26/addc",
    "date": "2019-07-25T22:00:00.000Z"
  },

When the build machine has a local TZ in GMT, the problem does not appear. This is why the public web site is correct.

I would suggest to modify the Gatsby module to not make that time conversion. But this is potentially a breaking change for other Gatsby apps.

I don't like the idea to generate multiple builds, for each different timezone (24 !) The design best practice is to store time in Zulu time and display in local time to the client app. TZ rendering should be a front end issue. Ideally, Gastby must return the GMT time and we should have client side code to convert it to local or not.

Regarding this use case, we can safely assume that event organisers are always going to give the date of their event / conference in local time and people interested to attend the conference are only interested by local time only. So if Gatsby returns whatever the event organiser entered, without conversion, we will be good.

@harrysolovay
Copy link
Contributor

@sebsto good call & agreed. Thank you for the deep dive! Will fix this asap.

watilde added a commit to watilde/amplify-community that referenced this issue Oct 24, 2020
Gatsby converts stored date to UTC cases the reported
dates shifts. This patch is to shows stored date as-is and
format date in UI side which is known as a workaround.

Fixes: aws-amplify#17
Refs: gatsbyjs/gatsby#11832 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants