UNPKG

universal-common

Version:

Library that provides useful missing base class library functionality.

208 lines (207 loc) 7.9 kB
/** * Provides functionality to format DateTime instances according to format strings. * This is the main formatting engine that processes custom format patterns. */ export default class DateTimeFormat { static MAX_SECONDS_FRACTION_DIGITS: number; static NULL_OFFSET: number; static ALL_STANDARD_FORMATS: string; static ROUNDTRIP_FORMAT: string; static ROUNDTRIP_DATETIME_UNFIXED: string; static FORMAT_O_MIN_LENGTH: number; static FORMAT_O_MAX_LENGTH: number; static FORMAT_INVARIANT_G_MIN_LENGTH: number; static FORMAT_INVARIANT_G_MAX_LENGTH: number; static FORMAT_R_LENGTH: number; static FORMAT_S_LENGTH: number; static FORMAT_U_LENGTH: number; static FIXED_NUMBER_FORMATS: string[]; static "__#4@#invariantFormatInfo": any; static "__#4@#invariantAbbreviatedMonthNames": string[]; static "__#4@#invariantAbbreviatedDayNames": string[]; /** * Gets the invariant DateTimeFormatInfo instance. * * @type {DateTimeFormatInfo} * @readonly * @static */ static readonly get invariantFormatInfo(): DateTimeFormatInfo; /** * Formats a positive integer with leading zeros. * * @private * @param {number} value - The value to format * @param {number} minimumLength - Minimum length with leading zeros * @returns {string} Formatted number string */ private static "__#4@#formatDigits"; /** * Parses the repeat count of a pattern character. * * @private * @param {string} format - The format string * @param {number} pos - Starting position * @param {string} patternChar - The character to count * @returns {number} Number of consecutive pattern characters */ private static "__#4@#parseRepeatPattern"; /** * Formats day of week name. * * @private * @param {number} dayOfWeek - Day of week (0-6, Sunday=0) * @param {number} repeat - Number of pattern characters * @param {DateTimeFormatInfo} dtfi - Format info * @returns {string} Formatted day name */ private static "__#4@#formatDayOfWeek"; /** * Formats month name. * * @private * @param {number} month - Month (1-12) * @param {number} repeatCount - Number of pattern characters * @param {DateTimeFormatInfo} dtfi - Format info * @returns {string} Formatted month name */ private static "__#4@#formatMonth"; /** * Parses quoted string in format pattern. * * @private * @param {string} format - The format string * @param {number} pos - Position of quote character * @returns {{text: string, length: number}} Parsed text and consumed length */ private static "__#4@#parseQuoteString"; /** * Gets the next character in format string. * * @private * @param {string} format - The format string * @param {number} pos - Current position * @returns {number} Next character code, or -1 if at end */ private static "__#4@#parseNextChar"; /** * Checks if genitive form should be used for month names. * * @private * @param {string} format - The format string * @param {number} index - Current position * @param {number} tokenLen - Length of current token * @param {string} patternToMatch - Pattern to search for (usually 'd') * @returns {boolean} Whether to use genitive form */ private static "__#4@#isUseGenitiveForm"; /** * Formats fractional seconds. * * @private * @param {number} fraction - Fractional part * @param {string} fractionFormat - Format pattern * @returns {string} Formatted fraction */ private static "__#4@#formatFraction"; /** * Formats timezone offset. * * @private * @param {DateTime} dateTime - The datetime * @param {TimeSpan|number} offset - Offset from UTC (or NULL_OFFSET) * @param {number} tokenLen - Length of 'z' pattern * @param {boolean} timeOnly - Whether this is time-only formatting * @returns {string} Formatted timezone */ private static "__#4@#formatCustomizedTimeZone"; /** * Formats roundtrip timezone (K format). * * @private * @param {DateTime} dateTime - The datetime * @param {TimeSpan|number} offset - Offset from UTC (or NULL_OFFSET) * @returns {string} Formatted timezone for roundtrip */ private static "__#4@#formatCustomizedRoundtripTimeZone"; /** * Main formatting method for custom patterns. * * @private * @param {DateTime} dateTime - The datetime to format * @param {string} format - Custom format pattern * @param {DateTimeFormatInfo} dtfi - Format info * @param {TimeSpan|number} offset - Timezone offset (or NULL_OFFSET) * @returns {string} Formatted datetime string */ private static "__#4@#formatCustomized"; /** * Expands standard format character to custom pattern. * * @param {string} format - Single character standard format * @param {DateTimeFormatInfo} dtfi - Format info * @returns {string} Expanded custom pattern */ static expandStandardFormatToCustomPattern(format: string, dtfi: DateTimeFormatInfo): string; /** * Formats DateTime with optional format and provider. * * @param {DateTime} dateTime - DateTime to format * @param {string} [format] - Format string * @param {string} [locale] - Locale string (e.g., 'en-US') * @param {TimeSpan|number} [offset] - Timezone offset * @returns {string} Formatted datetime string */ static format(dateTime: DateTime, format?: string, locale?: string, offset?: TimeSpan | number): string; /** * Checks if DateTime represents time-only for special case formatting. * * @private * @param {DateTime} dateTime - DateTime to check * @param {DateTimeFormatInfo} dtfi - Format info * @returns {boolean} Whether this should be treated as time-only */ private static "__#4@#isTimeOnlySpecialCase"; /** * Formats DateTime with 'O' roundtrip format. * * @param {DateTime} dateTime - DateTime to format * @param {TimeSpan|number} offset - Timezone offset * @returns {string} Formatted string */ static formatO(dateTime: DateTime, offset?: TimeSpan | number): string; /** * Formats DateTime with 'R' RFC1123 format. * * @param {DateTime} dateTime - DateTime to format * @param {TimeSpan|number} offset - Timezone offset * @returns {string} Formatted string */ static formatR(dateTime: DateTime, offset?: TimeSpan | number): string; /** * Formats DateTime with 'S' sortable format. * * @param {DateTime} dateTime - DateTime to format * @returns {string} Formatted string */ static formatS(dateTime: DateTime): string; /** * Formats DateTime with 'U' universal sortable format. * * @param {DateTime} dateTime - DateTime to format * @param {TimeSpan|number} offset - Timezone offset * @returns {string} Formatted string */ static formatU(dateTime: DateTime, offset?: TimeSpan | number): string; /** * Formats DateTime with invariant 'G' format (for performance). * * @param {DateTime} dateTime - DateTime to format * @param {TimeSpan|number} offset - Timezone offset * @returns {string} Formatted string */ static formatInvariantG(dateTime: DateTime, offset?: TimeSpan | number): string; } import DateTimeFormatInfo from "./DateTimeFormatInfo.js"; import DateTime from "./DateTime.js"; import TimeSpan from "./TimeSpan.js";