/**
* Why is rendering a Date as a string this complicated?
- * @param {Date|Number} date
+ * We handle the infinities because pg-promise might provide those in
+ * lieu of a Date object from timestamp fields.
+ * @param {Date|Number|String} date
* @param {String=} pInf
* @param {String=} nInf
* @param {String=} otherwise
return nInf;
default:
if (!date
+ || Number.isNaN(date.valueOf())
|| (!(date instanceof Date) && !isDatableType)) {
return otherwise;
}
const result = th.dateFormat(undefined, undefined, undefined, expected);
assert.strictEqual(result, expected);
});
+ it('handles invalid date', function () {
+ const expected = 'otherwise';
+ const result = th.dateFormat(new Date('bad date'), undefined, undefined, expected);
+ assert.strictEqual(result, expected);
+ });
it('renders Infinity', function () {
const expected = 'end of time';
const result = th.dateFormat(Infinity, expected);