The method 'calculateDuration' should return an empty string if time diff is less then a minute.
Signed-off-by: Volker Theile <vtheile@suse.com>
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;
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();