@blueprintjs/datetime
Version:
Components for interacting with dates and times
53 lines • 2.64 kB
JavaScript
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDateFnsParser = exports.getDateFnsFormatter = exports.getDefaultDateFnsFormat = exports.DefaultDateFnsFormats = void 0;
const date_fns_1 = require("date-fns");
const timePrecision_1 = require("./timePrecision");
exports.DefaultDateFnsFormats = {
DATE_ONLY: "yyyy-MM-dd",
DATE_TIME_MILLISECONDS: "yyyy-MM-dd HH:mm:ss.SSS",
DATE_TIME_MINUTES: "yyyy-MM-dd HH:mm",
DATE_TIME_SECONDS: "yyyy-MM-dd HH:mm:ss",
};
function getDefaultDateFnsFormat(props) {
var _a, _b, _c;
const hasTimePickerProps = props.timePickerProps !== undefined && Object.keys(props.timePickerProps).length > 0;
const precision = (_c = (_a = props.timePrecision) !== null && _a !== void 0 ? _a : (_b = props.timePickerProps) === null || _b === void 0 ? void 0 : _b.precision) !== null && _c !== void 0 ? _c :
// if timePickerProps is non-empty but has no precision defined, use the default value of "minute"
(hasTimePickerProps ? timePrecision_1.TimePrecision.MINUTE : undefined);
switch (precision) {
case timePrecision_1.TimePrecision.MILLISECOND:
return exports.DefaultDateFnsFormats.DATE_TIME_MILLISECONDS;
case timePrecision_1.TimePrecision.MINUTE:
return exports.DefaultDateFnsFormats.DATE_TIME_MINUTES;
case timePrecision_1.TimePrecision.SECOND:
return exports.DefaultDateFnsFormats.DATE_TIME_SECONDS;
default:
return exports.DefaultDateFnsFormats.DATE_ONLY;
}
}
exports.getDefaultDateFnsFormat = getDefaultDateFnsFormat;
function getDateFnsFormatter(formatStr, locale) {
return (date) => (0, date_fns_1.format)(date, formatStr, { locale });
}
exports.getDateFnsFormatter = getDateFnsFormatter;
function getDateFnsParser(formatStr, locale) {
return (str) => (0, date_fns_1.parse)(str, formatStr, new Date(), { locale });
}
exports.getDateFnsParser = getDateFnsParser;
//# sourceMappingURL=dateFnsFormatUtils.js.map
;