From 66ee67bd17f5301fa2e6efe8960e60e3120e7e69 Mon Sep 17 00:00:00 2001 From: Andras Date: Sun, 1 Mar 2020 19:39:37 -0500 Subject: [PATCH] faster gmdate using getSeconds --- lib/phpdate.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/phpdate.js b/lib/phpdate.js index 5e16c57..af9c89f 100644 --- a/lib/phpdate.js +++ b/lib/phpdate.js @@ -225,8 +225,11 @@ function configure( config ) { GmtDate.prototype.getDay = function GmtDate_getDay() { return this.dt.getUTCDay(); }; GmtDate.prototype.getDate = function GmtDate_getDate() { return this.dt.getUTCDate(); }; GmtDate.prototype.getHours = function GmtDate_getHours() { return this.dt.getUTCHours(); }; + // note: GmtDate is 2x slower than Date, because UTC access methods are 6x slower. + // note: if the tz offset coincides in hours, is 10% faster to use getMinutes() GmtDate.prototype.getMinutes = function GmtDate_getMinutes() { return this.dt.getUTCMinutes(); }; - GmtDate.prototype.getSeconds = function GmtDate_getSeconds() { return this.dt.getUTCSeconds(); }; + // note: all timezones are aligned on minute boundaries, use the faster method + GmtDate.prototype.getSeconds = function GmtDate_getSeconds() { return this.dt.getSeconds(); }; var _resultCacheGmt = new ResultCacheRing(); function gmdate( format, timestamp ) {