UNPKG

synapse-react-client

Version:

[![Build Status](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client.svg?branch=main)](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synaps

27 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFriendlyPreciseDuration = void 0; var tslib_1 = require("tslib"); var moment_1 = (0, tslib_1.__importDefault)(require("moment")); var getPart = function (n, unitDescriptor) { if (n > 0) { return n + " " + unitDescriptor + (n > 1 ? 's' : '') + " "; } return ''; }; /** * Return a "humanized" version of the given time, where the time given is in timeUnits. * moment.humanize() precision is unsatisfactory for our purposes. */ var getFriendlyPreciseDuration = function (time, timeUnits) { var duration = moment_1.default.duration(time, timeUnits); var years = duration.years(); var months = duration.months() % 12; var days = duration.days() % 31; var hours = duration.hours() % 24; var minutes = duration.minutes() % 60; var seconds = duration.seconds() % 60; return ("" + getPart(years, 'year') + getPart(months, 'month') + getPart(days, 'day') + getPart(hours, 'hour') + getPart(minutes, 'minute') + getPart(seconds, 'second')).trim(); }; exports.getFriendlyPreciseDuration = getFriendlyPreciseDuration; //# sourceMappingURL=getFriendlyPreciseDuration.js.map