Skip to content

Commit bdb7c82

Browse files
authored
fixes a critical times.nim bug reported on IRC [backport] (#13216)
1 parent b355ef2 commit bdb7c82

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/pure/strformat.nim

+3
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,9 @@ when isMainModule:
717717
var tm = fromUnix(0)
718718
discard &"{tm}"
719719

720+
var noww = now()
721+
check &"{noww}", $noww
722+
720723
# Unicode string tests
721724
check &"""{"αβγ"}""", "αβγ"
722725
check &"""{"αβγ":>5}""", " αβγ"

lib/pure/times.nim

+3-2
Original file line numberDiff line numberDiff line change
@@ -2339,9 +2339,10 @@ proc format*(dt: DateTime, f: static[string]): string {.raises: [].} =
23392339
const f2 = initTimeFormat(f)
23402340
result = dt.format(f2)
23412341

2342-
template formatValue*(result: var string; value: DateTime, specifier: string) =
2342+
proc formatValue*(result: var string; value: DateTime, specifier: string) =
23432343
## adapter for strformat. Not intended to be called directly.
2344-
result.add format(value, specifier)
2344+
result.add format(value,
2345+
if specifier.len == 0: "yyyy-MM-dd'T'HH:mm:sszzz" else: specifier)
23452346

23462347
proc format*(time: Time, f: string, zone: Timezone = local()): string
23472348
{.raises: [TimeFormatParseError].} =

0 commit comments

Comments
 (0)