Changing the date format
I wanted to change the date format, next to each release. The default format is yyyy-mm-dd. I looked at conventional-changelog-writer properties and saw that there is a transform method that formats committerDate with yyyy-mm-dd. But because it's a function, I don't really know how am I supposed to hook into it from my .releaserc file.
Looking at the source code of conventional-changelog-writer, the default transform method is
options.transform = _.assign({
hash: function (hash) {
if (_.isString(hash)) {
return hash.substring(0, 7)
}
},
header: function (header) {
return header.substring(0, 100)
},
committerDate: function (date) {
if (!date) {
return
}
return dateFormat(date, 'yyyy-mm-dd', true)
}
}, options.transform)
I tried the following but it fails.
branches:
- master
plugins:
- - "@semantic-release/commit-analyzer"
- preset: conventionalcommits
- - "@semantic-release/release-notes-generator"
- preset: conventionalcommits
writerOpts:
date: dateFormat(new Date(), 'yyyy/mm/dd', true)
transform: |
_.assign({
hash: function (hash) {
if (_.isString(hash)) {
return hash.substring(0, 7)
}
},
header: function (header) {
return header.substring(0, 100)
},
committerDate: function (date) {
if (!date) {
return
}
return dateFormat(date, 'yyyy/mm/dd', true)
}
}, options.transform)
Did you solve your problem?
Currently, my CI builds create the date in the header in the following format: mm/dd/yyyy I don't know why but it seems to be related to the locale settings of the container. On my Mac it is still yyyy-mm-dd.
It would be nice to use a dedicated setting for the format or a hint in the documentation how to handle date format issues.
It seems like date can't be configured at all?
The config value https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#date is outside of the writerOpts.
My config currently produces dates formatted like 2024-2-27 🤷
Edit: Found this function called formatDate https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-writer/src/types/options.ts#L116, unfortunately it is never called...
Edit 2: I ended up using pnpm patch conventional-changelog-writer to fix the formatting.
patches/[email protected]
diff --git a/index.js b/index.js
index 86e5add10bf78569c4e886c7ed3f8554acd80109..fb1d6f6034eaa5a207118a6088b11046fd2dabaa 100644
--- a/index.js
+++ b/index.js
@@ -23,7 +23,7 @@ async function conventionalChangelogWriterInit (context, options) {
context = {
commit: 'commits',
issue: 'issues',
- date: dateFormatter.format(new Date()),
+ date: new Date().toISOString().slice(0, 10),
...context
}
Hi @sac-cas I did not unfortunately, but I agree that a dedicated setting would be a nice addition.