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-5.2.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-5.1.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-5.1.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.1.5 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.1.4 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.1.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-3.0.6 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-5.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.1.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.1.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.0.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.1.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-3.0.5 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-4.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-3.0.4 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-2.0.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-3.0.3 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-3.0.2 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-3.0.1 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js
foreman-tasks-3.0.0 webpack/ForemanTasks/Components/TaskDetails/Components/TaskHelper.js