Hi,
Nim told me it can't find times.now(), which is documented here:
This small examples fails to compile for me:
import times
proc info(msg: string): void {.nimcall, gcsafe.} =
echo($now() & " INFO " & msg)
info("Hello World!")
with error:
testnow.nim(4, 9) Error: undeclared identifier: 'now'
And my Nim version:
C:>nim --version
Nim Compiler Version 0.17.2 (2017-09-07) [Windows: amd64]
Copyright (c) 2006-2017 by Andreas Rumpf
What am I doing wrong?
Since the doc has "Deprecated since v...", "Available since v..." would be useful too; I assumed "now()" existed for ever.
Anyway, I found the local doc folder, and it seems the equivalent in 0.17.2 is "getLocalTime(getTime())". Unfortunately, "getLocalTime()" is deprecated. How do I write this so it works without deprecation in 0.17.2 AND 0.18.0?
import times
proc nows(): string =
when false:
$now()
else:
$getLocalTime(getTime())
proc info(msg: string): void {.nimcall, gcsafe.} =
echo(nows() & " INFO " & msg)
info("Hello World!")
like this?
import times
proc now(): string = # module.now() won't conflict with times.now
when NimVersion == "0.17.2":
$getLocalTime(getTime())
else:
$times.now()
proc info(msg: string) = echo(now(), " INFO ", msg)
info("Hello world")
But when I did simply this, it returned like
import times
echo getTime()
My Nim version is still 0.17.2, because some of there are some deprecated JSON procs, I need to be careful for upgrading Nim version