From 6e9e150b6a1746df899b68158dd540b4e790eff8 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 33c4cdfff72167..fa96ade26a5954 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1349,7 +1349,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',