Ver código fonte

Fix numbers len bug in UnitsText

Maksim Fedorov 1 ano atrás
pai
commit
d021d4dee2
2 arquivos alterados com 15 adições e 2 exclusões
  1. 2 2
      src/timeline.ts
  2. 13 0
      src/utils/timelineUtils.ts

+ 2 - 2
src/timeline.ts

@@ -1493,11 +1493,11 @@ export class Timeline extends TimelineEventsEmitter {
     }
 
     if (minutes) {
-      str += minutes + ':';
+      str += hours ? TimelineUtils.timePadZero(minutes) : minutes + ':';
     }
 
     if (!isNaN(seconds)) {
-      str += seconds;
+      str += minutes ? TimelineUtils.timePadZero(seconds) : seconds;
     }
 
     return sign + str;

+ 13 - 0
src/utils/timelineUtils.ts

@@ -285,4 +285,17 @@ export class TimelineUtils {
     mergeOptionsDeep(toArg, newOptions);
     return toArg;
   }
+  /**
+   * Format numbers with len
+   */
+  static timePadZero(num: number, len = 2): string {
+    let str = String(num);
+    const threshold = Math.pow(10, len - 1);
+    if (num < threshold) {
+      while (String(threshold).length > str.length) {
+        str = `0${num}`;
+      }
+    }
+    return str;
+  }
 }