Skip to content

Commit

Permalink
Merge pull request #63 from davidparsson/refactor/remove-date-format
Browse files Browse the repository at this point in the history
Format dates without a dependency
  • Loading branch information
davidparsson authored Apr 19, 2024
2 parents a004867 + cc38417 commit e03b74f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"time-grunt": "^1.2.1"
},
"dependencies": {
"date-format": "4.0.3",
"lodash": "^4.17.21",
"make-dir": "^3.1.0",
"xmlbuilder": "^15.1.1"
Expand Down
2 changes: 1 addition & 1 deletion spec/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('JUnit Report builder', function () {
return result.trim();
};

const reportWith = (content, testSuitesProperties) => '<?xml version="1.0" encoding="UTF-8"?>\n' + content;
const reportWith = (content) => '<?xml version="1.0" encoding="UTF-8"?>\n' + content;

it('should produce a report identical to the expected one', function () {
builder.testCase().className('root.test.Class1');
Expand Down
3 changes: 1 addition & 2 deletions src/test_group.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check
var _ = require('lodash');
var formatDate = require('date-format').asString;
var { TestNode } = require('./test_node');

class TestGroup extends TestNode {
Expand All @@ -20,7 +19,7 @@ class TestGroup extends TestNode {
*/
timestamp(timestamp) {
if (_.isDate(timestamp)) {
this._attributes.timestamp = formatDate('yyyy-MM-ddThh:mm:ss', timestamp);
this._attributes.timestamp = this.formatDate(timestamp);
} else {
this._attributes.timestamp = timestamp;
}
Expand Down
23 changes: 23 additions & 0 deletions src/test_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ class TestNode {
return element;
}

/**
* @protected
* @param {Date} date
* @returns {string}
*/
formatDate(date) {
const pad = (num) => (num < 10 ? '0' : '') + num;

return (
date.getFullYear() +
'-' +
pad(date.getMonth() + 1) +
'-' +
pad(date.getDate()) +
'T' +
pad(date.getHours()) +
':' +
pad(date.getMinutes()) +
':' +
pad(date.getSeconds())
);
}

/**
* @protected
* @param {import('xmlbuilder').XMLElement} element
Expand Down

0 comments on commit e03b74f

Please sign in to comment.