@phensley/cldr-core
Version:
Core library for @phensley/cldr
130 lines (129 loc) • 4.41 kB
TypeScript
import { DateTimePatternFieldType, MetaZoneType } from '@phensley/cldr-schema';
import { ZoneInfo } from './timezone';
export declare type CalendarType = 'buddhist' | 'gregory' | 'iso8601' | 'japanese' | 'persian';
export declare type CalendarFromUnixEpoch<T> = (epoch: number, zoneId: string, firstDay: number, minDays: number) => T;
/**
* Generic structure used to add one or more fields to a date.
*/
export interface CalendarDateFields {
year?: number;
month?: number;
week?: number;
day?: number;
hour?: number;
minute?: number;
second?: number;
millis?: number;
zoneId?: string;
}
/**
* Base class for dates in supported calendars.
*/
export declare abstract class CalendarDate {
protected readonly _type: CalendarType;
protected readonly _firstDay: number;
protected readonly _minDays: number;
protected _fields: number[];
protected _zoneInfo: ZoneInfo;
/**
* Minimal fields required to construct any calendar date.
*/
protected constructor(_type: CalendarType, _firstDay: number, _minDays: number);
type(): CalendarType;
/**
* Unix epoch with no timezone offset.
*/
unixEpoch(): number;
firstDayOfWeek(): number;
minDaysInFirstWeek(): number;
/**
* Returns a floating point number representing the real Julian Day, UTC.
*/
julianDay(): number;
/**
* CLDR's modified Julian day used as the basis for all date calculations.
*/
modifiedJulianDay(): number;
era(): number;
extendedYear(): number;
year(): number;
relatedYear(): number;
yearOfWeekOfYear(): number;
weekOfYear(): number;
/**
* Ordinal month, one-based, e.g. Gregorian JANUARY = 1.
*/
month(): number;
/**
* Returns the week of the month computed using the locale's 'first day
* of week' and 'minimal days in first week' where applicable.
*
* For example, for the United States, weeks start on Sunday.
* Saturday 9/1/2018 would be in week 1, and Sunday 9/2/2018 would
* begin week 2.
*
* September
* Su Mo Tu We Th Fr Sa
* 1
* 2 3 4 5 6 7 8
* 9 10 11 12 13 14 15
* 16 17 18 19 20 21 22
* 23 24 25 26 27 28 29
* 30
*/
weekOfMonth(): number;
dayOfYear(): number;
/**
* Day of the week. 1 = SUNDAY, 2 = MONDAY, ..., 7 = SATURDAY
*/
dayOfWeek(): number;
/**
* Ordinal day of the week. 1 if this is the 1st day of the week,
* 2 if the 2nd, etc. Depends on the local starting day of the week.
*/
ordinalDayOfWeek(): number;
/**
* Ordinal number indicating the day of the week in the current month.
* The result of this method can be used to format messages like
* "2nd Sunday in August".
*/
dayOfWeekInMonth(): number;
dayOfMonth(): number;
isAM(): boolean;
hour(): number;
hourOfDay(): number;
minute(): number;
second(): number;
milliseconds(): number;
millisecondsInDay(): number;
metaZoneId(): MetaZoneType;
timeZoneId(): string;
timeZoneOffset(): number;
isLeapYear(): boolean;
isDaylightSavings(): boolean;
/**
* Computes the field of greatest difference between the two dates.
* Note: This assumes the dates are of the same type and have the same
* timezone offset.
*/
fieldOfGreatestDifference(other: CalendarDate): DateTimePatternFieldType;
abstract add(fields: CalendarDateFields): CalendarDate;
/**
* Compute a new Julian day and milliseconds UTC by updating one or more fields.
*/
protected _add(fields: CalendarDateFields): [number, number];
/**
* Converts all time fields into [days, milliseconds].
*/
protected _addTime(fields: CalendarDateFields): [number, number];
protected initFromUnixEpoch(ms: number, zoneId?: string): void;
protected initFromJD(jd: number, msDay: number, zoneId?: string): void;
protected _toString(type: string, year?: string): string;
/**
* Compute WEEK_OF_YEAR and YEAR_WOY on demand.
*/
protected computeWeekFields(): void;
protected yearLength(y: number): number;
protected weekNumber(desiredDay: number, dayOfPeriod: number, dayOfWeek: number): number;
protected abstract monthStart(eyear: number, month: number, useMonth: boolean): number;
}