public static long daysToMillis(int d, boolean doesTimeMatter) {
    // What we are trying to get is the equivalent of new Date(ymd).getTime() in the local tz,
    // where ymd is whatever d represents. How it "works" is this.
    // First we get the UTC midnight for that day (which always exists, a small island of sanity).
    long utcMidnight = d * MILLIS_PER_DAY;
    // Now we take a local TZ offset at midnight UTC. Say we are in -4; that means (surprise
    // surprise) that at midnight UTC it was 20:00 in local. So far we are on firm ground.
    long utcMidnightOffset = LOCAL_TIMEZONE.get().getOffset(utcMidnight);
    // And now we wander straight into the swamp, when instead of adding, we subtract it from UTC
    // midnight to supposedly get local midnight (in the above case, 4:00 UTC). Of course, given
    // all the insane DST variations, where we actually end up is anyone's guess.
    long hopefullyMidnight = utcMidnight - utcMidnightOffset;
    // Then we determine the local TZ offset at that magical time.
    long offsetAtHM = LOCAL_TIMEZONE.get().getOffset(hopefullyMidnight);
    // If the offsets are the same, we assume our initial jump did not cross any DST boundaries,
    // and is thus valid. Both times flowed at the same pace. We congratulate ourselves and bail.
    if (utcMidnightOffset == offsetAtHM) return hopefullyMidnight;
    // Alas, we crossed some DST boundary. If the time of day doesn't matter to the caller, we'll
    // simply get the next day and go back half a day. This is not ideal but seems to work.
    if (!doesTimeMatter) return daysToMillis(d + 1) - (MILLIS_PER_DAY >> 1);
    // Now, we could get previous and next day, figure our how many hours were inserted or removed,
    // and from which of the days, etc. But at this point our gun is pointing straight at our foot,
    // so let's just go the safe, expensive way.
    Calendar utc = UTC_CALENDAR.get(), local = LOCAL_CALENDAR.get();
    utc.setTimeInMillis(utcMidnight);
    local.set(utc.get(Calendar.YEAR), utc.get(Calendar.MONTH), utc.get(Calendar.DAY_OF_MONTH));
    return local.getTimeInMillis();
  }
@return time in seconds corresponding to this DateWritable
storage-api/src/java/org/apache/hadoop/hive/serde2/io/DateWritable.java