diff --git a/lib/internal/http.js b/lib/internal/http.js index 081f13c0b95e91..0065f93fd896f0 100644 --- a/lib/internal/http.js +++ b/lib/internal/http.js @@ -11,8 +11,14 @@ const { const { setUnrefTimeout } = require('internal/timers'); const { PerformanceEntry, notify } = internalBinding('performance'); +let nowCache; let utcCache; +function nowDate() { + if (!nowCache) cache(); + return nowCache; +} + function utcDate() { if (!utcCache) cache(); return utcCache; @@ -20,11 +26,13 @@ function utcDate() { function cache() { const d = new Date(); - utcCache = d.toUTCString(); - setUnrefTimeout(resetCache, 1000 - d.getMilliseconds()); + nowCache = DatePrototypeValueOf(d); + utcCache = DatePrototypeToUTCString(d); + setUnrefTimeout(resetCache, 1000 - DatePrototypeGetMilliseconds(d)); } function resetCache() { + nowCache = undefined; utcCache = undefined; } @@ -47,6 +55,7 @@ function emitStatistics(statistics) { module.exports = { kOutHeaders: Symbol('kOutHeaders'), kNeedDrain: Symbol('kNeedDrain'), + nowDate, utcDate, emitStatistics };