mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-02 09:58:01 +00:00
getDateStr and getClockStr takes a default parameter (#11108)
This commit is contained in:
committed by
Andreas Rumpf
parent
dc6a4b1d43
commit
5e552ad3a5
@@ -1280,15 +1280,17 @@ proc `-`*(ti1, ti2: TimeInterval): TimeInterval =
|
||||
|
||||
result = ti1 + (-ti2)
|
||||
|
||||
proc getDateStr*(): string {.rtl, extern: "nt$1", tags: [TimeEffect].} =
|
||||
proc getDateStr*(dt = now()): string {.rtl, extern: "nt$1", tags: [TimeEffect].} =
|
||||
## Gets the current local date as a string of the format ``YYYY-MM-DD``.
|
||||
var dt = now()
|
||||
runnableExamples:
|
||||
echo getDateStr(now() - 1.months)
|
||||
result = $dt.year & '-' & intToStr(ord(dt.month), 2) &
|
||||
'-' & intToStr(dt.monthday, 2)
|
||||
|
||||
proc getClockStr*(): string {.rtl, extern: "nt$1", tags: [TimeEffect].} =
|
||||
proc getClockStr*(dt = now()): string {.rtl, extern: "nt$1", tags: [TimeEffect].} =
|
||||
## Gets the current local clock time as a string of the format ``HH:MM:SS``.
|
||||
var dt = now()
|
||||
runnableExamples:
|
||||
echo getClockStr(now() - 1.hours)
|
||||
result = intToStr(dt.hour, 2) & ':' & intToStr(dt.minute, 2) &
|
||||
':' & intToStr(dt.second, 2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user