carbonjs
Version:
Javascript date library alternative to Moment.js with the same modern API
109 lines (108 loc) • 4.69 kB
TypeScript
declare module Carbon {
type CarbonInput = string | number | Date | Carbon;
type Unit = "y" | "year" | "M" | "month" | "d" | "day" | "h" | "hour" | "m" | "minute" | "s" | "second" | "ms" | "millisecond";
type ManipulationUnit = Carbon.Unit | "years" | "months" | "w" | "week" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds";
type DateInputArray = [number, number, number, number, number, number, number];
interface Tokens {
[token: string]: string;
}
type Plugin<T = any> = (Base: typeof Carbon, options?: T) => void;
interface Locale {
name: string;
weekdays: string[];
weekdaysShort?: string[];
weekdaysMin?: string[];
months: string[];
monthsShort?: string[];
relativeTime?: {
future: string;
past: string;
s: string;
m: string;
mm: string;
h: string;
hh: string;
d: string;
dd: string;
M: string;
MM: string;
y: string;
yy: string;
};
ordinal?: (num: string | number) => string | number;
}
}
interface Carbon {
isBetween(from: Carbon.CarbonInput, to: Carbon.CarbonInput): boolean;
dayOfYear(calendar?: "jalaali" | "islamic"): number;
isLeapYear(calendar?: "jalaali" | "islamic"): boolean;
from(input: Carbon.CarbonInput, withoutSuffix?: boolean): string;
to(input: Carbon.CarbonInput, withoutSuffix?: boolean): string;
fromNow(withoutSuffix?: boolean): string;
toNow(withoutSuffix?: boolean): string;
weekOfYear(calendar?: "jalaali" | "islamic"): number;
year(calendar: "jalaali" | "islamic"): number;
month(calendar: "jalaali" | "islamic"): number;
day(calendar: "jalaali" | "islamic"): number;
daysInMonth(calendar: "jalaali" | "islamic"): number;
add(value: string | number, unit: Carbon.ManipulationUnit | "jY" | "jM" | "jYear" | "jMonth" | "iY" | "iM" | "iYear" | "iMonth"): this;
subtract(value: string | number, unit: Carbon.ManipulationUnit | "jY" | "jM" | "jYear" | "jMonth" | "iY" | "iM" | "iYear" | "iMonth"): this;
set(unit: Carbon.Unit | "weekday" | "jY" | "jM" | "jD" | "jYear" | "jMonth" | "jDay" | "iY" | "iM" | "iD" | "iYear" | "iMonth" | "iDay", value: number): this;
startOf(unit: Carbon.ManipulationUnit | "jY" | "jM" | "jYear" | "jMonth" | "iY" | "iM" | "iYear" | "iMonth"): this;
endOf(unit: Carbon.ManipulationUnit | "jY" | "jM" | "jYear" | "jMonth" | "iY" | "iM" | "iYear" | "iMonth"): this;
}
declare class Carbon {
protected static _en: Carbon.Locale;
protected _localeName: string;
protected _date: Date;
protected _year: number;
protected _month: number;
protected _weekday: number;
protected _day: number;
protected _hours: number;
protected _minutes: number;
protected _seconds: number;
protected _milliseconds: number;
static isCarbon: (arg: any) => arg is Carbon;
static extend: <T = any>(plugin: Carbon.Plugin<T>, options?: T | undefined) => void;
static locale: (locale: string | Carbon.Locale, global?: boolean) => string;
static parse: (input?: string | number | Date | Carbon | undefined, format?: string | undefined, locale?: string | Carbon.Locale | undefined) => Carbon;
constructor(input?: Carbon.CarbonInput, format?: string, locale?: string | Carbon.Locale);
protected readonly _locale: Carbon.Locale;
protected _parseDate(input?: Carbon.CarbonInput, format?: string, locale?: string | Carbon.Locale): Date;
protected _parseToken(token: string, value: string, dateArray: Carbon.DateInputArray, tokens: Carbon.Tokens): void;
private _clone;
private _compare;
private _edge;
locale(locale: string | Carbon.Locale): Carbon;
isValid(): boolean;
isSame(input?: Carbon.CarbonInput): boolean;
isBefore(input?: Carbon.CarbonInput): boolean;
isAfter(input?: Carbon.CarbonInput): boolean;
weekday(): number;
hour(): number;
minute(): number;
second(): number;
millisecond(): number;
utcOffset(): number;
valueOf(): number;
unix(): number;
format(format?: string): string;
diff(date: Carbon.CarbonInput, unit?: Carbon.ManipulationUnit | "quarter" | "quarters", float?: boolean): number;
clone(): Carbon;
toDate(): Date;
toArray(): number[];
toObject(): {
years: number;
months: number;
date: number;
hours: number;
minutes: number;
seconds: number;
milliseconds: number;
};
toISOString(): string;
toJSON(): string;
toString(): string;
}
export = Carbon;