How to use humanize-duration - 10 common examples

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 Dragory / ZeppelinBot / backend / src / plugins / Post.ts View on Github external
}

    if (repeatUntil && repeatTimes) {
      return this.sendErrorMessage(msg.channel, "You can only use one of -repeat-until or -repeat-times at once");
    }

    if (opts.repeat && !repeatUntil && !repeatTimes) {
      return this.sendErrorMessage(
        msg.channel,
        "You must specify -repeat-until or -repeat-times for repeated messages",
      );
    }

    if (opts.repeat) {
      repeatDetailsStr = repeatUntil
        ? `every ${humanizeDuration(opts.repeat)} until ${repeatUntil.format(DBDateFormat)}`
        : `every ${humanizeDuration(opts.repeat)}, ${repeatTimes} times in total`;
    }

    // Save schedule/repeat information in DB
    if (postAt) {
      if (postAt < moment()) {
        return this.sendErrorMessage(msg.channel, "Post can't be scheduled to be posted in the past");
      }

      await this.scheduledPosts.create({
        author_id: msg.author.id,
        author_name: `${msg.author.username}#${msg.author.discriminator}`,
        channel_id: targetChannel.id,
        content,
        attachments: msg.attachments,
        post_at: postAt.format(DBDateFormat),
github Dragory / ZeppelinBot / backend / src / plugins / Post.ts View on Github external
if (!(targetChannel instanceof TextChannel)) {
      msg.channel.createMessage(errorMessage("Channel is not a text channel"));
      return;
    }

    if (content == null && msg.attachments.length === 0) {
      msg.channel.createMessage(errorMessage("Message content or attachment required"));
      return;
    }

    if (opts.repeat) {
      if (opts.repeat < MIN_REPEAT_TIME) {
        return this.sendErrorMessage(msg.channel, `Minimum time for -repeat is ${humanizeDuration(MIN_REPEAT_TIME)}`);
      }
      if (opts.repeat > MAX_REPEAT_TIME) {
        return this.sendErrorMessage(msg.channel, `Max time for -repeat is ${humanizeDuration(MAX_REPEAT_TIME)}`);
      }
    }

    // If this is a scheduled or repeated post, figure out the next post date
    let postAt;
    if (opts.schedule) {
      // Schedule the post to be posted later
      postAt = this.parseScheduleTime(opts.schedule);
      if (!postAt) {
        return this.sendErrorMessage(msg.channel, "Invalid schedule time");
      }
    } else if (opts.repeat) {
      postAt = moment().add(opts.repeat, "ms");
    }

    // For repeated posts, make sure repeat-until or repeat-times is specified
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 magicdawn / yun-playlist-downloader / ts-src / yun.bin.ts View on Github external
song,
        totalLength: songs.length,
        retryTimeout,
        retryTimes,
        skipExists,
        progress,
      })
    },
    concurrency
  )

  await new Promise(r => {
    process.nextTick(r)
  })

  const dur = humanizeDuration(Date.now() - start, {language: 'zh_CN'})
  console.log('下载完成, 耗时%s', dur)
}
github Dragory / ZeppelinBot / backend / src / plugins / Tags.ts View on Github external
countdown(toDate) {
        if (typeof toDate !== "string") return "";

        const now = moment();
        const target = moment(toDate, "YYYY-MM-DD HH:mm:ss");
        if (!target.isValid()) return "";

        const diff = target.diff(now);
        const result = humanizeDuration(diff, { largest: 2, round: true });
        return diff >= 0 ? result : `${result} ago`;
      },
github HubSpot / Blazar-Archive / BlazarUI / app / scripts / data / RepoBuildApi.js View on Github external
function _parse(resp) {
  if (resp.startTimestamp && resp.endTimestamp) {
    resp.duration = humanizeDuration(resp.endTimestamp - resp.startTimestamp, {round: true});
  }

  return resp;
}
github kestra-io / kestra / ui / src / components / executions / Overview.vue View on Github external
items() {
            const startTs = this.execution.state.histories[0].date;
            const stopTs = this.execution.state.histories[this.execution.state.histories.length - 1].date;
            const delta = ts(stopTs) - ts(startTs);
            const duration = this.$moment.duration(delta);
            const humanDuration = humanizeDuration(duration);
            const stepCount = this.execution.taskRunList ? this.execution.taskRunList.length : 0
            return [
                {key: this.$t('namespace'), value: this.execution.namespace},
                {key: this.$t('flow'), value: this.execution.flowId},
                {key: this.$t('created date'), value: startTs},
                {key: this.$t('updated date'), value: stopTs},
                {key: this.$t('duration'), value: humanDuration},
                {key: this.$t('steps'), value: stepCount},
            ]
        }
    }
github freinbichler / ar-room-availability / src / js / components / activity.js View on Github external
constructor(el) {
    this.start = el.activityBegin;
    this.end = el.activityEnd;
    this.name = el.activityName;
    this.range = window.moment.range(window.moment(this.start), window.moment(this.end));
    this.duration = humanizeDuration(this.range + 0);
  }
}
github JustArchiNET / ASF-ui / src / components / AsfFarmingInfo.vue View on Github external
timeRemaining() {
				if (this.botsFarmingCount === 0) return '-';
				const language = getLocaleForHD();
				return humanizeDuration(this.$store.getters['bots/timeRemaining'] * 1000, { language });
			},
			gamesRemaining() {

humanize-duration

Convert millisecond durations to English and many other languages.

Unlicense
Latest version published 6 months ago

Package Health Score

79 / 100
Full package analysis

Popular humanize-duration functions