From 72a2f418c8156eefa40532742768a21cdaa9542b Mon Sep 17 00:00:00 2001 From: Kevin Jin Date: Sun, 27 Sep 2015 10:41:58 -0400 Subject: [PATCH 1/3] Pass through unrecognized directives For compatibility with strftime() on Unix, preserve the percent sign for unrecognized directives when appending to resultString. --- strftime.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strftime.js b/strftime.js index d34ad58..8deb8b1 100644 --- a/strftime.js +++ b/strftime.js @@ -494,6 +494,8 @@ break; default: + if (isInScope) + resultString += '%'; resultString += format[i]; break; } From 58f5c3fee82a5f48eb6b02349f35ecf3f9133327 Mon Sep 17 00:00:00 2001 From: Kevin Jin Date: Sun, 27 Sep 2015 11:03:32 -0400 Subject: [PATCH 2/3] Support literal percent sign By the spec for strftime(3), '%%' in the format string should be replaced with '%' in the resultString. --- strftime.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/strftime.js b/strftime.js index 8deb8b1..a3420f2 100644 --- a/strftime.js +++ b/strftime.js @@ -227,6 +227,12 @@ // Examples for new Date(0) in GMT + // '%' + // case '%': + case 37: + resultString += '%'; + break; + // 'Thursday' // case 'A': case 65: From f5bb0982211ded427f27ebf8511d7507fea8bd9b Mon Sep 17 00:00:00 2001 From: Kevin Jin Date: Fri, 2 Oct 2015 21:39:02 -0400 Subject: [PATCH 3/3] Consistency with existing code Add test for unrecognized directives to test.js. Add braces around if statement. --- strftime.js | 3 ++- test.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/strftime.js b/strftime.js index a3420f2..8cc8f35 100644 --- a/strftime.js +++ b/strftime.js @@ -500,8 +500,9 @@ break; default: - if (isInScope) + if (isInScope) { resultString += '%'; + } resultString += format[i]; break; } diff --git a/test.js b/test.js index 66db148..17efa56 100755 --- a/test.js +++ b/test.js @@ -121,7 +121,8 @@ assert.format('%y', '11'); assert.format('%Z', null, 'GMT'); assert.format('%z', null, '+0000'); assert.format('%:z', null, '+00:00'); -assert.format('%%', '%'); // any other char +assert.format('%%', '%'); // literal percent sign +assert.format('%g', '%g'); // unrecognized directive assert.format('%F %T', null, '1970-01-01 00:00:00', new Date(0)); assert.format('%U', null, '12', new Date('2017-03-25 00:00:00 +0000')); assert.format('%U', null, '13', new Date('2017-03-26 00:00:00 +0000'));