Convert duration to years?

Nestor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 15 00:40:37 PST 2017


I cleaned up the function a little, but it still feels like a 
hack:

uint getAge(uint yyyy, uint mm, uint dd) {
   import std.datetime;
   SysTime t = Clock.currTime;
   ubyte correction = 0;
   if(
     (t.month < mm) ||
     ( (t.month == mm) && (t.day < dd) )
   ) correction += 1;
   return (t.year - yyyy - correction);
}

Isn't there anything better?


More information about the Digitalmars-d-learn mailing list