UNPKG

@harvest-profit/npk

Version:
38 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useValueFormatter = exports.isoDateIncludesTime = void 0; const utils_1 = require("../Calendar/utils"); const isoDateIncludesTime = (value) => { if (`${value}`.includes('T')) return true; return false; }; exports.isoDateIncludesTime = isoDateIncludesTime; const useValueFormatter = (format = 'ISO', includeTime = true) => { let toDateFormatter = (v) => v; let fromDateFormatter = (v) => v; switch (format || 'ISO') { case 'ISO': // We want to strip the time off of the outputted value if the inputted value did not contain // a time. This indicates that the ISO format/attribute we are affecting is date only. toDateFormatter = (v) => (0, utils_1.fromISO)(v); fromDateFormatter = (newValue) => includeTime ? (0, utils_1.toISODateTime)(newValue) : (0, utils_1.toISODate)(newValue); break; case 'timestamp': toDateFormatter = (v) => (0, utils_1.fromTimestamp)(v); fromDateFormatter = (newValue) => (0, utils_1.toTimestamp)(newValue); break; default: break; } const toOutputFormatter = (value, optionalFormat) => { if (optionalFormat === 'ISO') return includeTime ? (0, utils_1.toISODateTime)(value) : (0, utils_1.toISODate)(value); if (optionalFormat === 'timestamp') return (0, utils_1.toTimestamp)(value); return fromDateFormatter(value); }; return { to: toOutputFormatter, from: toDateFormatter }; }; exports.useValueFormatter = useValueFormatter; //# sourceMappingURL=helpers.js.map