import times
echo($getTzname()) #this yields "WILDABBR" but we expect "EST" or "GMT" etc.
Anyone else get this problem or know how to work around it? Anyone know how to set a timezone, to tell times to convert a time to xyz timezone?
After an import strutils it works for me and I get good output:
(nonDST: GMT, DST: GMT)
Any more information about your system, ggibson?
Strange it works for you! That gives me hope.
Thanks novist; I've updated the example to import strutils which I forgot.
Here is my exact output of the above example:
(nonDST: WILDABBR, DST: WILDABBR)
My system is an early 2011 macbook pro running MacOSX Yosemite (the latest at time of writing). I'm using nim 0.10.3 (2015-3-3) so maybe that's it? Does anyone know what timezone setting this is trying to use?
I can print my current timezone setting via the terminal:
$sudo systemsetup -gettimezone Time Zone: America/Detroit
Or the linux way:
$date +%Z EDT
So what gives?
UPDATE
Since the mac terminal way of retrieving timezone requires root, then I tried running the example as root, but there was no difference.
Well I just investigated a bit and this works:
var
timezone {.importc, header: "<time.h>".}: int
tzname {.importc, header: "<time.h>" .}: array[0..1, cstring]
proc tzset*() {.importc, header: "<time.h>".}
tzset()
echo timezone
echo tzname[0]
echo tzname[1]
which is pointing out the problem with your code and it will work doing it like this:
import posix, times
tzset()
echo getTzname()
I am not sure about how that should be handled. At least it should be better documented.