@tubular/time
Version:
Date/time, IANA timezones, leap seconds, TAI/UTC conversions, calendar with settable Julian/Gregorian switchover
237 lines • 11.4 kB
TypeScript
import { DateAndTime, YMDDate } from './common';
export declare enum CalendarType {
PURE_GREGORIAN = 0,
PURE_JULIAN = 1
}
export declare const GREGORIAN_CHANGE_MIN_YEAR = 300;
export declare const GREGORIAN_CHANGE_MAX_YEAR = 3900;
export declare const SUNDAY = 0;
export declare const MONDAY = 1;
export declare const TUESDAY = 2;
export declare const WEDNESDAY = 3;
export declare const THURSDAY = 4;
export declare const FRIDAY = 5;
export declare const SATURDAY = 6;
export declare enum DayOfWeek {
SUNDAY = 0,
MONDAY = 1,
TUESDAY = 2,
WEDNESDAY = 3,
THURSDAY = 4,
FRIDAY = 5,
SATURDAY = 6
}
export declare enum Month {
JANUARY = 1,
FEBRUARY = 2,
MARCH = 3,
APRIL = 4,
MAY = 5,
JUNE = 6,
JULY = 7,
AUGUST = 8,
SEPTEMBER = 9,
OCTOBER = 10,
NOVEMBER = 11,
DECEMBER = 12
}
/**
* Constant for indicating the last occurrence of a particular day of the week (e.g. the last Tuesday) of a given month.
*/
export declare const LAST = 6;
/**
* Type allowing a year alone to be specified, a full date as a [[YMDDate]], or a full date as a numeric array in the
* form [year, month, date].
*/
export declare type YearOrDate = number | YMDDate | number[];
/**
* Type for specifying the date when a calendar switches from Julian to Gregorian, or if the calendar is purely Julian
* or purely Gregorian. As a string, the letters 'J' or 'G' can be used.
*/
export declare type GregorianChange = YMDDate | CalendarType | string | number[];
/** @hidden */
export declare function isGregorianType(obj: any): obj is GregorianChange;
/** @hidden */
export declare function handleVariableDateArgs(yearOrDate: YearOrDate, month?: number, day?: number, calendar?: Calendar | 'g' | 'j', ignoreJ?: boolean): number[];
/**
* Determine if a given date falls during the Julian calendar or the Gregorian calendar, given the standard
* Gregorian change date of 1582-10-15.
*
* @param {YearOrDate} yearOrDate
* @param {number} month
* @param {number} day
* @returns True if the date is Julian.
*/
export declare function isJulianCalendarDate_SGC(yearOrDate: YearOrDate, month?: number, day?: number): boolean;
/**
* Gets the day number for the given date, relative to 1970-01-01, using the standard Gregorian change date 1582-10-15.
* @param yearOrDate
* @param month
* @param day
* @returns Day number.
*/
export declare function getDayNumber_SGC(yearOrDate: YearOrDate, month?: number, day?: number): number;
/**
* Gets the day number for the given Gregorian calendar date, relative to 1970-01-01.
* @param yearOrDate
* @param month
* @param day
* @returns Day number.
*/
export declare function getDayNumberGregorian(yearOrDate: YearOrDate, month?: number, day?: number): number;
/**
* Gets the day number for the given Julian calendar date, relative to 1970-01-01 Gregorian.
* @param yearOrDate
* @param month
* @param day
* @returns Day number.
*/
export declare function getDayNumberJulian(yearOrDate: YearOrDate, month?: number, day?: number): number;
/**
* Always returns 1. This function exists only to parallel getFirstDateInMonth, which isn't always 1 when the
* Gregorian change date is not fixed.
* @returns First date of calendar month.
*/
export declare function getFirstDateInMonth_SGC(year: number, month: number): number;
/**
* The last date of the given calendar month, using the standard Gregorian change date 1582-10-15, e.g. 31 for
* any January, 28 for non-leap-year February, 29 for leap-year February, etc.
* @param year
* @param month
* @returns Last date of calendar month.
*/
export declare function getLastDateInMonth_SGC(year: number, month: number): number;
/**
* The last date of the given Gregorian calendar month.
* @param year
* @param month
* @returns Last date of calendar month.
*/
export declare function getLastDateInMonthGregorian(year: number, month: number): number;
/**
* The last date of the given Gregorian calendar month.
* @param year
* @param month
* @returns Last date of calendar month.
*/
export declare function getLastDateInMonthJulian(year: number, month: number): number;
/**
* Returns the number of days in the given calendar month. Since this
* function is for the standard Gregorian change date of 1582-10-15,
* it returns 21 for 1582/10, otherwise it returns the same value as
* [[getLastDateInMonth_SGC]].
* @param year
* @param month
* @returns Total number of days in the given month.
*/
export declare function getDaysInMonth_SGC(year: number, month: number): number;
/**
* This typically returns 365, or 366 for a leap year, but for the year
* 1582 it returns 355.
* @param year
* @returns Total number of days in the given year.
*/
export declare function getDaysInYear_SGC(year: number): number;
/**
* Get day of week for a given 1970-01-01-based day number.
* @param dayNum 1970-01-01-based day number.
* @return Day of week as 0-6: 0 for Sunday, 1 for Monday... 6 for Saturday.
*/
export declare function getDayOfWeek(dayNum: number): number;
/**
* Get day of week for a given date, assuming standard Gregorian change.
* @param yearOrDateOrDayNum 1970-01-01-based day number (month and date must be left undefined) - OR -
* YMDDate form y/m/d - OR - [y, m, d].
* @param month
* @param day
* @return Day of week as 0-6: 0 for Sunday, 1 for Monday... 6 for Saturday.
*/
export declare function getDayOfWeek_SGC(yearOrDateOrDayNum: YearOrDate, month?: number, day?: number): number;
/**
* Get the date of the index-th day of the week of a given month, e.g. the date of the
* first Wednesday or the third Monday or the last Friday of the month.
* @param year Year.
* @param month Month.
* @param dayOfTheWeek The day of the week (e.g. 0 for Sunday, 2 for Tuesday, 6 for Saturday) for
* which you wish to find the date.
* @param index A value of 1-5, or LAST (6), for the occurrence of the specified day of the week.
* @return 0 if the described day does not exist (e.g. there is no fifth Monday in the given month) or
* the date of the specified day.
*/
export declare function getDateOfNthWeekdayOfMonth_SGC(year: number, month: number, dayOfTheWeek: number, index: number): number;
export declare function getDayOfWeekInMonthCount_SGC(year: number, month: number, dayOfTheWeek: number): number;
export declare function getDayOnOrAfter_SGC(year: number, month: number, dayOfTheWeek: number, minDate: number): number;
export declare function getDayOnOrBefore_SGC(year: number, month: number, dayOfTheWeek: number, maxDate: number): number;
export declare function addDaysToDate_SGC(deltaDays: number, yearOrDate: YearOrDate, month?: number, day?: number): YMDDate;
export declare function getDateFromDayNumber_SGC(dayNum: number): YMDDate;
export declare function getDateFromDayNumberGregorian(dayNum: number): YMDDate;
export declare function getDateFromDayNumberJulian(dayNum: number): YMDDate;
export declare function millisFromDateTime_SGC(year: number, month: number, day: number, hour: number, minute: number, second?: number, millis?: number): number;
export declare function dateAndTimeFromMillis_SGC(ticks: number): DateAndTime;
export declare function isValidDate_SGC(yearOrDate: YearOrDate, month?: number, day?: number): boolean;
export declare function isValidDateGregorian(yearOrDate: YearOrDate, month?: number, day?: number): boolean;
export declare function isValidDateJulian(yearOrDate: YearOrDate, month?: number, day?: number): boolean;
export declare function getISOFormatDate(yearOrDate: YearOrDate, month?: number, day?: number): string;
export declare function parseISODate(date: string): YMDDate;
export declare class Calendar {
private gcYear;
private gcMonth;
private gcDate;
private firstGregorianDay;
private firstDateInGCChangeMonth;
private lengthOfGCChangeMonth;
private lastJulianYear;
private lastJulianMonth;
private lastJulianDate;
protected _locked: boolean;
constructor(gcYearOrDateOrType?: YearOrDate | CalendarType | string, gcMonth?: number, gcDate?: number);
lock: () => this;
protected _lock(doLock?: boolean): this;
get locked(): boolean;
setPureGregorian(pureGregorian: boolean): this;
isPureGregorian(): boolean;
setPureJulian(pureJulian: boolean): this;
isPureJulian(): boolean;
setGregorianChange(gcYearOrDate: YearOrDate | string, gcMonth?: number, gcDate?: number): this;
getGregorianChange(): YMDDate;
isJulianCalendarDate(yearOrDate: YearOrDate, month?: number, day?: number): boolean;
getDayNumber(yearOrDate: YearOrDate, month?: number, day?: number): number;
protected computeWeekValues: number;
/** @hidden */
getDateFromDayNumber(dayNum: number, startingDayOfWeek?: number, minDaysInCalendarYear?: number): YMDDate;
getFirstDateInMonth(year: number, month: number): number;
getLastDateInMonth(year: number, month: number): number;
getDaysInMonth(year: number, month: number): number;
getDaysInYear(year: number): number;
getDayOfWeek(yearOrDateOrDayNum: YearOrDate, month?: number, day?: number): number;
/**
* @description Get the date of the index-th day of the week of a given month, e.g. the date of the
* first Wednesday or the third Monday or the last Friday of the month.
*
* @param {number} year - Year.
* @param {number} month - Month.
* @param {number} dayOfTheWeek - The day of the week (e.g. 0 for Sunday, 2 for Tuesday, 6 for Saturday) for
* which you wish to find the date.
* @param {number} index - A value of 1-5, or LAST (6), for the occurrence of the specified day of the week.
*
* @return {number} 0 if the described day does not exist (e.g. there is no fifth Monday in the given month) or
* the date of the specified day.
*/
getDateOfNthWeekdayOfMonth(year: number, month: number, dayOfTheWeek: number, index: number): number;
getDayOfWeekInMonthCount(year: number, month: number, dayOfTheWeek: number): number;
getDayOfWeekInMonthIndex(yearOrDate: YearOrDate, month?: number, day?: number): number;
getDayOnOrAfter(year: number, month: number, dayOfTheWeek: number, minDate: number): number;
getDayOnOrBefore(year: number, month: number, dayOfTheWeek: number, maxDate: number): number;
addDaysToDate(deltaDays: number, yearOrDate: YearOrDate, month?: number, day?: number): YMDDate;
getCalendarMonth(year: number, month: number, startingDayOfWeek?: number): YMDDate[];
isValidDate(year: number, month: number, day: number): boolean;
isValidDate(yearOrDate: YMDDate | number[]): boolean;
normalizeDate(year: number, month: number, day: number): YMDDate;
normalizeDate(yearOrDate: YMDDate | number[]): YMDDate;
getMissingDateRange(year: number, month: number): number[] | null;
getStartDateOfFirstWeekOfYear(year: number, startingDayOfWeek?: number, minDaysInCalendarYear?: number): YMDDate;
getWeeksInYear(year: number, startingDayOfWeek?: number, minDaysInCalendarYear?: number): number;
getYearWeekAndWeekday(year: number, month: number, day: number, startingDayOfWeek?: number, minDaysInCalendarYear?: number): number[];
getYearWeekAndWeekday(date: YearOrDate | number, startingDayOfWeek?: number, minDaysInCalendarYear?: number): number[];
}
//# sourceMappingURL=calendar.d.ts.map