Skip to content

Commit

Permalink
getDateStr and getClockStr takes a default parameter (#11108)
Browse files Browse the repository at this point in the history
  • Loading branch information
gogolxdong authored and Araq committed May 21, 2019
1 parent dc6a4b1 commit 5e552ad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/pure/times.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 5e552ad

Please sign in to comment.