How to use iso8601-duration - 10 common examples

To help you get started, we’ve selected a few iso8601-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 bhj / karaoke-forever / server / Providers / youtube / YouTubeScanner.js View on Github external
return Promise.reject(err)
    }

    // new song
    const { artist, title } = parseMeta(item.snippet.title, parseMetaCfg)

    if (!artist || !title) {
      log(' => skipping: couldn\'t parse artist/title from video title')
      return Promise.reject(new Error('couldn\'t parse artist/title'))
    }

    const song = {
      artist,
      title,
      provider: 'youtube',
      duration: toSeconds(parse(item.contentDetails.duration)),
      providerData: {
        videoId: item.id,
        channel: item.channel,
        publishedAt: item.snippet.publishedAt,
      }
    }

    try {
      const mediaId = await Media.add(song)
      return Promise.resolve(mediaId)
    } catch (err) {
      return Promise.reject(err)
    }
  }
github kudos / combine.fm / lib / services / youtube / index.js View on Github external
export async function lookupId(id) {
  const path = `/videos?part=snippet%2CcontentDetails&id=${id}&key=${credentials.key}`;
  try {
    const result = await request.get(apiRoot + path);
    const item = result.body.items[0].snippet;

    const duration = toSeconds(ptParse(result.body.items[0].contentDetails.duration));

    const split = item.title.match(/([^-]+)-(.*)/);

    const artist = split[1].trim();
    const name = split[2].match(/^[^([]+/)[0].trim();

    // nodebrainz.luceneSearch('recording', {artist, query: release }, (err, response) => {
    //   const recording = response.recordings[0];
    //   debug(recording.releases[0].media[0].track[0].title)
    //   artist = recording['artist-credit'].name;
    //   release = recording.media;
    // });

    const match = {
      id,
      type: 'album',
github paed01 / bpmn-engine / lib / events / TimerEvent.js View on Github external
function resolveDuration() {
    const isoDuration = executionContext.resolveExpression(duration);
    return iso8601duration.toSeconds(iso8601duration.parse(isoDuration)) * 1000;
  }
github paed01 / bpmn-engine / lib / eventDefinitions / TimerEventDefinition.js View on Github external
function isoToMs(isoDuration) {
    return toSeconds(parse(isoDuration)) * 1000;
  }
};
github serverless / enterprise-plugin / lib / safeguards / policies / restricted-deploy-times.js View on Github external
module.exports = function restrictedDeployTimesPolicy(policy, service, options = []) {
  const now = moment();

  for (let { time, duration, interval } of Array.isArray(options) ? options : [options]) {
    time = moment(time);
    duration = moment.duration(parse(duration));
    interval = interval && moment.duration(parse(interval));

    while (time.isBefore(now)) {
      const end = time.clone();
      end.add(duration);
      if (end.isAfter(now)) {
        policy.fail(`Deploying on ${now.format('YYYY-MM-DD')} is not allowed`);
        return;
      }
      if (interval) {
        time.add(interval);
      } else {
        break;
      }
    }
  }
github serverless / enterprise-plugin / lib / safeguards / policies / restricted-deploy-times.js View on Github external
module.exports = function restrictedDeployTimesPolicy(policy, service, options = []) {
  const now = moment();

  for (let { time, duration, interval } of Array.isArray(options) ? options : [options]) {
    time = moment(time);
    duration = moment.duration(parse(duration));
    interval = interval && moment.duration(parse(interval));

    while (time.isBefore(now)) {
      const end = time.clone();
      end.add(duration);
      if (end.isAfter(now)) {
        policy.fail(`Deploying on ${now.format('YYYY-MM-DD')} is not allowed`);
        return;
      }
      if (interval) {
        time.add(interval);
      } else {
        break;
      }
    }
  }
  policy.approve();
github paed01 / bpmn-elements / src / eventDefinitions / TimerEventDefinition.js View on Github external
function executeTimer() {
      const isoDuration = timeDuration && environment.resolveExpression(timeDuration, startMessage);
      const timeout = isoDuration ? toSeconds(parse(isoDuration)) * 1000 : 0;

      const startedAt = new Date();
      debug(`<${executionId} (${id})> start timer ${timeout}ms, duration ${isoDuration || 'none'}`);
      timerContent = {...messageContent, isoDuration, timeout, startedAt, state: 'timer'};

      broker.publish('execution', 'execute.timer', cloneContent(timerContent));
      broker.publish('event', 'activity.timer', cloneContent(timerContent));

      timer = setTimeout(completed, timeout);
    }
github Feverqwe / ytWatchBot / src / tools / formatDuration.js View on Github external
const formatDuration = (duration) => {
  let seconds = toSeconds(parse(duration));

  const hours = Math.floor(seconds / 60 / 60);
  seconds -= hours * 60 * 60;
  const minutes = Math.floor(seconds / 60);
  seconds -= minutes * 60;

  const parts = [
    hours,
    minutes,
    seconds
  ];

  if (parts[0] === 0) {
    parts.shift();
  }
github gajus / slonik / src / factories / typeParsers / createIntervalTypeParser.js View on Github external
const intervalParser = (value) => {
  return value === null ? value : durationToSeconds(parseIsoDuration(parseInterval(value).toISOString()));
};
github samuelmaddock / metastream / app / renderer / media / middleware / microdata.ts View on Github external
noscript.each(function(idx: number, elem: any) {
        const node = ctx.state.$!(elem)
        const text = node.text()

        if (text.indexOf('schema.org') === -1) {
          return
        }

        const $ = load(text)

        const metaDuration = $(`meta[itemprop='duration']`).attr('content')
        if (metaDuration) {
          const duration = toSeconds(parse(metaDuration)) * 1000

          if (duration && !isNaN(duration)) {
            ctx.res.duration = duration
          }
        }
      })
    }

iso8601-duration

Node/Js-module for parsing and making sense of ISO8601-durations

MIT
Latest version published 11 months ago

Package Health Score

63 / 100
Full package analysis

Popular iso8601-duration functions