private Object evaluateDate(DeferredObject[] arguments) throws UDFArgumentLengthException,
      HiveException, UDFArgumentTypeException, UDFArgumentException {
    if (arguments.length != 2) {
      throw new UDFArgumentLengthException("trunc() requires 2 argument, got " + arguments.length);
    }

    if (arguments[0].get() == null || arguments[1].get() == null) {
      return null;
    }

    if (textConverter2 != null) {
      fmtInput = textConverter2.convert(arguments[1].get()).toString();
    }

    Date d;
    switch (inputType1) {
    case STRING:
      String dateString = textConverter1.convert(arguments[0].get()).toString();
      d = DateParser.parseDate(dateString);
      if (d == null) {
        return null;
      }
      break;
    case TIMESTAMP:
      Timestamp ts =
          ((TimestampWritableV2) timestampConverter.convert(arguments[0].get())).getTimestamp();
      d = Date.ofEpochMilli(ts.toEpochMilli());
      break;
    case DATE:
      DateWritableV2 dw = (DateWritableV2) dateWritableConverter.convert(arguments[0].get());
      d = dw.get();
      break;
    default:
      throw new UDFArgumentTypeException(0,
          "TRUNC() only takes STRING/TIMESTAMP/DATEWRITABLE types, got " + inputType1);
    }

    if (evalDate(d) == null) {
      return null;
    }

    output.set(date.toString());
    return output;
  }
GenericUDFTrunc.

Returns the first day of the month which the date belongs to. The time part of the date will be
ignored.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTrunc.java