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-10.0.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-10.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.2.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.2.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.2.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.2.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.1.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.0.4 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.1.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.0.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.0.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.3.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-9.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.2.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.1.4 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.3.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.3.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.1.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.3.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-8.2.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js