Skip to content

Commit

Permalink
[bugfix] update moment.d.ts for calendar (#5566)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alanscut committed May 29, 2020
1 parent 7991d0d commit e3c6790
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions ts3.1-typing-tests/moment-tests.ts
Expand Up @@ -294,6 +294,19 @@ adur.subtract(bdur).days();
adur.subtract(1).days();
adur.subtract(1, 'd').days();

var calendarFormat = {
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'DD/MM/YYYY'
};
moment().calendar();
moment().calendar(null);
moment().calendar(calendarFormat);
moment().calendar(null, calendarFormat);

// Selecting a language
moment.locale();
moment.locale('en');
Expand Down Expand Up @@ -329,6 +342,7 @@ moment.locale('en', {
hh: "%d hours",
d: "a day",
dd: "%d days",
w: "%d weeks",
M: "a month",
MM: "%d months",
y: "a year",
Expand Down
5 changes: 4 additions & 1 deletion ts3.1-typings/moment.d.ts
Expand Up @@ -2,7 +2,7 @@ declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSp
declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, language?: string, strict?: boolean): moment.Moment;

declare namespace moment {
type RelativeTimeKey = 's' | 'ss' | 'm' | 'mm' | 'h' | 'hh' | 'd' | 'dd' | 'M' | 'MM' | 'y' | 'yy';
type RelativeTimeKey = 's' | 'ss' | 'm' | 'mm' | 'h' | 'hh' | 'd' | 'dd' | 'w' | 'M' | 'MM' | 'y' | 'yy';
type CalendarKey = 'sameDay' | 'nextDay' | 'lastDay' | 'nextWeek' | 'lastWeek' | 'sameElse' | string;
type LongDateFormatKey = 'LTS' | 'LT' | 'L' | 'LL' | 'LLL' | 'LLLL' | 'lts' | 'lt' | 'l' | 'll' | 'lll' | 'llll';

Expand Down Expand Up @@ -89,6 +89,7 @@ declare namespace moment {
hh?: RelativeTimeSpecVal;
d?: RelativeTimeSpecVal;
dd?: RelativeTimeSpecVal;
w?: RelativeTimeSpecVal;
M?: RelativeTimeSpecVal;
MM?: RelativeTimeSpecVal;
y?: RelativeTimeSpecVal;
Expand Down Expand Up @@ -441,6 +442,8 @@ declare namespace moment {
*/
subtract(unit: unitOfTime.DurationConstructor, amount: number|string): Moment;

calendar(): string;
calendar(formats: CalendarSpec): string;
calendar(time?: MomentInput, formats?: CalendarSpec): string;

clone(): Moment;
Expand Down
21 changes: 21 additions & 0 deletions typing-tests/moment-tests.ts
Expand Up @@ -298,6 +298,26 @@ adur.subtract(bdur).days();
adur.subtract(1).days();
adur.subtract(1, 'd').days();

var calendarFormat = {
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'DD/MM/YYYY'
};
moment().calendar();
moment().calendar(null);
moment().calendar(calendarFormat);
moment().calendar(null, {
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'DD/MM/YYYY'
});

// Selecting a language
moment.locale();
moment.locale('en');
Expand Down Expand Up @@ -334,6 +354,7 @@ moment.locale('en', {
hh: "%d hours",
d: "a day",
dd: "%d days",
w: "%d weeks",
M: "a month",
MM: "%d months",
y: "a year",
Expand Down

0 comments on commit e3c6790

Please sign in to comment.