/* 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) }
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) ) }
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 }
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 }, ); });
(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 }; };
// 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) } }
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 }) }
// 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 }) } }
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; }
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(" "); }