app.get('/comments/:slug', (request, reply) => { const { slug } = request.params; const user = getUser(request); const providers = user ? null : auth.providers; let query = queries.get_comments; let args = [slug, user ? user.id : -1]; if (isAdmin(user)) { user.admin = true; query = queries.admin_get_comments; args.length = 1; } const date_format = config.get('date_format'); db.all(query, args, (err, comments) => { if (error(err, request, reply)) return; comments.forEach(c => { const m = moment.utc(c.created_at); c.created_at_s = date_format ? m.format(date_format) : m.fromNow(); c.comment = marked(c.comment.trim()); c.author_url = auth.getAuthorUrl(c); }); reply.send({ user, auth: providers, slug, comments }); }); });
tasks.status() .then(frames => { if (frames.length === 0) { console.log('No projects are started right now.'); return; } frames.forEach(frame => console.log(`Project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} is running, started ${moment(frame.start).fromNow().green} (id: ${frame.id})`)); }) .catch(error => Cli.error('Could not read frames.', error));
// 格式化时间 beautyTime(time) { moment.locale('zh-cn'); return moment(time, 'YYYY-MM-DD HH:mm:ss').fromNow(); }
countdowns.map(countdown => [ `» **${countdown._id}** «`, `\tIn #${msg.guild.channel(countdown.channel_id).name} (${msg.guild.channel(countdown.channel_id)})`, `\tExpires **${moment(countdown.expiry_timestamp).fromNow()}**`, ].join("\n"))
const getString = doc => { if (!doc.ts) return '' let now = Date.now() if ((now - doc.ts) < 10 * 60 * 1000) { return moment(doc.ts).fromNow() } else { return moment(doc.ts).calendar() } }
// 会话记录 @computed get sessionList(): Array<Object> { return [...this.sessionListMap.values()].sort(function(a, b) { return b.timestamp - a.timestamp; }).map(function (item) { item.latestTime = moment(item.timestamp).startOf('minute').fromNow(); return item; }); }
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) } }
userDocument.reminders.forEach(reminderDocument => { fields.push({ name: `__${reminderDocument.name}__`, value: `${moment(reminderDocument.expiry_timestamp).fromNow()}`, inline: true, }); });
mem(str => wheretogo(str).then(res => { let arr = res.events // console.log(res.uri) if (!arr.length) return `No events found here 😔 😞` return arr.slice(0, 7).map(e => { return `${(moment(e.start).isBefore(Date.now()) ? `Started ` : `Starts in `) + chalk.green(moment(e.start).fromNow())}: ${chalk.bold(e.n)} @ ${chalk.yellow(e.v)} ${chalk.dim(`(${e.lat}, ${e.lng})`)} ${chalk.dim(JSON.stringify(e.d))} Link: ${e.tktU ? `${chalk.underline(e.tktU)}` : 'no Ticket Link available'} - by ${chalk.bold(e.c)}: ${chalk.underline('https://www.facebook.com/' + e.cId)}` }).join('\n\n') }) )
let cleanup = (ts) => { // Remove close box let closebox = el.querySelector('div.boxclose') closebox.parentNode.removeChild(closebox) // Set time info let time = el.querySelector('span.ts') time.setAttribute('ts', ts) let now = Date.now() if ((now - ts) < 10 * 60 * 1000) { time.innerHTML = moment(ts).fromNow() } else { time.innerHTML = moment(ts).calendar() } }
userDocument.reminders.map(reminderDocument => ({ name: `__${reminderDocument.name}__`, value: `${moment(reminderDocument.expiry_timestamp).fromNow()}`, inline: true, }))
tasks.cancel() .then(frames => { frames.forEach(frame => { if(!frame.resource.new) return console.log(`Cancel project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue}, started ${moment(frame.start).fromNow().green}`) console.log(`Cancel project ${frame.project.magenta} for new ${frame.resource.type} "${(frame.resource.id).blue}", started ${moment(frame.start).fromNow().green}`) }) }) .catch(error => Cli.error(error));
Handlebars.registerHelper('dateFormat', function(context, format) { 'use strict'; if (format === 'fromNow') { return moment(context).fromNow(); } else { return moment(context).format(format); } });
tasks.stop() .then(frames => { frames.forEach(frame => { if(!frame.resource.new) return console.log(`Stopping project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue}, started ${moment(frame.start).fromNow().green} (id: ${frame.id})`) console.log(`Stopping project ${frame.project.magenta} for new ${frame.resource.type} "${(frame.resource.id).blue}", started ${moment(frame.start).fromNow().green} (id: ${frame.id})`) }); }) .catch(error => Cli.error(error));
Handlebars.registerHelper('dateFormat', function(context, format) { 'use strict'; if (format === 'fromNow') { return moment(context).fromNow(); } else { return moment(context).format(format); } });