On Sunday, 15 January 2017 at 08:40:37 UTC, Nestor wrote:
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?

It doesn't feel like a hack to me, because it's simple and correct code that comply with the common definition of a person's age. The only inaccuracy I can think of is about people born on February 29th...

Reply via email to