芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/app.optimyar.com/backend/node_modules/react-intl/dist/formatters/dateTime.js
"use strict"; /* * Copyright 2015, Yahoo Inc. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = require("../utils"); var error_1 = require("../error"); var DATE_TIME_FORMAT_OPTIONS = [ 'localeMatcher', 'formatMatcher', 'timeZone', 'hour12', 'weekday', 'era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName', ]; function getFormatter(_a, type, getDateTimeFormat, options) { var locale = _a.locale, formats = _a.formats, onError = _a.onError, timeZone = _a.timeZone; if (options === void 0) { options = {}; } var format = options.format; var defaults = __assign(__assign({}, (timeZone && { timeZone: timeZone })), (format && utils_1.getNamedFormat(formats, type, format, onError))); var filteredOptions = utils_1.filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults); if (type === 'time' && !filteredOptions.hour && !filteredOptions.minute && !filteredOptions.second) { // Add default formatting options if hour, minute, or second isn't defined. filteredOptions = __assign(__assign({}, filteredOptions), { hour: 'numeric', minute: 'numeric' }); } return getDateTimeFormat(locale, filteredOptions); } exports.getFormatter = getFormatter; function formatDate(config, getDateTimeFormat, value, options) { if (options === void 0) { options = {}; } var date = typeof value === 'string' ? new Date(value || 0) : value; try { return getFormatter(config, 'date', getDateTimeFormat, options).format(date); } catch (e) { config.onError(new error_1.ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, 'Error formatting date.', e)); } return String(date); } exports.formatDate = formatDate; function formatTime(config, getDateTimeFormat, value, options) { if (options === void 0) { options = {}; } var date = typeof value === 'string' ? new Date(value || 0) : value; try { return getFormatter(config, 'time', getDateTimeFormat, options).format(date); } catch (e) { config.onError(new error_1.ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, 'Error formatting time.', e)); } return String(date); } exports.formatTime = formatTime; function formatDateToParts(config, getDateTimeFormat, value, options) { if (options === void 0) { options = {}; } var date = typeof value === 'string' ? new Date(value || 0) : value; try { return getFormatter(config, 'date', getDateTimeFormat, options).formatToParts(date); } catch (e) { config.onError(new error_1.ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, 'Error formatting date.', e)); } return []; } exports.formatDateToParts = formatDateToParts; function formatTimeToParts(config, getDateTimeFormat, value, options) { if (options === void 0) { options = {}; } var date = typeof value === 'string' ? new Date(value || 0) : value; try { return getFormatter(config, 'time', getDateTimeFormat, options).formatToParts(date); } catch (e) { config.onError(new error_1.ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, 'Error formatting time.', e)); } return []; } exports.formatTimeToParts = formatTimeToParts;