@Override
    public long truncate(final long t) {
      final long duration = getDurationMillis();
      long offset = t % duration - origin % duration;
      if (offset < 0) {
        offset += duration;
      }
      return t - offset;
    }
UDFDateFloor.

Abstract class that converts a timestamp to a timestamp with a given granularity.
ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateFloor.java