]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Update the type definition of the humanize() API, fix compilation error...
authorAlan Wang <wp_scut@163.com>
Mon, 18 May 2020 04:24:56 +0000 (12:24 +0800)
committerGitHub <noreply@github.com>
Mon, 18 May 2020 04:24:56 +0000 (21:24 -0700)
moment.d.ts
ts3.1-typing-tests/moment-tests.ts
ts3.1-typings/moment.d.ts
typing-tests/moment-tests.ts

index 630fc03ab85a44cd12f9e479946434c6d1023d6c..89ab02fc79374e9b0dd8af560383b589a686d3d6 100644 (file)
@@ -178,23 +178,22 @@ declare namespace moment {
     milliseconds: number;
   }
 
-  interface HumanizeOptions {
-    withSuffix?: boolean;
-    thresholds?: {
-      ss?: number;
-      s?: number;
-      m?: number;
-      h?: number;
-      d?: number;
-      w?: number | void;
-      M?: number;
-    };
+  interface argThresholdOpts {
+    ss?: number;
+    s?: number;
+    m?: number;
+    h?: number;
+    d?: number;
+    w?: number | void;
+    M?: number;
   }
 
   interface Duration {
     clone(): Duration;
 
-    humanize(withSuffixOrOptions?: boolean | HumanizeOptions): string;
+    humanize(argWithSuffix?: boolean, argThresholds?: argThresholdOpts): string;
+    
+    humanize(argThresholds?: argThresholdOpts): string;
 
     abs(): Duration;
 
index 943738c6ddd53acb77469e4cb8e6bde2151ef17b..0ac74ae3a193165e76c15de522179880101a208d 100644 (file)
@@ -236,6 +236,15 @@ moment(1316116057189).fromNow();
 moment.localeData('en');
 var globalLang = moment();
 var localLang = moment();
+var thresholds = {
+    ss: 44, 
+    s: 45,
+    m: 45,
+    h: 22,
+    d: 26,
+    w: 2,
+    M: 11,
+};
 localLang.localeData();
 localLang.format('LLLL');
 globalLang.format('LLLL');
@@ -264,6 +273,9 @@ moment.duration({
 });
 moment.duration(1, "minute").clone();
 moment.duration(1, "minutes").humanize();
+moment.duration(1, "minutes").humanize(true);
+moment.duration(1, "minutes").humanize(thresholds);
+moment.duration(1, "minutes").humanize(true, thresholds);
 moment.duration(500).milliseconds();
 moment.duration(500).asMilliseconds();
 moment.duration(500).seconds();
index fa90acae32961ca082922f7131a6b2e1ad64dc92..e100ee3a76bb8f4bc390e784ee0c01e654bab36e 100644 (file)
@@ -153,11 +153,22 @@ declare namespace moment {
     seconds: number;
     milliseconds: number;
   }
+  interface argThresholdOpts {
+    ss?: number;
+    s?: number;
+    m?: number;
+    h?: number;
+    d?: number;
+    w?: number | null;
+    M?: number;
+  }
 
   interface Duration {
     clone(): Duration;
 
-    humanize(withSuffix?: boolean): string;
+    humanize(argWithSuffix?: boolean, argThresholds?: argThresholdOpts): string;
+    
+    humanize(argThresholds?: argThresholdOpts): string;
 
     abs(): Duration;
 
index 41cff85cf61ec205d304c48b158be54ce0cd5f04..a01dd21eb19e9d0f1918b6f425d67f2117a40ef4 100644 (file)
@@ -239,6 +239,15 @@ moment(1316116057189).fromNow();
 moment.localeData('en');
 var globalLang = moment();
 var localLang = moment();
+var thresholds = {
+    ss: 44, 
+    s: 45,
+    m: 45,
+    h: 22,
+    d: 26,
+    w: 2,
+    M: 11,
+};
 localLang.localeData();
 localLang.format('LLLL');
 globalLang.format('LLLL');
@@ -268,6 +277,9 @@ moment.duration({
 });
 moment.duration(1, "minute").clone();
 moment.duration(1, "minutes").humanize();
+moment.duration(1, "minutes").humanize(true);
+moment.duration(1, "minutes").humanize(thresholds);
+moment.duration(1, "minutes").humanize(true, thresholds);
 moment.duration(500).milliseconds();
 moment.duration(500).asMilliseconds();
 moment.duration(500).seconds();