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

Language format for the date in GraphQL #3529

Closed
MaralS opened this issue Jan 15, 2018 · 2 comments
Closed

Language format for the date in GraphQL #3529

MaralS opened this issue Jan 15, 2018 · 2 comments

Comments

@MaralS
Copy link

MaralS commented Jan 15, 2018

Description

For a client, I'm using this amazing framework to build a fast web app. However, I'm beginning with GraphQL. I noticed that the date is formatted to display months in English. I wanted to know which parameters is necessary to display the date in french.

Environment

Gatsby version: 1.1.27
Node.js version: 8.9.3
Operating System: OS X El Capitan 10.11.6

File contents (if changed):

gatsby-node.js:

const path = require('path');

exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators;

const blogPostTemplate = path.resolve(`src/templates/blog-post.js`);

return graphql(`{
allMarkdownRemark(
  sort: { order: DESC, fields: [frontmatter___date] }
  limit: 1000
) {
  edges {
    node {
      excerpt(pruneLength: 250)
      html
      id
      frontmatter {
        date
        path
        title
      
      }
    }
  }
}

}`)
.then(result => {
if (result.errors) {
return Promise.reject(result.errors);
}

        result.data.allMarkdownRemark.edges
            .forEach(({ node }) => {
                createPage({
                    path: node.frontmatter.path,
                    component: blogPostTemplate,
                    context: {} // additional data can be passed via context
                });
            });
    });

}

GraphQL Query :

export const pageQuery = graphql`

query BlogPostByPath($path: String!) {
markdownRemark(frontmatter: { path: { eq: $path } }) {
html
frontmatter {
date(formatString: "DD/MM/YYYY")
path
title

    image{
      childImageSharp{
        sizes(maxWidth: 1000, quality: 100, cropFocus: CENTER, toFormat: JPG) {
            ...GatsbyImageSharpSizes
        }
        responsiveSizes(quality: 70){
          src
          srcSet
        }
      }
    }
  }
}

}
`;

Actual result

I just have the month date like DD/MM/YYYY with numbers like 12/05/2017.

Expected behavior

I wanted to show the date like : 12 mai 2017

Thank you in advance for your help,

kind regards,

Maral.

@KyleAMathews
Copy link
Contributor

The GraphQL date field takes an optional locale argument for modifying how the date is formatted #2652

Good luck with the client site!

@derozan10
Copy link

Is it possible to show how to get this working on my example? I'm trying to sort on the "datumString"which has a format like "01-12-2018" (first of december, 2018).

{
  allThirdPartyClubwedstrijden(
    sort: {fields: datumString, order: ASC}
    filter: {
      uitslag: {eq: ""}
      datumString: {ne: null}
    }
    limit: 5
  ){
    edges {
      node {
        datumString
        tTNaam
        tUNaam
        uitslag
        beginTijd
      }
    }
  }
}

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

No branches or pull requests

3 participants