]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Add time-diff unittest and docs 31357/head
authorVolker Theile <vtheile@suse.com>
Mon, 4 Nov 2019 13:44:58 +0000 (14:44 +0100)
committerVolker Theile <vtheile@suse.com>
Thu, 7 Nov 2019 09:07:26 +0000 (10:07 +0100)
The method 'calculateDuration' should return an empty string if time diff is less then a minute.

Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/services/time-diff.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/time-diff.service.ts

index 59b52ae6039939c77e27960e07d7cbde6c515ff9..335b85cecddae3c6eee29e8ecdde0d1fe2ce204c 100644 (file)
@@ -38,6 +38,11 @@ describe('TimeDiffService', () => {
     expect(service.calculateDuration(baseTime, new Date('2022-02-28T04:05:00'))).toBe('6d 4h 5m');
   });
 
+  it('should return an empty string if time diff is less then a minute', () => {
+    const ts = 1568361327000;
+    expect(service.calculateDuration(new Date(ts), new Date(ts + 120))).toBe('');
+  });
+
   describe('testing duration calculation in detail', () => {
     const minutes = 60 * 1000;
     const hours = 60 * minutes;
index 051d104906e754069a87f90e013879ba479b7bd9..0f882bc8f4d21020bfc91225037ed2bf8c68b3fb 100644 (file)
@@ -18,6 +18,12 @@ export class TimeDiffService {
     return duration;
   }
 
+  /**
+   * Get the duration in the format '[Nd] [Nh] [Nm]', e.g. '2d 1h 15m'.
+   * @param ms The time in milliseconds.
+   * @return The duration. An empty string is returned if the duration is
+   *   less than a minute.
+   */
   private getDuration(ms: number): string {
     const date = new Date(ms);
     const h = date.getUTCHours();