public static QueryGranularity fromString(String str) {
      String name = str.toUpperCase();
      if (CALENDRIC_GRANULARITIES.containsKey(name)) {
        return CALENDRIC_GRANULARITIES.get(name);
      }
      return new DurationGranularity(convertValue(str), 0);
    }
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