From f86ca8948ad858620bb959735ecf3ea4c6dc2f4a Mon Sep 17 00:00:00 2001 From: MaleDong Date: Fri, 20 Jul 2018 15:55:27 +0800 Subject: [PATCH] util: Fix number format for `pad` `pad` is now using `toString(10)`, actually we don't need to do this. As for https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString, `toString(N)` is a radix converter, which isn't proper here for time conversion. PR-URL: https://github.com/nodejs/node/pull/21906 Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Sam Ruby --- lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 16a31eade17077..7707a7c767254d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1301,7 +1301,7 @@ function isPrimitive(arg) { } function pad(n) { - return n < 10 ? `0${n.toString(10)}` : n.toString(10); + return n.toString().padStart(2, '0'); } const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',