Fix strftime/1 and strflocaltime/1 to allow an empty result (#3670)

These functions failed with "unknown system failure" whenever strftime()
returned 0 for a non-empty format, but 0 also means the format expands to
an empty string, as %p does in a locale without AM/PM.

Prepend a character to the format and trim it from the result, so that 0
can only mean the result is too long. Now 0 | strflocaltime("%p") gives
"" in fr_FR.UTF-8, and a result that is still too long fails with
"result too long" error instead. The size limit is unchanged.
This commit is contained in:
Doha Nam authored and GitHub committed 2026-10-13 16:47:58 +09:00
1 parent 80fc7a169d
commit 6b53f80311
3 files changed
+37 -10

No files matched your search

+16
View File
@@ -1945,6 +1945,22 @@ try ["OK", strflocaltime({})] catch ["KO", .]
0
["KO","strflocaltime/1 requires a string format"]
[strftime("", " %Y ")]
0
["", " 1970 "]
try strftime("%c" * 10) catch .
0
"strftime/1: result too long"
[strflocaltime("", " %Y ")]
[2015,2,5,23,51,47,4,63]
["", " 2015 "]
try strflocaltime("%c" * 10) catch .
[2015,2,5,23,51,47,4,63]
"strflocaltime/1: result too long"
[strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]
"2015-03-05T23:51:47Z"
[[2015,2,5,23,51,47,4,63],1425599507]