Sha256: 1c26365347eaa0fc8a0e4a2f60f4b01448c76264265cab8910e0eb886fe55514

Contents?: true

Size: 769 Bytes

Versions: 76

Compression:

Stored size: 769 Bytes

Contents

import { translate as __, documentLocale } from 'foremanReact/common/I18n';
import { isoCompatibleDate } from 'foremanReact/common/helpers';
import humanizeDuration from 'humanize-duration';

export const durationInWords = (
  start,
  finish,
  selectedLocale = documentLocale()
) => {
  if (!start) return __('N/A');
  start = new Date(isoCompatibleDate(start)).getTime();
  finish = new Date(isoCompatibleDate(finish)).getTime();
  return {
    text: humanizeDuration(new Date(finish - start).getTime(), {
      largest: 1,
      language: selectedLocale,
      fallbacks: ['en'],
    }),
    tooltip: `${numberWithDelimiter((finish - start) / 1000)} ${__('seconds')}`,
  };
};

const numberWithDelimiter = x =>
  x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
foreman-tasks-8.1.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.1.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.1.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.0.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.0.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-7.2.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-7.1.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-7.2.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-7.1.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-6.0.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-7.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-6.0.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.1.6 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-5.2.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-6.0.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-5.2.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-6.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-5.2.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-5.3.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js