@talend/react-forms
Version:
React forms library based on json schema form.
32 lines (31 loc) • 965 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.convertDate = convertDate;
exports.isoStrToDate = isoStrToDate;
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
var _customFormats = require("../../customFormats");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function isoStrToDate(isoStr) {
if (_customFormats.isoDateTimeRegExp.test(isoStr)) {
return new Date(isoStr);
}
return isoStr;
}
function dateToIsoStr(date) {
return date.toISOString();
}
const memorizedDateToIsoStr = (0, _memoizeOne.default)(dateToIsoStr);
function convertDate(value, textInput, schema) {
let converted = value;
if (schema.format === 'iso-datetime') {
converted = memorizedDateToIsoStr(value);
} else if (schema.type === 'number') {
converted = value.getTime();
} else {
converted = textInput;
}
return converted;
}
//# sourceMappingURL=Date.utils.js.map