Make Time work with std/strformat (#21409)
* Add test case * Remove formatValue template for `Time` It didn't handle empty specifier correctly which caused it to be blank with strformat
This commit is contained in:
parent
e54d3cc418
commit
6d423f1856
2 changed files with 6 additions and 5 deletions
|
|
@ -2109,7 +2109,7 @@ proc format*(dt: DateTime, f: static[string]): string {.raises: [].} =
|
||||||
const f2 = initTimeFormat(f)
|
const f2 = initTimeFormat(f)
|
||||||
result = dt.format(f2)
|
result = dt.format(f2)
|
||||||
|
|
||||||
proc formatValue*(result: var string; value: DateTime, specifier: string) =
|
proc formatValue*(result: var string; value: DateTime | Time, specifier: string) =
|
||||||
## adapter for strformat. Not intended to be called directly.
|
## adapter for strformat. Not intended to be called directly.
|
||||||
result.add format(value,
|
result.add format(value,
|
||||||
if specifier.len == 0: "yyyy-MM-dd'T'HH:mm:sszzz" else: specifier)
|
if specifier.len == 0: "yyyy-MM-dd'T'HH:mm:sszzz" else: specifier)
|
||||||
|
|
@ -2133,10 +2133,6 @@ proc format*(time: Time, f: static[string], zone: Timezone = local()): string
|
||||||
const f2 = initTimeFormat(f)
|
const f2 = initTimeFormat(f)
|
||||||
result = time.inZone(zone).format(f2)
|
result = time.inZone(zone).format(f2)
|
||||||
|
|
||||||
template formatValue*(result: var string; value: Time, specifier: string) =
|
|
||||||
## adapter for `strformat`. Not intended to be called directly.
|
|
||||||
result.add format(value, specifier)
|
|
||||||
|
|
||||||
proc parse*(input: string, f: TimeFormat, zone: Timezone = local(),
|
proc parse*(input: string, f: TimeFormat, zone: Timezone = local(),
|
||||||
loc: DateTimeLocale = DefaultLocale): DateTime
|
loc: DateTimeLocale = DefaultLocale): DateTime
|
||||||
{.raises: [TimeParseError, Defect].} =
|
{.raises: [TimeParseError, Defect].} =
|
||||||
|
|
|
||||||
5
tests/stdlib/t21406.nim
Normal file
5
tests/stdlib/t21406.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import std/[times, strformat]
|
||||||
|
import std/assertions
|
||||||
|
|
||||||
|
doAssert fmt"{getTime()}" == $getTime()
|
||||||
|
doAssert fmt"{now()}" == $now()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue