本文整理匯總了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;