github-tools / github-release-notes

Node module to create a release or a changelog from a tag and uses issues or commits to creating the release notes.
https://github-tools.github.io/github-release-notes/
GNU General Public License v3.0
884 stars 325 forks source link

customize changelog date format? #147

Open seiyria opened 6 years ago

seiyria commented 6 years ago

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

phun-ky commented 6 years ago

@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 commented 6 years ago

Ah. I see. Thanks. I was hoping there's be a way to do it from a yml config file instead (just to keep all of my configs in the same format).

On Wed, Mar 7, 2018, 13:26 Alexander Vassbotn Røyne-Helgesen < notifications@github.com> wrote:

@seiyria https://github.com/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().toLocaleDateString("sv-SE");
      // Or you just placeholders.replace(/\./,'-')
      return `## ${placeholders.release}} (${placeholders.date})\n{{body}}`
    },
    "releaseSeparator": "\n---\n\n"
  }
}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github-tools/github-release-notes/issues/147#issuecomment-371254441, or mute the thread https://github.com/notifications/unsubscribe-auth/AAum2TmjyQ-QkO1cgGu2uy7Nfnz9Axqxks5tcDQFgaJpZM4SfKqe .

phun-ky commented 6 years ago

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

Something like this?

{
  "template": {
    "locale": "sv-SE",
    ...
  }
}
seiyria commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

seiyria commented 6 years ago

Well, I stated my use case: changing the format of the date. I had no idea that sv-SE formatted dates like that and that's not the first thing I'd think of when trying to format a date. However, if that is how it would be configured then that's fine.

On Wed, Mar 7, 2018, 14:00 Alexander Vassbotn Røyne-Helgesen < notifications@github.com> wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github-tools/github-release-notes/issues/147#issuecomment-371265491, or mute the thread https://github.com/notifications/unsubscribe-auth/AAum2V_UkTuybtwueSqDtlGbtoCE5IyWks5tcDxwgaJpZM4SfKqe .

phun-ky commented 6 years ago

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

seiyria commented 6 years ago

Right, but I'd have to change formats. I'd prefer an option to set instead of changing my config file to have code.

On Thu, Mar 8, 2018, 02:53 Alexander Vassbotn Røyne-Helgesen < notifications@github.com> wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github-tools/github-release-notes/issues/147#issuecomment-371421476, or mute the thread https://github.com/notifications/unsubscribe-auth/AAum2aEvNzHG6FTEGJP9VRnGqxvL8VAfks5tcPFBgaJpZM4SfKqe .

harvash commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

@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.