Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
'use strict';

const moment = require('moment');

const dateRange = (start, end) => {
if (start && end)
if (start && end) {
if (start instanceof Date) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like moment(start).isValid() be more generic.
If we drop moment, than something like this:

const startDate = new Date(start);
if (isNaN(startDate)) throw new Error('Invalid start date`);
const formatedStartDate = helperFormatter(startDate);

start = moment(start).format('YYYY-MM-DD');
}
if (end instanceof Date) {
end = moment(end).format('YYYY-MM-DD');
}
return {
DateRange: {
Start: start,
End: end,
},
};
}

return {};
};
Expand Down