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-2.0.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-1.1.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-1.1.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-2.0.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-2.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-1.2.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-1.1.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-1.1.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-0.17.6 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-1.0.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-1.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-0.17.5 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-0.17.4 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-0.17.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-0.17.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-0.17.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js