How to use parse-duration - 5 common examples

To help you get started, we’ve selected a few parse-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 jailbreakdiscord / bot / src / discord / utilities / MuteHandler.ts View on Github external
public async mute(
        message: Message,
        member: GuildMember,
        duration: number,
        reason: string
    ) {
        const dbMember = await DBGuildMember.findOne({
            where: { id: member.id }
        });
        const dbGuild = await DBGuild.findOne({
            where: { id: member.guild.id }
        });
        if (!dbMember) await DBGuildMember.createOrUpdate(member, dbGuild!);

        duration = Math.floor(parse(duration) / 60000); // parse to minutes
        console.log(duration);

        await member.addRole(this.muteRole);
        await getPublicLogger().send({
            type: "mute",
            duration,
            member,
            moderator: message.author,
            reason
        });

        // Shorter equivalent of `valueOf` (returns a Unix timestamp).
        let unmuteAt = Math.floor(+new Date() / 1000);

        // Add minutes to the timestamp.
        unmuteAt += duration * 60;
github alexcroox / jira-timer-menubar / renderer / containers / worklog / worklog-container.js View on Github external
onTimeChanged (worklog, editedTime) {
    if (editedTime != '') {
      let ms = parseDuration(editedTime)

      // Is the timer entered valid?
      if (ms > 0)
        this.props.updateWorkLogTime(worklog, Math.round(ms / 1000))
    }

    this.onResetEditTime()
  }
github alexcroox / jira-timer-menubar / renderer / containers / timer / timer-container.js View on Github external
onTimeChanged (timerId, editedTime) {
    if (editedTime != '') {
      let ms = parseDuration(editedTime)

      // Is the timer entered valid?
      if (ms > 0)
        this.props.updateTimer(timerId, ms)
    }

    this.onResetEditTime()
  }
github curioswitch / curiostack / tools / cloudbuild-github / src / webhook.ts View on Github external
console.log(`Found existing build ${build.id}. Cancelling.`);
          cloudbuild.projects.builds.cancel({ projectId, id: build.id });
        });
    }
  } catch (e) {
    console.log(
      'Error fetching existing builds, not cancelling existing builds.',
    );
  }
  console.log(`Starting cloud build for pull request ${pull.number}.`);

  const cloudbuildConfig: Build = config.repos[repo].cloudbuild;
  const sanitizedConfig: Build = cloudbuildConfig.timeout
    ? {
        ...cloudbuildConfig,
        timeout: `${parseDuration(cloudbuildConfig.timeout) /
          MILLIS_IN_SECOND}s`,
      }
    : cloudbuildConfig;

  await cloudbuild.projects.builds.create({
    projectId,
    requestBody: {
      ...sanitizedConfig,
      options: {
        ...sanitizedConfig.options,
        substitutionOption: 'ALLOW_LOOSE',
      },
      substitutions,
      tags,
    },
  });
github shastajs / sutro / src / cacheControl.js View on Github external
const parseNumber = (v) => {
  const n = typeof v === 'number'
    ? v
    : parseDuration(v)
  if (isNaN(n)) throw new Error(`Invalid number: ${v}`)
  return n / 1000
}

parse-duration

convert a human readable duration string to a duration format

MIT
Latest version published 11 months ago

Package Health Score

70 / 100
Full package analysis

Popular parse-duration functions