convertBirthdateToYearsOld(person, timezone) { const today = moment().tz(timezone).startOf('day'); const wasBorn = moment(person.date_of_birth.value).tz(timezone).startOf('day'); return today.diff(wasBorn, 'years'); }
validate(token, callback) { // Check token timestamp const ttl = 30 * 1000 * 60; const diff = Moment().diff(Moment(token.iat * 1000)); if (diff > ttl) { return callback(null, false); } callback(null, true, token); }
const validate = function (token, request, callback) { const Moment = require('moment') let decyptToken = require('../users/util/userFunctions').decyptToken // decrypt the token token = decyptToken(token) // Check token timestamp var diff = Moment().diff(Moment(token.iat * 1000)) if (diff > key.tokenExpiry) { return callback(null, false) } return callback(null, true, token) }
get status() { return { name: `${this.config.name}${this.critical ? '' : ' (not critical)'}`, status: this._status, statusPath: this.config.statusPath, type: this.config.type, isTraversable: this.traversable, statusDuration: Math.round(new moment().diff(this._startTime) * constants.TIME_FACTOR), }; }
/** * Check token validity. Token validity window is set to 240 seconds * @param service tokenObject */ let isTokenValid = function (service) { let tokenAge = moment.duration(moment(new Date()).diff(service.lastUpdated)).asSeconds() + TOKEN_INVALIDITY_WINDOW return (tokenAge < service.timeout) }
const run = async (operation, name, timeoutDurationInMs, task) => { log().info({operation, name, timeoutDurationInMs}, `Will try to run operation "${operation}" on "${name}" (timeout: ${timeoutDurationInMs} ms)`) const {start, end} = await store().save(operation, name, timeoutDurationInMs) const remainingTimeInMs = moment(start).add(timeoutDurationInMs, 'milliseconds').diff(moment(new Date())) try { return await pTimeout(task(), remainingTimeInMs, () => { throw Boom.gatewayTimeout(`Operation '${operation}' Timeout: the operation started ${moment(start).fromNow()} did not finish in the given '${timeoutDurationInMs}' ms time it had to ( it should have finished well before ${moment(end).fromNow()}). You are likely to have to either change this timeout because it was not enough, or make some manual operations in your Elasticsearch Cluster`) }) } finally { store().delete(operation, name) } }
isEven(value) { var dateNow = moment(Date.now()); var dateCheck = moment(value); if (sequelize._env.includes("sp") && (dateNow.diff(dateCheck, 'years')) < 18) throw new Error('the client must be over 18 years old'); }
mongoDbStat.db.listCollections(function(names){ for(let name of names) { let name_date=name.name.split("_") if(name_date.length>1) { let date=moment(name_date[1],'YYYYMMDD') if(today.diff(date,'days')>config.dbKeepDays) { mongoDbStat.db.dropCollection(name.name,{},function(err,ret){ console.log("--deleteCollection:"+name.name,ret,err) }) } } } })
const expiresIn = expiresAt => Math.round(moment.duration( moment(expiresAt).diff(moment()) ).asSeconds())
// 判断节点状态 let isStatusOk = (activedAt, maxDowntime) => { return moment().diff(activedAt) <= (maxDowntime * 1000) }
// input start, end, pause // output duration const calculateWorkHours = (start, end, pause) => { // to assign hours to moment objects, we need the diff so current moment is fine const startDate = composeDateObject(start) const endDate = composeDateObject(end) || moment() const duration = moment.duration( endDate.diff(startDate.add({ minutes: pause })) ) return duration }
failedTasks.filter(task => { const now = moment(); const failTime = new moment(task.Status.Timestamp); return now.diff(failTime, 'minutes') < 1; })
async function durationWrapper (checked) { const start = moment(); checked && await checked(); const end = moment(); return moment.duration(end.diff(start)); }
getUserReductionPercentage() { let loyaltyInYears = moment(moment()).diff(this.loyalSince, 'years'); if (loyaltyInYears >= 2) { return 5; } return 0; }
validate(token, callback) { // Check token timestamp const ttl = 30 * 1000 * 60; const diff = Moment().diff(Moment(token.iat * 1000)); if (diff > ttl) { return callback(null, false); } callback(null, true, token); }