UNPKG

@phensley/cldr-core

Version:
109 lines (108 loc) 4.19 kB
import { CalendarSchema } from '@phensley/cldr-schema'; import { Internals } from '../../internals'; import { Bundle } from '../../resource'; import { DatePatternMatcher, DateSkeleton, DateSkeletonParser } from './skeleton'; import { DateTimeNode } from '../../parsing/patterns/date'; import { CalendarDate } from '../../systems/calendars'; import { LRU } from '../../utils/lru'; export interface CachedSkeletonRequest { dateSkel?: DateSkeleton; timeSkel?: DateSkeleton; date?: DateTimeNode[]; time?: DateTimeNode[]; } export interface CachedIntervalRequest { date?: DateTimeNode[]; range?: DateTimeNode[]; skeleton?: string; } export declare type StandaloneFieldType = 'dayPeriods' | 'months' | 'quarters' | 'weekdays'; /** * Caches all available date formatting patterns for a given calendar schema. * We must cache all available skeletons in order to perform best-fit matching * to a given input skeleton. We also need to cache the standard date and time * patterns for use in best-fit matching. */ export declare class CalendarPatterns { readonly bundle: Bundle; readonly internals: Internals; readonly schema: CalendarSchema; readonly cacheSize: number; protected language: string; protected region: string; protected namesCache: LRU<string, { [x: string]: { [y: string]: string; }; }>; protected skeletonParser: DateSkeletonParser; protected skeletonRequestCache: LRU<string, CachedSkeletonRequest>; protected intervalRequestCache: LRU<string, CachedIntervalRequest>; protected dateFormats: { [x: string]: string; }; protected timeFormats: { [x: string]: string; }; protected wrapperFormats: { [x: string]: string; }; protected availableMatcher: DatePatternMatcher; protected intervalMatcher: { [x: string]: DatePatternMatcher; }; protected rawAvailableFormats: { [x: string]: { [y: string]: string; }; }; protected rawIntervalFormats: { [x: string]: { [y: string]: string; }; }; protected intervalFallback: string; constructor(bundle: Bundle, internals: Internals, schema: CalendarSchema, cacheSize?: number); dayPeriods(): { [x: string]: string; }; months(): { [x: string]: string; }; weekdays(): { [x: string]: string; }; quarters(): { [x: string]: string; }; _getStandalone(key: StandaloneFieldType, width: string): { [x: string]: string; }; parseSkeleton(raw: string): DateSkeleton; getDatePattern(width: string): DateTimeNode[]; getTimePattern(width: string): DateTimeNode[]; getCachedSkeletonRequest(key: string): CachedSkeletonRequest | undefined; setCachedSkeletonRequest(key: string, req: CachedSkeletonRequest): void; getCachedIntervalRequest(key: string): CachedIntervalRequest | undefined; setCachedIntervalRequest(key: string, req: CachedIntervalRequest): void; getWrapperPattern(width: string): string; getAvailablePattern(d: CalendarDate, s: DateSkeleton): DateTimeNode[]; getIntervalPattern(field: string, skeleton: string): DateTimeNode[]; getIntervalFallback(): string; adjustPattern(pattern: DateTimeNode[], skeleton: DateSkeleton, decimal?: string): DateTimeNode[]; matchAvailable(skeleton: DateSkeleton): DateSkeleton; matchInterval(skeleton: DateSkeleton, field: string): DateSkeleton; protected buildSkeletonParser(): DateSkeletonParser; protected buildAvailableMatcher(): void; protected buildIntervalMatcher(): void; protected getTimeData(): [string, string]; } export declare class GregorianPatterns extends CalendarPatterns { /** * Apply pluralization rules to select a skeleton pattern. Note: this is slightly * future-proofing since at the time of this writing these patterns don't actually * differ based on the plural category. This is here so the design has a chance of * supporting pluralization of skeleton patterns in the future. */ getAvailablePattern(d: CalendarDate, s: DateSkeleton): DateTimeNode[]; }