2023-06-19 16:23:53 +00:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-06-19 16:23:53 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-03-14 09:56:47 -07:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
|
import { inject as service } from '@ember/service';
|
2024-09-13 09:43:08 -05:00
|
|
|
import { DurationFormat } from '@formatjs/intl-durationformat';
|
|
|
|
|
import { secondsToDuration } from 'core/utils/seconds-to-duration';
|
2023-03-14 09:56:47 -07:00
|
|
|
|
|
|
|
|
export default class extends Helper {
|
|
|
|
|
// =services
|
|
|
|
|
@service intl;
|
|
|
|
|
|
|
|
|
|
// =methods
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {number} durationInMs Duration in milliseconds
|
|
|
|
|
* @returns localized human-readable duration string. For example, in English "1 hr 23 min 20 sec"
|
|
|
|
|
*/
|
|
|
|
|
compute([durationInMs]) {
|
|
|
|
|
const durationInSeconds = durationInMs / 1000;
|
2024-09-13 09:43:08 -05:00
|
|
|
const durationFormat = new DurationFormat(this.intl.primaryLocale, {
|
2023-03-14 12:28:54 -07:00
|
|
|
style: 'narrow',
|
2023-03-14 09:56:47 -07:00
|
|
|
});
|
|
|
|
|
|
2024-09-13 09:43:08 -05:00
|
|
|
return durationFormat.format(secondsToDuration(durationInSeconds));
|
2023-03-14 09:56:47 -07:00
|
|
|
}
|
|
|
|
|
}
|