Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[misc] add readonly typescript interface #5752

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
179 changes: 120 additions & 59 deletions ts3.1-typings/moment.d.ts
Expand Up @@ -427,10 +427,10 @@ declare namespace moment {
to: MomentInput;
}

type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | null | undefined;
type MomentInput = ReadonlyMoment | Date | string | number | (number | string)[] | MomentInputObject | null | undefined;
type DurationInputArg1 = Duration | number | string | FromTo | DurationInputObject | null | undefined;
type DurationInputArg2 = unitOfTime.DurationConstructor;
type LocaleSpecifier = string | Moment | Duration | string[] | boolean;
type LocaleSpecifier = string | ReadonlyMoment | Duration | string[] | boolean;

interface MomentCreationData {
input: MomentInput;
Expand All @@ -440,24 +440,9 @@ declare namespace moment {
strict?: boolean;
}

interface Moment extends Object {
interface ReadonlyMoment extends Object {
format(format?: string): string;

startOf(unitOfTime: unitOfTime.StartOf): Moment;
endOf(unitOfTime: unitOfTime.StartOf): Moment;

add(amount?: DurationInputArg1, unit?: DurationInputArg2): Moment;
/**
* @deprecated reverse syntax
*/
add(unit: unitOfTime.DurationConstructor, amount: number|string): Moment;

subtract(amount?: DurationInputArg1, unit?: DurationInputArg2): Moment;
/**
* @deprecated reverse syntax
*/
subtract(unit: unitOfTime.DurationConstructor, amount: number|string): Moment;

calendar(): string;
calendar(formats: CalendarSpec): string;
calendar(time?: MomentInput, formats?: CalendarSpec): string;
Expand All @@ -470,25 +455,139 @@ declare namespace moment {
valueOf(): number;

// current date/time in local mode
local(keepLocalTime?: boolean): Moment;
isLocal(): boolean;

// current date/time in UTC mode
utc(keepLocalTime?: boolean): Moment;
isUTC(): boolean;
/**
* @deprecated use isUTC
*/
isUtc(): boolean;

parseZone(): Moment;
isValid(): boolean;
invalidAt(): number;

hasAlignedHourOffset(other?: MomentInput): boolean;

creationData(): MomentCreationData;
parsingFlags(): MomentParsingFlags;
year(): number;
/**
* @deprecated use year()
*/
years(): number;
quarter(): number;
quarters(): number;
month(): number;
/**
* @deprecated use month()
*/
months(): number;
day(): number;
days(): number;
date(): number;
/**
* @deprecated use date()
*/
dates(): number;
hour(): number;
hours(): number;
minute(): number;
minutes(): number;
second(): number;
seconds(): number;
millisecond(): number;
milliseconds(): number;
weekday(): number;
isoWeekday(): number;
weekYear(): number;
isoWeekYear(): number;
week(): number;
weeks(): number;
isoWeek(): number;
isoWeeks(): number;
weeksInYear(): number;
isoWeeksInYear(): number;
isoWeeksInISOWeekYear(): number;
dayOfYear(): number;

from(inp: MomentInput, suffix?: boolean): string;
to(inp: MomentInput, suffix?: boolean): string;
fromNow(withoutSuffix?: boolean): string;
toNow(withoutPrefix?: boolean): string;

diff(b: MomentInput, unitOfTime?: unitOfTime.Diff, precise?: boolean): number;

toArray(): [number, number, number, number, number, number, number];
toDate(): Date;
toISOString(keepOffset?: boolean): string;
inspect(): string;
toJSON(): string;
unix(): number;

isLeapYear(): boolean;
/**
* @deprecated in favor of utcOffset
*/
zone(): number;
utcOffset(): number;
isUtcOffset(): boolean;
daysInMonth(): number;
isDST(): boolean;

zoneAbbr(): string;
zoneName(): string;

isBefore(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isAfter(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isSame(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isSameOrAfter(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isSameOrBefore(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isBetween(a: MomentInput, b: MomentInput, granularity?: unitOfTime.StartOf, inclusivity?: "()" | "[)" | "(]" | "[]"): boolean;

/**
* @deprecated as of 2.8.0, use locale
*/
lang(): Locale;

locale(): string;

localeData(): Locale;

/**
* @deprecated no reliable implementation
*/
isDSTShifted(): boolean;


get(unit: unitOfTime.All): number;

toObject(): MomentObjectOutput;
}

interface Moment extends ReadonlyMoment {
startOf(unitOfTime: unitOfTime.StartOf): Moment;
endOf(unitOfTime: unitOfTime.StartOf): Moment;

add(amount?: DurationInputArg1, unit?: DurationInputArg2): Moment;
/**
* @deprecated reverse syntax
*/
add(unit: unitOfTime.DurationConstructor, amount: number|string): Moment;

subtract(amount?: DurationInputArg1, unit?: DurationInputArg2): Moment;
/**
* @deprecated reverse syntax
*/
subtract(unit: unitOfTime.DurationConstructor, amount: number|string): Moment;

// current date/time in local mode
local(keepLocalTime?: boolean): Moment;

// current date/time in UTC mode
utc(keepLocalTime?: boolean): Moment;

parseZone(): Moment;

year(y: number): Moment;
year(): number;
Expand Down Expand Up @@ -566,41 +665,13 @@ declare namespace moment {
dayOfYear(): number;
dayOfYear(d: number): Moment;

from(inp: MomentInput, suffix?: boolean): string;
to(inp: MomentInput, suffix?: boolean): string;
fromNow(withoutSuffix?: boolean): string;
toNow(withoutPrefix?: boolean): string;

diff(b: MomentInput, unitOfTime?: unitOfTime.Diff, precise?: boolean): number;

toArray(): [number, number, number, number, number, number, number];
toDate(): Date;
toISOString(keepOffset?: boolean): string;
inspect(): string;
toJSON(): string;
unix(): number;

isLeapYear(): boolean;
/**
* @deprecated in favor of utcOffset
*/
zone(): number;
zone(b: number|string): Moment;
utcOffset(): number;
utcOffset(b: number|string, keepLocalTime?: boolean): Moment;
isUtcOffset(): boolean;
daysInMonth(): number;
isDST(): boolean;

zoneAbbr(): string;
zoneName(): string;

isBefore(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isAfter(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isSame(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isSameOrAfter(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isSameOrBefore(inp?: MomentInput, granularity?: unitOfTime.StartOf): boolean;
isBetween(a: MomentInput, b: MomentInput, granularity?: unitOfTime.StartOf, inclusivity?: "()" | "[)" | "(]" | "[]"): boolean;

/**
* @deprecated as of 2.8.0, use locale
Expand All @@ -614,13 +685,6 @@ declare namespace moment {
locale(): string;
locale(locale: LocaleSpecifier): Moment;

localeData(): Locale;

/**
* @deprecated no reliable implementation
*/
isDSTShifted(): boolean;

// NOTE(constructor): Same as moment constructor
/**
* @deprecated as of 2.7.0, use moment.min/max
Expand All @@ -641,11 +705,8 @@ declare namespace moment {
*/
min(inp?: MomentInput, format?: MomentFormatSpecification, language?: string, strict?: boolean): Moment;

get(unit: unitOfTime.All): number;
set(unit: unitOfTime.All, value: number): Moment;
set(objectLiteral: MomentSetObject): Moment;

toObject(): MomentObjectOutput;
}

export var version: string;
Expand Down