private static long convertValue(Object o) {
      if (o instanceof String) {
        return MillisIn.valueOf(((String) o).toUpperCase()).millis;
      } else if (o instanceof ReadableDuration) {
        return ((ReadableDuration) o).getMillis();
      } else if (o instanceof Number) {
        return ((Number) o).longValue();
      }
      throw new RuntimeException("Granularity not recognized");
    }
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