momocow / semantic-release-gitmoji

✨🐛💥 A semantic-release plugin for gitmojis. Different from conventional changelog, Gitmoji commits are used to determine a release type and generate release notes.
MIT License
91 stars 20 forks source link

Question: how to get the commit date/time? #89

Closed arkadioz closed 10 months ago

arkadioz commented 10 months ago

Is it possible to get the commit date (with time would be great) to use in the handlebar template? Thanks 👍

arkadioz commented 10 months ago

Is it possible to get the commit date (with time would be great) to use in the handlebar template? Thanks 👍

I found in this documentation some different ways to get it https://github.com/semantic-release/semantic-release/blob/master/docs/developer-guide/js-api.md

those ways are: {{author.short}} or {{committer.short}} or {{committerDate}} I am not sure if there is a difference between author and committer, using committerDate, the date comes printed like so: Mon Jan 08 2024 18:31:20 GMT+0000 (Coordinated Universal Time) I wonder if there is a way to format the date? just to be yyyy-mm-dd hh:mm:ss and also how to change the timezone?

arkadioz commented 10 months ago

Okay after some time researching and trying stuff, the solution to format the date is:

add a helper at your releaserc.js config file, for example I add two different ones, the first one just formats but does not change timezone, the second one adjust to the desired timezone:

               helpers: {
                  formatDate: function(date) {
                    return dateFormat(date, 'yyyy-mm-dd HH:MM:ss');
                  },
                  split: function(string) {
                     return string.trim().split('\n');
                  },
                  formatDateAmerica: function(date) {
                   return date.toLocaleString('en-US', { timeZone: 'America/New_York', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }).replace(',', '');
                  }

Then use at the handlebar template like so:

- 📅 Date: {{formatDateAmerica this.committer.date}}

this.commiter.date is just the commit date, im gonna leave open this issue to see if there are better ways or for any feedback, if not lets just close it, thanks

📅 is just the html unicode of the calendar emoji, it would not work with :calendar: so I had to use the unicode

momocow commented 10 months ago

I am not sure if there is a difference between author and committer

FYI:

You may be wondering what the difference is between author and committer. The author is the person who originally wrote the patch, whereas the committer is the person who last applied the patch. So, if you send in a patch to a project and one of the core members applies the patch, both of you get credit — you as the author and the core member as the committer.

Source: https://stackoverflow.com/a/18754896

momocow commented 10 months ago

im gonna leave open this issue to see if there are better ways or for any feedback, if not lets just close it, thanks

@arkadioz LGTM, I'll close this one!