Skip to content

Commit

Permalink
Use 'Date.prototype.toUTCString()' to format dates for changelogs
Browse files Browse the repository at this point in the history
- This is done to remove the dependency on the (currently 4 MB large) moment.js
  • Loading branch information
Nils Knappmeier committed Jan 4, 2016
1 parent 63cda43 commit fb33874
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
6 changes: 2 additions & 4 deletions lib/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'use strict'

var qfs = require('q-io/fs')
var moment = require('moment')
var path = require('path')

module.exports = function (cwd) {
Expand All @@ -27,7 +26,6 @@ function Changelog (cwd) {
* @type {String}
*/
this.insertMarker = '<a name="current-release"></a>'
this.momentFormat = 'YYYY-MM-DD'

/**
* A promise for the contents of CHANGELOG.md
Expand All @@ -43,12 +41,12 @@ function Changelog (cwd) {
* This method takes a version, a date and a formatted set of changes
* and returns a combined markdown string of the changes.
* @param version
* @param date
* @param {Date} date
* @param changes
* @returns {*}
*/
this.formatRelease = function (version, date, changes) {
var dateStr = moment(date).format(this.momentFormat)
var dateStr = date.toUTCString()
return `# Version ${version} (${dateStr})\n\n${changes}\n\n`
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"dependencies": {
"commander": "^2.9.0",
"lodash": "^3.10.1",
"moment": "^2.10.6",
"q": "^1.4.1",
"q-io": "^1.13.2",
"semver": "^5.1.0"
Expand Down
4 changes: 2 additions & 2 deletions test/changelog-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('changelog-library:', () => {

describe('the newRelease-method', () => {
it('should add the data of a new release', () => {
var cl = changelog('test').newRelease('1.0.0', new Date(2015, 9, 2, 0, 0, 0, 0), '* [Fix] Test')
var cl = changelog('test').newRelease('1.0.0', new Date('2015-10-02T13:05:00Z'), '* [Fix] Test')
return expect(cl.contents).to.eventually.equal(fixture('changelog-with-a-release.md'))
})
})
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('changelog-library:', () => {
it('should be able to load a CHANGELOG.md and store a modified version', () => {
var changelogContents = qfs.copy('test/fixtures/changelog-with-a-release.md', workDir('CHANGELOG.md'))
.then(() => changelog(workDir())
.newRelease('2.0.0', new Date(2015, 11, 25, 0, 0, 0, 0), '* Change 1\n* Change 2')
.newRelease('2.0.0', new Date('2015-11-25T13:06:00Z'), '* Change 1\n* Change 2')
.save())
.then(() => qfs.read(workDir('CHANGELOG.md')))
return expect(changelogContents).to.eventually.equal(fixture('changelog-with-two-releases.md'))
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/changelog-with-a-release.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release-Notes

<a name="current-release"></a>
# Version 1.0.0 (2015-10-02)
# Version 1.0.0 (Fri, 02 Oct 2015 13:05:00 GMT)

* [Fix] Test
4 changes: 2 additions & 2 deletions test/fixtures/changelog-with-two-releases.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Release-Notes

<a name="current-release"></a>
# Version 2.0.0 (2015-12-25)
# Version 2.0.0 (Wed, 25 Nov 2015 13:06:00 GMT)

* Change 1
* Change 2


# Version 1.0.0 (2015-10-02)
# Version 1.0.0 (Fri, 02 Oct 2015 13:05:00 GMT)

* [Fix] Test

0 comments on commit fb33874

Please sign in to comment.