From 08eb1a20c3975230aa1fe1c693b0cd1ac7a0752b Mon Sep 17 00:00:00 2001 From: Equim Date: Sun, 21 May 2017 23:33:25 +0800 Subject: [PATCH] docs: apply `Date.now()` to all docs (#988) --- Readme.md | 4 ++-- docs/api/index.md | 8 ++++---- docs/guide.md | 4 ++-- docs/migration.md | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Readme.md b/Readme.md index 25621c1..074cb0c 100644 --- a/Readme.md +++ b/Readme.md @@ -70,9 +70,9 @@ app.use(async (ctx, next) => { // next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion. app.use((ctx, next) => { - const start = new Date(); + const start = Date.now(); return next().then(() => { - const ms = new Date() - start; + const ms = Date.now() - start; console.log(`${ctx.method} ${ctx.url} - ${ms}ms`); }); }); diff --git a/docs/api/index.md b/docs/api/index.md index a2a23a0..a25da8c 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -81,18 +81,18 @@ const app = new Koa(); // x-response-time app.use(async function (ctx, next) { - const start = new Date(); + const start = Date.now(); await next(); - const ms = new Date() - start; + const ms = Date.now() - start; ctx.set('X-Response-Time', `${ms}ms`); }); // logger app.use(async function (ctx, next) { - const start = new Date(); + const start = Date.now(); await next(); - const ms = new Date() - start; + const ms = Date.now() - start; console.log(`${ctx.method} ${ctx.url} - ${ms}`); }); diff --git a/docs/guide.md b/docs/guide.md index c2ee87b..de27ade 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -13,9 +13,9 @@ ```js async function responseTime(ctx, next) { - const start = new Date(); + const start = Date.now(); await next(); - const ms = new Date() - start; + const ms = Date.now() - start; ctx.set('X-Response-Time', `${ms}ms`); } diff --git a/docs/migration.md b/docs/migration.md index 172d877..d6ed25d 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -39,9 +39,9 @@ It is however recommended that you choose to migrate all v1.x middleware as soon ```js // Koa will convert app.use(function *(next) { - const start = new Date(); + const start = Date.now(); yield next; - const ms = new Date() - start; + const ms = Date.now() - start; console.log(`${this.method} ${this.url} - ${ms}ms`); }); ``` @@ -52,9 +52,9 @@ You could do it manually as well, in which case Koa will not convert. const convert = require('koa-convert'); app.use(convert(function *(next) { - const start = new Date(); + const start = Date.now(); yield next; - const ms = new Date() - start; + const ms = Date.now() - start; console.log(`${this.method} ${this.url} - ${ms}ms`); })); ```