"use strict";
/*
 * 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;
var date_fns_1 = require("date-fns");
var datetime_1 = require("@blueprintjs/datetime");
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;
    var hasTimePickerProps = props.timePickerProps !== undefined && Object.keys(props.timePickerProps).length > 0;
    var 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 ? datetime_1.TimePrecision.MINUTE : undefined);
    switch (precision) {
        case datetime_1.TimePrecision.MILLISECOND:
            return exports.DefaultDateFnsFormats.DATE_TIME_MILLISECONDS;
        case datetime_1.TimePrecision.MINUTE:
            return exports.DefaultDateFnsFormats.DATE_TIME_MINUTES;
        case datetime_1.TimePrecision.SECOND:
            return exports.DefaultDateFnsFormats.DATE_TIME_SECONDS;
        default:
            return exports.DefaultDateFnsFormats.DATE_ONLY;
    }
}
exports.getDefaultDateFnsFormat = getDefaultDateFnsFormat;
function getDateFnsFormatter(formatStr, locale) {
    return function (date) { return (0, date_fns_1.format)(date, formatStr, { locale: locale }); };
}
exports.getDateFnsFormatter = getDateFnsFormatter;
function getDateFnsParser(formatStr, locale) {
    return function (str) { return (0, date_fns_1.parse)(str, formatStr, new Date(), { locale: locale }); };
}
exports.getDateFnsParser = getDateFnsParser;
//# sourceMappingURL=dateFnsFormatUtils.js.map