Search in sources :

Example 1 with DateTimeFormat

use of com.actiontech.dble.plan.common.time.DateTimeFormat in project dble by actiontech.

the class ItemFuncStrToDate method valDatetime.

@Override
protected boolean valDatetime(MySQLTime ltime, long fuzzyDate) {
    DateTimeFormat dateTimeFormat = new DateTimeFormat();
    String val = args.get(0).valStr();
    String format = args.get(1).valStr();
    boolean nullDate = false;
    if (args.get(0).isNullValue() || args.get(1).isNullValue())
        nullDate = true;
    if (!nullDate) {
        nullValue = false;
        dateTimeFormat.setFormat(format);
        if (MyTime.extractDateTime(dateTimeFormat, val, ltime, cachedTimestampType, "datetime") || ((fuzzyDate & MyTime.TIME_NO_ZERO_DATE) != 0 && (ltime.getYear() == 0 || ltime.getMonth() == 0 || ltime.getDay() == 0)))
            nullDate = true;
    }
    if (!nullDate) {
        ltime.setTimeType(cachedTimestampType);
        if (cachedTimestampType == MySQLTimestampType.MYSQL_TIMESTAMP_TIME && ltime.getDay() != 0) {
            /*
                 * Day part for time type can be nonzero value and so we should
                 * add hours from day part to hour part to keep valid time
                 * value.
                 */
            ltime.setHour(ltime.getHour() + ltime.getDay() * 24);
            ltime.setDay(0);
        }
        return false;
    }
    if (val != null && (fuzzyDate & MyTime.TIME_NO_ZERO_DATE) != 0) /* warnings */
    {
        LOGGER.info("str_to_date value:" + val + " is wrong value for format:" + format);
    }
    return (nullValue = true);
}
Also used : DateTimeFormat(com.actiontech.dble.plan.common.time.DateTimeFormat)

Example 2 with DateTimeFormat

use of com.actiontech.dble.plan.common.time.DateTimeFormat in project dble by actiontech.

the class ItemFuncDateFormat method valStr.

@Override
public String valStr() {
    String format;
    MySQLTime lTime = new MySQLTime();
    int size;
    if (!isTimeFormat) {
        if (getArg0Date(lTime, MyTime.TIME_FUZZY_DATE))
            return null;
    } else {
        if (getArg0Time(lTime))
            return null;
        lTime.setDay(0);
        lTime.setMonth(0);
        lTime.setYear(0);
    }
    if ((format = args.get(1).valStr()) == null || format.length() == 0) {
        nullValue = true;
        return null;
    }
    size = formatLength(format);
    if (size < MyTime.MAX_DATE_STRING_REP_LENGTH)
        size = MyTime.MAX_DATE_STRING_REP_LENGTH;
    DateTimeFormat dateTimeFormat = new DateTimeFormat();
    dateTimeFormat.setFormat(format);
    StringPtr strPtr = new StringPtr("");
    if (!MyTime.makeDateTime(dateTimeFormat, lTime, isTimeFormat ? MySQLTimestampType.MYSQL_TIMESTAMP_TIME : MySQLTimestampType.MYSQL_TIMESTAMP_DATE, strPtr)) {
        return strPtr.get();
    }
    nullValue = true;
    return null;
}
Also used : StringPtr(com.actiontech.dble.plan.common.ptr.StringPtr) MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime) DateTimeFormat(com.actiontech.dble.plan.common.time.DateTimeFormat)

Aggregations

DateTimeFormat (com.actiontech.dble.plan.common.time.DateTimeFormat)2 StringPtr (com.actiontech.dble.plan.common.ptr.StringPtr)1 MySQLTime (com.actiontech.dble.plan.common.time.MySQLTime)1