本文整理汇总了TypeScript中moment.isDuration函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isDuration函数的具体用法?TypeScript isDuration怎么用?TypeScript isDuration使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isDuration函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
parse: function(eventInput, source) {
if (
isTimeString(eventInput.start) || moment.isDuration(eventInput.start) ||
isTimeString(eventInput.end) || moment.isDuration(eventInput.end)
) {
return RecurringEventDef.parse(eventInput, source)
} else {
return SingleEventDef.parse(eventInput, source)
}
}
示例2: computeRangeAs
// Computes the number of units (like "hours") in the given range.
// Range can be a {start,end} object, separate start/end args, or a Duration.
// Results are based on Moment's .as() and .diff() methods, so results can depend on internal handling
// of month-diffing logic (which tends to vary from version to version).
function computeRangeAs(unit, start, end) {
if (end != null) { // given start, end
return end.diff(start, unit, true)
} else if (moment.isDuration(start)) { // given duration
return start.as(unit)
} else { // given { start, end } range object
return start.end.diff(start.start, unit, true)
}
}
示例3: function
newMomentProto.time = function(time) {
// Fallback to the original method (if there is one) if this moment wasn't created via FullCalendar.
// `time` is a generic enough method name where this precaution is necessary to avoid collisions w/ other plugins.
if (!this._fullCalendar) {
return oldMomentProto.time.apply(this, arguments)
}
if (time == null) { // getter
return moment.duration({
hours: this.hours(),
minutes: this.minutes(),
seconds: this.seconds(),
milliseconds: this.milliseconds()
})
} else { // setter
this._ambigTime = false // mark that the moment now has a time
if (!moment.isDuration(time) && !moment.isMoment(time)) {
time = moment.duration(time)
}
// The day value should cause overflow (so 24 hours becomes 00:00:00 of next day).
// Only for Duration times, not Moment times.
let dayHours = 0
if (moment.isDuration(time)) {
dayHours = Math.floor(time.asDays()) * 24
}
// We need to set the individual fields.
// Can't use startOf('day') then add duration. In case of DST at start of day.
return this.hours(dayHours + time.hours())
.minutes(time.minutes())
.seconds(time.seconds())
.milliseconds(time.milliseconds())
}
}
示例4:
export const formatCountdown = (countdown: Duration) => {
let result = ''
if (countdown && moment.isDuration(countdown)) {
let minutes: any = countdown.minutes()
let seconds: any = countdown.seconds()
if (minutes < 10) {
minutes = `0${minutes}`
}
if (seconds < 10) {
seconds = `0${seconds}`
}
result = `${minutes}:${seconds}`
}
return result
}
示例5: coerce
{
name: 'duration',
coerce(value: any, state: State, options: ValidationOptions) {
try {
if (typeof value === 'string' || typeof value === 'number') {
return ensureDuration(value);
}
} catch (e) {
return this.createError('duration.parse', { value, message: e.message }, state, options);
}
return value;
},
pre(value: any, state: State, options: ValidationOptions) {
if (!isDuration(value)) {
return this.createError('duration.base', { value }, state, options);
}
return value;
},
rules: [anyCustomRule],
},
{
name: 'number',
base: Joi.number(),
coerce(value: any, state: State, options: ValidationOptions) {
// If value isn't defined, let Joi handle default value if it's defined.
if (value === undefined) {
return value;