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

Add option to get date in local or specified time zone #11832

Closed
mono0x opened this issue Feb 17, 2019 · 3 comments
Closed

Add option to get date in local or specified time zone #11832

mono0x opened this issue Feb 17, 2019 · 3 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. status: needs more info Needs triaging and reproducible examples or more information to be resolved

Comments

@mono0x
Copy link

mono0x commented Feb 17, 2019

Summary

Add option to get date in local or specified time zone.

Basic example

Add option to date type.

  query blogListQuery($skip: Int!, $limit: Int!) {
    ...
    allMarkdownRemark(...) {
      edges {
        node {
          ...
          frontmatter {
            date(formatString: "MMMM DD, YYYY", local: true) <-- use local time zone
            date(formatString: "MMMM DD, YYYY", tz: "Asia/Tokyo") <-- use specified time zone
          }
        }
      }
    }
  }

and/or add option to gatsby-config.js.

Motivation

Display date in an easy-to-understand way for main readers of the website.

@wardpeet wardpeet added type: feature or enhancement status: needs more info Needs triaging and reproducible examples or more information to be resolved labels Feb 18, 2019
@wardpeet
Copy link
Contributor

Why do you want to do this inside the query and not inside the page or component itself?

@mono0x
Copy link
Author

mono0x commented Feb 18, 2019

Thank you for your comment. I didn't know I can get raw string of the date if formatString is not specified.

I could display date in local time zone using following query and page.

  query blogListQuery($skip: Int!, $limit: Int!) {
    ...
    allMarkdownRemark(...) {
      edges {
        node {
          ...
          frontmatter {
            date
          }
        }
      }
    }
  }
import moment from 'moment'

<small>{moment(node.frontmatter.date).local().format(`MMMM DD, YYYY`)}</small>

Therefore, I think that applying time zone in query is not absolutely necessary. However, if Gatsby supports formatString, it is more natural to be able to specify time zone of formatted time.

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Mar 11, 2019
@gatsbot gatsbot bot closed this as completed Mar 22, 2019
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)
@gatsbyjs gatsbyjs deleted a comment from gatsbot bot Feb 22, 2022
@gatsbyjs gatsbyjs deleted a comment from gatsbot bot Feb 22, 2022
@KyleAMathews
Copy link
Contributor

KyleAMathews commented Feb 22, 2022

Re-opening this as it's a valid use case as if you're displaying dates e.g. for an event, you often know what time zone you want to display and it'd be nice to generate that at build-time vs having to load a library for it. Intl is close to being widely usable ~90% but not quite there https://caniuse.com/?search=intl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. status: needs more info Needs triaging and reproducible examples or more information to be resolved
Projects
None yet
Development

No branches or pull requests

3 participants