當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript moment.duration函數代碼示例

本文整理匯總了TypeScript中moment.duration函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript duration函數的具體用法?TypeScript duration怎麽用?TypeScript duration使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了duration函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: processOptions

  /* Options
  ------------------------------------------------------------------------------------------------------------------*/


  // Parses various options into properties of this object
  processOptions() {
    let slotDuration = this.opt('slotDuration')
    let snapDuration = this.opt('snapDuration')
    let input

    slotDuration = moment.duration(slotDuration)
    snapDuration = snapDuration ? moment.duration(snapDuration) : slotDuration

    this.slotDuration = slotDuration
    this.snapDuration = snapDuration
    this.snapsPerSlot = slotDuration / snapDuration // TODO: ensure an integer multiple?

    // might be an array value (for TimelineView).
    // if so, getting the most granular entry (the last one probably).
    input = this.opt('slotLabelFormat')
    if ($.isArray(input)) {
      input = input[input.length - 1]
    }

    this.labelFormat = input ||
      this.opt('smallTimeFormat') // the computed default

    input = this.opt('slotLabelInterval')
    this.labelInterval = input ?
      moment.duration(input) :
      this.computeLabelInterval(slotDuration)
  }
開發者ID:enhazappe,項目名稱:fullcalendar,代碼行數:32,代碼來源:TimeGrid.ts

示例2: run

    public async run(msg: CommandMessage): Promise<Message | Message[]> {
        if (msg.channel instanceof TextChannel &&
            !msg.channel.permissionsFor(this.client.user).has('SEND_MESSAGES')) {
            return
        }

        const statsDisplay = stripIndents`
            Guilds: ${this.client.guilds.size}
            Channels: ${this.client.channels.size}
            Users: ${this.client.guilds.map((g: Guild) => g.memberCount).reduce((a, b) => a + b)}
        `

        if (msg.channel instanceof TextChannel &&
            !msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) {
            return msg.say(stripIndents`
                **${this.client.user.username} Statistics**
                **Uptime**
                ${moment.duration(this.client.uptime).humanize()}
                **Memory Usage**
                ${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)}MB
                **General Stats**
                ${statsDisplay}
            `)
        }

        return msg.embed(
            new RichEmbed()
                .setTitle(`${this.client.user.username} Statistics`)
                .setThumbnail(this.client.user.displayAvatarURL)
                .addField('Uptime', moment.duration(this.client.uptime).humanize(), true)
                .addField('Memory Usage', `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)}MB`, true)
                .addField('General Stats', statsDisplay, true)
        )
    }
開發者ID:tinnvec,項目名稱:stonebot,代碼行數:34,代碼來源:stats.ts

示例3:

export const init = (props: ITimeUtilsInitProps) => {
  backgroundDuration = moment
    .duration(props.backgroundTime, 'minutes')
    .asMilliseconds()
  modalDuration = moment.duration(props.modalTime, 'minutes').asMilliseconds()
  defaultCallback = props.defaultCallback
  hideModal = props.hideModal
  onTimerEnd = props.onTimerEnd
}
開發者ID:appirio-digital,項目名稱:react-native-session-timer-modal,代碼行數:9,代碼來源:utils.ts

示例4: it

 it("should create the correct action to set time window settings", function() {
   const payload: timewindow.TimeScale = {
     windowSize: moment.duration(10, "s"),
     windowValid: moment.duration(10, "s"),
     sampleSize: moment.duration(10, "s"),
   };
   assert.deepEqual(
     timewindow.setTimeScale(payload),
     { type: timewindow.SET_SCALE, payload },
   );
 });
開發者ID:duzhanyuan,項目名稱:cockroach,代碼行數:11,代碼來源:timewindow.spec.ts

示例5: findId

 (item: RegimenItem): RegimenItemCalendarRow => {
   const uuid = findId(index, "Sequence", item.sequence_id);
   const sequence = findSequence(index, uuid);
   const { time_offset } = item;
   const d = moment.duration(time_offset);
   const { name } = sequence.body;
   const color = sequence.body.color || randomColor();
   const hhmm = moment({ hour: d.hours(), minute: d.minutes() }).format(FMT);
   const day = Math.floor(moment.duration(time_offset).asDays()) + 1;
   return { name, hhmm, color, day, dispatch, regimen, item, sortKey: time_offset };
 };
開發者ID:RickCarlino,項目名稱:farmbot-web-app,代碼行數:11,代碼來源:state_to_props.ts

示例6: computeSnapTime

 // Given a row number of the grid, representing a "snap", returns a time (Duration) from its start-of-day
 computeSnapTime(snapIndex) {
   let slots = this.slots
   if (slots && this.snapOnSlots) {
     let start = this.view.calendar.msToUtcMoment(this.dateProfile.renderUnzonedRange.startMs)
     let beginTime = start.clone()
     let rowTime = start.clone().time(slots[Math.min(snapIndex, slots.length - 1)].start)
     return moment.duration(rowTime.diff(beginTime))
   } else {
     return moment.duration(this.dateProfile.minTime + this.snapDuration * snapIndex)
   }
 }
開發者ID:kleisauke,項目名稱:fullcalendar,代碼行數:12,代碼來源:TimeGrid.ts

示例7: multiplyDuration

export function multiplyDuration(dur, n) {
  let months

  if (durationHasTime(dur)) {
    return moment.duration(dur * n)
  }
  months = dur.asMonths()
  if (Math.abs(months) >= 1 && isInt(months)) {
    return moment.duration({ months: months * n })
  }
  return moment.duration({ days: dur.asDays() * n })
}
開發者ID:enhazappe,項目名稱:fullcalendar,代碼行數:12,代碼來源:util.ts

示例8: buildDateIncrement

  // Compute the duration value that should be added/substracted to the current date
  // when a prev/next operation happens.
  buildDateIncrement(fallback) {
    let dateIncrementInput = this.opt('dateIncrement')
    let customAlignment

    if (dateIncrementInput) {
      return moment.duration(dateIncrementInput)
    } else if ((customAlignment = this.opt('dateAlignment'))) {
      return moment.duration(1, customAlignment)
    } else if (fallback) {
      return fallback
    } else {
      return moment.duration({ days: 1 })
    }
  }
開發者ID:caseyjhol,項目名稱:fullcalendar,代碼行數:16,代碼來源:DateProfileGenerator.ts

示例9: getMomentDuration

export function getMomentDuration(timeSpan: string): Duration | null {
    const
        litRegex = /((\d*)\.)?(\d{2}):(\d{2}):(\d{2})(\.(\d{0,3}))?/,
        isoRegex = /^P(([\d\.]+)Y)?(([\d\.]+)M)?(([\d\.]+)D)?T(([\d\.]+)H)?(([\d\.]+)M)?(([\d\.]+)S)?$/;

    let matches: RegExpMatchArray | null,
        options: DurationInputObject | undefined;

    if (matches = timeSpan.match(isoRegex)) {
        options = {
            years: matches[1] ? parseFloat(matches[2]) : 0,
            months: matches[3] ? parseFloat(matches[4]) : 0,
            days: matches[5] ? parseFloat(matches[6]) : 0,
            hours: matches[7] ? parseFloat(matches[8]) : 0,
            minutes: matches[9] ? parseFloat(matches[10]) : 0,
            seconds: matches[11] ? parseFloat(matches[12]) : 0
        };
    }
    else if (matches = timeSpan.match(litRegex)) {
        options = {
            milliseconds: matches[7] ? parseInt(matches[7], 10) : 0,
            seconds: matches[5] ? parseInt(matches[5], 10) : 0,
            minutes: matches[4] ? parseInt(matches[4], 10) : 0,
            hours: matches[3] ? parseInt(matches[3], 10) : 0,
            days: matches[2] ? parseInt(matches[2], 10) : 0
        };
    }

    return options ?
        moment.duration(options) :
        null;
}
開發者ID:spatools,項目名稱:komoment,代碼行數:32,代碼來源:core.ts

示例10: transform

    transform(value: number, args?: any): any {

        if (isNaN(Number.parseInt(value as any))) {
            return value;
        }

        const leftmostPair = [];

        const time  = moment.duration(value, "milliseconds");
        const order = ["years", "months", "days", "hours", "minutes", "seconds", "milliseconds"];
        const short = ["y", "m", "d", "h", "min", "s", "ms"];


        for (let i = 0; i < order.length; i++) {

            const amount = time.get(order[i] as any);

            if (amount > 0) {
                leftmostPair.push(amount + short[i]);
            }

            if (leftmostPair.length >= 2) {
                break;
            }

        }

        return leftmostPair.join(" ");
    }
開發者ID:hmenager,項目名稱:composer,代碼行數:29,代碼來源:execution-duration.pipe.ts


注:本文中的moment.duration函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。