Search in sources :

Example 6 with MySQLTime

use of com.actiontech.dble.plan.common.time.MySQLTime 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)

Example 7 with MySQLTime

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

the class FieldTime method compare.

@Override
public int compare(byte[] v1, byte[] v2) {
    if (v1 == null && v2 == null)
        return 0;
    try {
        String sval1 = MySQLcom.getFullString(javaCharsetName, v1);
        String sval2 = MySQLcom.getFullString(javaCharsetName, v2);
        MySQLTime ltime1 = new MySQLTime();
        MySQLTime ltime2 = new MySQLTime();
        MyTime.strToTimeWithWarn(sval1, ltime1);
        MyTime.strToTimeWithWarn(sval2, ltime2);
        return ltime1.getCompareResult(ltime2);
    } catch (Exception e) {
        Field.LOGGER.info("String to biginteger exception!", e);
        return -1;
    }
}
Also used : MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with MySQLTime

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

the class ItemExtract method valInt.

@Override
public BigInteger valInt() {
    MySQLTime ltime = new MySQLTime();
    int weekFormat;
    long neg;
    if (dateValue) {
        if (getArg0Date(ltime, MyTime.TIME_FUZZY_DATE))
            return BigInteger.ZERO;
        neg = 1;
    } else {
        if (getArg0Time(ltime))
            return BigInteger.ZERO;
        neg = ltime.isNeg() ? -1 : 1;
    }
    switch(intType) {
        case YEAR:
            return BigInteger.valueOf(ltime.getYear());
        case YEAR_MONTH:
            return BigInteger.valueOf(ltime.getYear() * 100L + ltime.getMonth());
        case QUARTER:
            return BigInteger.valueOf((ltime.getMonth() + 2) / 3);
        case MONTH:
            return BigInteger.valueOf(ltime.getMonth());
        case WEEK:
            {
                weekFormat = MyTime.WEEK_MONDAY_FIRST;
                long ret = MyTime.calcWeek(ltime, MyTime.weekMode(weekFormat), new LongPtr(0));
                return BigInteger.valueOf(ret);
            }
        case DAY:
            return BigInteger.valueOf(ltime.getDay());
        case DAY_HOUR:
            return BigInteger.valueOf((ltime.getDay() * 100L + ltime.getHour()) * neg);
        case DAY_MINUTE:
            return (BigInteger.valueOf((ltime.getDay() * 10000L + ltime.getHour() * 100L + ltime.getMinute()) * neg));
        case DAY_SECOND:
            return BigInteger.valueOf((ltime.getDay() * 1000000L + (ltime.getHour() * 10000L + ltime.getMinute() * 100 + ltime.getSecond())) * neg);
        case HOUR:
            return BigInteger.valueOf(ltime.getHour() * neg);
        case HOUR_MINUTE:
            return BigInteger.valueOf((ltime.getHour() * 100 + ltime.getMinute()) * neg);
        case HOUR_SECOND:
            return BigInteger.valueOf((ltime.getHour() * 10000 + ltime.getMinute() * 100 + ltime.getSecond()) * neg);
        case MINUTE:
            return BigInteger.valueOf(ltime.getMinute() * neg);
        case MINUTE_SECOND:
            return BigInteger.valueOf((ltime.getMinute() * 100 + ltime.getSecond()) * neg);
        case SECOND:
            return BigInteger.valueOf(ltime.getSecond() * neg);
        case MICROSECOND:
            return BigInteger.valueOf(ltime.getSecondPart() * neg);
        case DAY_MICROSECOND:
            return BigInteger.valueOf(((ltime.getDay() * 1000000L + ltime.getHour() * 10000L + ltime.getMinute() * 100 + ltime.getSecond()) * 1000000L + ltime.getSecondPart()) * neg);
        case HOUR_MICROSECOND:
            return BigInteger.valueOf(((ltime.getHour() * 10000L + ltime.getMinute() * 100 + ltime.getSecond()) * 1000000L + ltime.getSecondPart()) * neg);
        case MINUTE_MICROSECOND:
            return BigInteger.valueOf((((ltime.getMinute() * 100 + ltime.getSecond())) * 1000000L + ltime.getSecondPart()) * neg);
        case SECOND_MICROSECOND:
            return BigInteger.valueOf((ltime.getSecond() * 1000000L + ltime.getSecondPart()) * neg);
        default:
            break;
    }
    // Impossible
    return BigInteger.ZERO;
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime)

Example 9 with MySQLTime

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

the class ItemFuncTimediff method getTime.

/**
 * TIMEDIFF(t,s) is a time function that calculates the time value between a
 * start and end time.
 * <p>
 * t and s: time_or_datetime_expression
 *
 * @param[out] l_time3 Result is stored here.
 * @param[in] flags Not used in this class.
 * @returns
 * @retval false On succes
 * @retval true On error
 */
@Override
public boolean getTime(MySQLTime ltime) {
    MySQLTime lTime1 = new MySQLTime();
    MySQLTime lTime2 = new MySQLTime();
    int lSign = 1;
    nullValue = false;
    if ((args.get(0).isTemporalWithDate() && args.get(1).fieldType() == FieldTypes.MYSQL_TYPE_TIME) || (args.get(1).isTemporalWithDate() && args.get(0).fieldType() == FieldTypes.MYSQL_TYPE_TIME)) {
        return nullValue = true;
    }
    if (args.get(0).isTemporalWithDate() || args.get(1).isTemporalWithDate()) {
        if (args.get(0).getDate(lTime1, MyTime.TIME_FUZZY_DATE) || args.get(1).getDate(lTime2, MyTime.TIME_FUZZY_DATE))
            return nullValue = true;
    } else {
        if (args.get(0).getTime(lTime1) || args.get(1).getTime(lTime2))
            return nullValue = true;
    }
    if (lTime1.getTimeType() != lTime2.getTimeType()) {
        // Incompatible types
        return nullValue = true;
    }
    if (lTime1.isNeg() != lTime2.isNeg())
        lSign = -lSign;
    MySQLTime lTime3 = new MySQLTime();
    LongPtr seconds = new LongPtr(0);
    LongPtr microseconds = new LongPtr(0);
    lTime3.setNeg(MyTime.calcTimeDiff(lTime1, lTime2, lSign, seconds, microseconds));
    /*
         * For MYSQL_TIMESTAMP_TIME only: If first argument was negative and
         * diff between arguments is non-zero we need to swap sign to get proper
         * result.
         */
    if (lTime1.isNeg() && (seconds.get() != 0 || microseconds.get() != 0))
        // Swap sign of result
        lTime3.setNeg(!lTime3.isNeg());
    MyTime.calcTimeFromSec(lTime3, seconds.get(), microseconds.get());
    return false;
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime)

Example 10 with MySQLTime

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

the class ItemFuncToSeconds method valInt.

@Override
public BigInteger valInt() {
    MySQLTime ltime = new MySQLTime();
    if (getArg0Date(ltime, MyTime.TIME_NO_ZERO_DATE))
        return BigInteger.ZERO;
    long seconds = ltime.getHour() * 3600L + ltime.getMinute() * 60 + ltime.getSecond();
    seconds = ltime.isNeg() ? -seconds : seconds;
    long days = MyTime.calcDaynr(ltime.getYear(), ltime.getMonth(), ltime.getDay());
    return BigInteger.valueOf(seconds + days * 24L * 3600L);
}
Also used : MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime)

Aggregations

MySQLTime (com.actiontech.dble.plan.common.time.MySQLTime)16 LongPtr (com.actiontech.dble.plan.common.ptr.LongPtr)6 StringPtr (com.actiontech.dble.plan.common.ptr.StringPtr)1 DateTimeFormat (com.actiontech.dble.plan.common.time.DateTimeFormat)1 MySQLTimeStatus (com.actiontech.dble.plan.common.time.MySQLTimeStatus)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1