How to use the humanize-duration.humanizer function in humanize-duration

To help you get started, we’ve selected a few humanize-duration examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sebastianhaas / medical-appointment-scheduling / src / app / appointment / appointment-detail.component.ts View on Github external
ngOnInit(): void {
    let param: string = this.route.snapshot.params['id'];

    // Mouseflow integration
    _mfq.push(['newPageView', '/appointment/' + param]);

    // This is a sub-page
    this._state.isSubPage.next(true);
    this._state.title.next();
    this._state.actions.next();
    this._state.primaryAction.next();

    // Set up localized humanizer for durations
    this.localeHumanizer = humanizeDuration.humanizer({
      language: localStorage.getItem('locale').startsWith('de') ? 'de' : 'en'
    });

    this.trans = getI18nStrings();

    // Create new appointment
    if (param === 'add') {
      this.editing = true;

    // View or edit existing appointment
    } else if (Number(param) !== NaN) {
      this.editing = false;
      console.log('displaying appointment with id: %d', Number(param));
      this.getAppointmentById(Number(param));
    }
github Sefaria / Sefaria-Project / static / js / sefaria / util.js View on Github external
this.$preview.html("");
          this.$preview.hide();
      }
      this.$input.autocomplete("enable");
      var inString = this.$input.val();
      if (inString.length < 3) {
          this._disallow();
          return;
      }
      this._lookupAndRoute(inString);
  }
};
const secsInDay = 24 * 60 * 60;
Util._cookies = {};
Util._scrollbarWidth = null;
Util.sefariaHumanizeDuration = humanizeDuration.humanizer({
  units: ['y', 'mo', 'w', 'd', 'h', 'm', 's'],
  largest: 1,
  round: true,
  unitMeasures: {
    y: 365 * secsInDay,
    mo: 30 * secsInDay,
    w: 7 * secsInDay,
    d: secsInDay,
    h: 60 * 60,
    m: 60,
    s: 1,
  },
  languages: {
    he: {  // add hebrew since it's not supported in the package
      y: n => Util.naturalTimePlural(n, 'שנה', 'שנים'),
      mo: n => Util.naturalTimePlural(n, 'חודש', 'חודשים'),
github redhat-developer-tooling / developer-platform-install / browser / pages / install / controller.js View on Github external
this.productName = productName;
    this.productVersion = productVersion;
    this.productDesc = productDesc;
    this.$timeout = $timeout;
    this.$scope = $scope;
    this.current = 0;
    this.label = '';
    this.status = '';
    this.currentAmount = 0;
    this.lastAmount = 0;
    this.totalAmount = 0;
    this.min = minValue;
    this.max = maxValue;
    this.lastTime = Date.now();
    this.averageSpeed = 0;
    this.durationFormat = duration.humanizer(Object.assign({}, shortDuration));
    this.durationFormat.units = ['y', 'd', 'h', 'm'];
  }
github evancohen / smart-mirror / plugins / traffic / controller.js View on Github external
function Traffic($scope, $http, $interval, $q, TimeboxService) {
	var BING_MAPS = "http://dev.virtualearth.net/REST/V1/Routes/";
	var language = (typeof config.general.language !== 'undefined') ? config.general.language.substr(0, 2) : "en"
	var durationHumanizer = require('humanize-duration').humanizer({
		language: language,
		units: ['h', 'm'],
		round: true
	});

	var getDurationForTrips = function () {
		var deferred = $q.defer();
		var promises = [];

		if (typeof config.traffic != 'undefined' && config.traffic.key != '' && config.traffic.trips) {
			angular.forEach(config.traffic.trips, function (trip) {
				if (trip.hasOwnProperty('startTime') && TimeboxService.shouldDisplay(trip.startTime, trip.endTime)
                    || !trip.hasOwnProperty('startTime')) {
					promises.push(getTripDuration(trip));
				}
			});
github Satont / twobit / systems / variables.js View on Github external
const { io } = require('../libs/panel')
const commons = require('../libs/commons')
const _ = require('lodash')
const shortEnglish = require('humanize-duration').humanizer({
  language: 'shortEn',
  languages: {
    shortEn: {
      h: () => 'h'
    }
  },
  units: ['h'],
  spacer: '',
  maxDecimalPoints: 1,
  decimal: '.'
})
const notable = require('./notable')
const users = require('./users')

class Variables {
  async prepareMessage (response, userstate, message) {
github HubSpot / Blazar-Archive / BlazarUI / app / scripts / components / branch-state / shared / BuildDuration.jsx View on Github external
import React, { PropTypes } from 'react';
import humanizeDuration from 'humanize-duration';

const buildDurationHumanizer = humanizeDuration.humanizer({
  delimiter: ' ',
  units: ['m', 's'],
  round: true
});

const shortEnglishHumanizer = humanizeDuration.humanizer({
  language: 'shortEn',
  languages: {
    shortEn: {
      m: () => 'm',
      s: () => 's',
    }
  },
  delimiter: ' ',
  spacer: '',
  units: ['m', 's'],
github JustArchiNET / ASF-ui / src / store / modules / asf.js View on Github external
import * as humanizeDuration from 'humanize-duration';
import Vue from 'vue';
import * as http from '../../plugins/http';

const humanizer = humanizeDuration.humanizer({
	language: 'shortEn',
	units: ['d', 'h', 'm', 's'],
	round: true,
	delimiter: ' ',
	languages: {
		shortEn: {
			d: () => 'd',
			h: () => 'h',
			m: () => 'm',
			s: () => 's'
		}
	}
});

export const UPDATECHANNEL = {
	NONE: 0,
github HubSpot / Blazar-Archive / BlazarUI / app / scripts / components / branch-state / shared / BuildDuration.jsx View on Github external
import React, { PropTypes } from 'react';
import humanizeDuration from 'humanize-duration';

const buildDurationHumanizer = humanizeDuration.humanizer({
  delimiter: ' ',
  units: ['m', 's'],
  round: true
});

const shortEnglishHumanizer = humanizeDuration.humanizer({
  language: 'shortEn',
  languages: {
    shortEn: {
      m: () => 'm',
      s: () => 's',
    }
  },
  delimiter: ' ',
  spacer: '',
  units: ['m', 's'],
  round: true
});

const BuildDuration = ({startTimestamp, endTimestamp, abbreviateUnits}) => {
  const duration = endTimestamp - startTimestamp;
  const formattedDuration = abbreviateUnits ? shortEnglishHumanizer(duration) : buildDurationHumanizer(duration);
github tsouza / yajs / src / bench / bench.ts View on Github external
import * as AsciiTable from 'ascii-table';
import { fork } from 'child_process';
import { Stats } from 'fast-stats';
import * as humanizeDuration from 'humanize-duration';

const time = humanizeDuration.humanizer({
    language: 'shortEn',
    languages: {
      shortEn: {
        y() { return 'y'; },
        mo() { return 'mo'; },
        w() { return 'w'; },
        d() { return 'd'; },
        h() { return 'h'; },
        m() { return 'm'; },
        s() { return 's'; },
        ms() { return 'ms'; },
        decimal: '.',
      },
    },
  });
github sidd / serene / assets / utils.jsx View on Github external
* @param  {Object}  obj
 * @return {Boolean}
 */
export function isEmpty (obj) {
  if (obj !== null && typeof obj !== 'object') {
    throw new Error('`obj` must be an object.')
  }
  return Object.keys(obj).length === 0
}

/**
 * A custom `HumanizeDuration` humanizer that is more terse.
 * @return {Function}
 * @see    https://www.npmjs.com/package/humanize-duration#humanizers
 */
export const humanize = HumanizeDuration.humanizer({
  language: 'short',
  delimiter: ' ',
  spacer: '',
  languages: {
    short: {
      y: () => 'y',
      mo: () => 'mo',
      w: () => 'w',
      d: () => 'd',
      h: () => 'h',
      m: () => 'm',
      s: () => 's',
      ms: () => 'ms'
    }
  }
})

humanize-duration

Convert millisecond durations to English and many other languages.

Unlicense
Latest version published 7 months ago

Package Health Score

79 / 100
Full package analysis

Popular humanize-duration functions