On Thursday, 7 April 2016 at 11:07:35 UTC, Marc Schütz wrote:
On Thursday, 7 April 2016 at 08:06:03 UTC, Puming wrote:
On Thursday, 7 April 2016 at 07:45:06 UTC, yawniek wrote:
what is the way one is supposed to parse e.g. a
double of unixtime (as delived by nginx logs) into a SysTime?
currently i'm creating a wrapper struct around SysTime with
alias this as:
https://gist.github.com/yannick/6caf5a5184beea0c24f35d9d4a4c7783
really ugly imho.
is there a better way to do this?
you mean
http://dlang.org/phobos/std_datetime.html#.SysTime.fromUnixTime ?
That one only accepts `long`, though, so you'd lose sub-second
precision.
Yes, might be due to that standard UnixTime only has second
precision.
For the sub-second part, you need to add a duration like nsecs.
It's still ugly, but you don't need another struct if what you
want is just a SysTime.
SysTime parseNginxTime(string t) {
// assuming the nginx time has precision of nano-seconds.
return SysTime.fromUnixTime(t[0..$-9].to!long)
+ t[$-9..$].to!long.nsecs;
}
The problem though is that SysTime only hode precision to the
hnsec, so the last three digits is actually lost.