]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] update moment.d.ts for calendar (#5566)
authorAlan Wang <wp_scut@163.com>
Fri, 29 May 2020 21:40:47 +0000 (05:40 +0800)
committerGitHub <noreply@github.com>
Fri, 29 May 2020 21:40:47 +0000 (14:40 -0700)
ts3.1-typing-tests/moment-tests.ts
ts3.1-typings/moment.d.ts
typing-tests/moment-tests.ts

index 9ee1b2ed61e93fe272b1467eedd27dee5940ef80..201b68dc9bfb3cc424c115011e0f8507f98e5dfb 100644 (file)
@@ -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');
@@ -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",
index e4f531979f10ce334b7c68731529e797a883c0fc..3f6bb8ed606712607b76a343234f3495840fd40d 100644 (file)
@@ -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';
 
@@ -89,6 +89,7 @@ declare namespace moment {
     hh?: RelativeTimeSpecVal;
     d?: RelativeTimeSpecVal;
     dd?: RelativeTimeSpecVal;
+    w?: RelativeTimeSpecVal;
     M?: RelativeTimeSpecVal;
     MM?: RelativeTimeSpecVal;
     y?: RelativeTimeSpecVal;
@@ -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;
index e3e98286f7297041aaa5f2f5189f7ec91c7eaa78..929f7cc73252d30ee8a92dbc61545650b410cc8c 100644 (file)
@@ -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');
@@ -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",