Search in sources :

Example 11 with MySQLTime

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

the class ItemFuncYearweek method valInt.

@Override
public BigInteger valInt() {
    LongPtr year = new LongPtr(0);
    long week;
    MySQLTime ltime = new MySQLTime();
    if (getArg0Date(ltime, MyTime.TIME_NO_ZERO_DATE))
        return BigInteger.ZERO;
    week = MyTime.calcWeek(ltime, (MyTime.weekMode(args.size() > 1 ? args.get(1).valInt().intValue() : 0) | MyTime.WEEK_YEAR), year);
    return BigInteger.valueOf(week + year.get() * 100);
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime)

Example 12 with MySQLTime

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

the class ItemTemporalHybridFunc method valStr.

@Override
public String valStr() {
    MySQLTime ltime = new MySQLTime();
    if (valDatetime(ltime, MyTime.TIME_FUZZY_DATE))
        return null;
    String res = MyTime.myTimeToStr(ltime, cachedFieldType == FieldTypes.MYSQL_TYPE_STRING ? (ltime.getSecondPart() != 0 ? MyTime.DATETIME_MAX_DECIMALS : 0) : decimals);
    if (res == null)
        nullValue = true;
    return res;
}
Also used : MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime)

Example 13 with MySQLTime

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

the class ItemFuncDatediff method valInt.

@Override
public BigInteger valInt() {
    MySQLTime ltime1 = new MySQLTime();
    MySQLTime ltime2 = new MySQLTime();
    if (args.get(0).isNullValue() || args.get(1).isNullValue() || args.get(0).getDate(ltime1, MyTime.TIME_FUZZY_DATE) || args.get(1).getDate(ltime2, MyTime.TIME_FUZZY_DATE)) {
        nullValue = true;
        return BigInteger.ZERO;
    }
    java.util.Calendar cal1 = ltime1.toCalendar();
    java.util.Calendar cal2 = ltime2.toCalendar();
    long diff = (cal1.getTimeInMillis() - cal2.getTimeInMillis()) / (24 * 3600);
    return BigInteger.valueOf(diff);
}
Also used : MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime)

Example 14 with MySQLTime

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

the class CmpUtil method getDateFromStr.

/**
 * @return converted value. 0 on error and on zero-dates -- check 'failure'
 * @brief Convert date provided in a string to its packed temporal int
 * representation.
 * @param[in] thd thread handle
 * @param[in] str a string to convert
 * @param[in] warn_type type of the timestamp for issuing the warning
 * @param[in] warn_name field name for issuing the warning
 * @param[out] error_arg could not extract a DATE or DATETIME
 * @details Convert date provided in the string str to the int
 * representation. If the string contains wrong date or doesn't
 * contain it at all then a warning is issued. The warn_type and
 * the warn_name arguments are used as the name and the type of the
 * field when issuing the warning.
 */
public static long getDateFromStr(String str, MySQLTimestampType warnType, String warnName, BoolPtr errorArg) {
    MySQLTime lTime = new MySQLTime();
    errorArg.set(getMysqlTimeFromStr(str, warnType, warnName, lTime));
    if (errorArg.get())
        return 0;
    return MyTime.timeToLonglongDatetimePacked(lTime);
}
Also used : MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime)

Example 15 with MySQLTime

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

the class FieldTemporal method compareTo.

@Override
public int compareTo(final Field other) {
    if (other == null || !(other instanceof FieldTemporal))
        return 1;
    FieldTemporal other2 = (FieldTemporal) other;
    this.internalJob();
    other2.internalJob();
    MySQLTime ltime2 = other2.ltime;
    return ltime.getCompareResult(ltime2);
}
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