Determining if currently set time is in daylight savings or not

This seems to work:

  // First, get the year:
  int yy = year - 2000;
  // yy should be e.g. 16 for AD 2016

  // Then calculate:
  int x = (yy + yy/4 + 2) % 7;

  // Then, if date/time is in the period from
  //   02:00:00 on day (14 - x) of March
  // through
  //   00:59:59 on day (7 - x) of November
  // then US Daylight Saving Time is in effect.