private static boolean isCompoundPeriod(Period period) {
      int[] values = period.getValues();
      boolean single = false;
      for (int v : values) {
        if (v > 0) {
          if (single)
            return true;
          single = true;
        }
      }
      return false;
    }
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