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

customize changelog date format? #147

Open
seiyria opened this issue Mar 6, 2018 · 12 comments
Open

customize changelog date format? #147

seiyria opened this issue Mar 6, 2018 · 12 comments

Comments

@seiyria
Copy link

seiyria commented Mar 6, 2018

Instead of DD/MM/YYYY, I'd like to use YYYY-MM-DD. I don't see an option for that.

@phun-ky
Copy link
Contributor

phun-ky commented Mar 7, 2018

@seiyria you can customize your own templates if you are using a configuration file. Best bet might be using a .grenrc.js file with something like this:

    module.exports = {
      "template": {
        "commit": "- [{{message}}]({{url}}) - @{{author}}",
        "issue": "- {{labels}} {{name}} [{{text}}]({{url}})",
        "label": "[**{{label}}**]",
        "noLabel": "closed",
        "group": "\n#### {{heading}}\n",
        "changelogTitle": "# Changelog\n\n",
        "release": function (placeholders) {
          // Here you either set a new date with the desired format based on `placeholders.date`, ie:
          // new Date(placeholders.date).toLocaleDateString("sv-SE");
          // Or you just placeholders.replace(/\./,'-')
          return `## ${placeholders.release}} (${placeholders.date})\n{{body}}`
        },
        "releaseSeparator": "\n---\n\n"
      }
    }

@seiyria
Copy link
Author

seiyria commented Mar 7, 2018 via email

@phun-ky
Copy link
Contributor

phun-ky commented Mar 7, 2018

@seiyria perhaps you are looking for a feature to set the desired date format via options?

Something like this?

{
  "template": {
    "locale": "sv-SE",
    ...
  }
}

@seiyria
Copy link
Author

seiyria commented Mar 7, 2018

Hmm. I'm not sure about setting the locale. In all honesty it'd be nice to use a library like moment.js and just support their date parsing formats, so you could pass in mm/dd/yyyy or yyyy-mm-dd or whatever you wanted. If you wanted to add seconds for the timestamp for example.

@phun-ky
Copy link
Contributor

phun-ky commented Mar 7, 2018

You rarely want to set the date format to anything other than the locale for the application, so why would you? What is the use case for this? You can do what you want, providing you use the correct locale:

new Date(1520452614000).toLocaleDateString('sv-SE')
// Produces 2018-03-07

@phun-ky
Copy link
Contributor

phun-ky commented Mar 7, 2018

But, regardless, I support a feature to specify the date format, either by locale, or template strings

@seiyria
Copy link
Author

seiyria commented Mar 7, 2018 via email

@phun-ky
Copy link
Contributor

phun-ky commented Mar 8, 2018

Yeah, you can use moment.js in that configuration file :)

@seiyria
Copy link
Author

seiyria commented Mar 8, 2018 via email

@harvash
Copy link

harvash commented Feb 11, 2020

Had to play around a little, but got this working with following template. There were a few pieces of @phun-ky code that needed tweaked

module.exports = {
    // NOTE: check if author is present as might be returned as null.
    commit: ({ message, url, author, name }) => `- [${message}](${url}) - ${author ? `@${author}` : name}`,
    issue: '- {{labels}} {{name}} [{{text}}]({{url}})',
    label: '[**{{label}}**]',
    noLabel: 'closed',
    group: '\n#### {{heading}}\n',
    changelogTitle: '# Changelog\n\n',
    template: {
      release: function (placeholders,body) {
        var fDate = new Date(placeholders.date).toLocaleDateString("sv-SE");
        return `## ${placeholders.release} ${fDate}\n${placeholders.body}`
     },
      releaseSeparator: '\n- - - -\n\n'
   }
};

@cjbarth
Copy link
Contributor

cjbarth commented Jan 7, 2021

Honestly, it seems that there should be at least a basic option to use either the locale date or ISO 8601 date, which is the standard.

@cjbarth
Copy link
Contributor

cjbarth commented Jan 9, 2021

@phun-ky I'm interested in adding support for locales and date formatting using the Intl.DateTimeFormat library. Do you have guidance on how you'd like to see that added? It feels like it would be an option, but the way options are set up in this tool, it seems a more natural fit would be a template. In either case, it also feels like it wouldn't be a good fit for _utils.js because options would have to be passed in.

@cjbarth cjbarth mentioned this issue Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants