Counting time difference.

holo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 3 14:27:07 PST 2016


Hello

I'm trying to count time difference to count time for how long 
instance is running. Here is how am i doing it:


import std.stdio, sigv4, kxml.xml, awsxml;
import std.datetime;
import std.string;



void main()
{
     SigV4 req = new SigV4;
     IfResult result = req.go;
     AwsXml instancesData = new AwsXml(result.retResult);
     auto instsData =  instancesData.getInstancesData;


     foreach(instData; instsData)
     {



         auto currentTime = Clock.currTime();
    //     auto currentStrTime = 
currentTime.toISOExtString().split(".")[0];
    //     auto currTime = 
SysTime.fromISOExtString(currentStrTime);

         auto launchStrTime = instData.instanceLaunchTime;
         auto launchTime = SysTime.fromISOExtString(launchStrTime);

         auto diff = currentTime - launchTime;

         auto zagadka = launchTime + diff;




         writeln(instData.instanceId ~ " " ~ instData.instanceName 
~ " " ~ instData.instanceState ~ " " ~ 
instData.instanceLaunchTime ~ " " ~ instData.instanceReason);
         writeln(launchTime);
         writeln(currentTime);
         writeln(diff);
         writeln(zagadka);
     }
}

but the results do not match (launchTime + diff != currentTime)


...

2015-Mar-17 14:32:24Z
2016-Feb-03 23:21:41.2374511
46 weeks, 1 day, 7 hours, 49 minutes, 17 secs, 237 ms, 451 μs, 
and 1 hnsec
2016-Feb-03 22:21:41.2374511Z


When i start same program on server in different timezone 
difference is much higher (more than hour). Why it is happening? 
Timezones shouldnt have influence on such equation.

//holo


More information about the Digitalmars-d-learn mailing list