package com.tibbo.aggregate.common.expression.function.type;

import com.google.common.primitives.Longs;
import com.tibbo.aggregate.common.Cres;
import com.tibbo.aggregate.common.data.Data;
import com.tibbo.aggregate.common.expression.EvaluationException;
import com.tibbo.aggregate.common.expression.Evaluator;
import com.tibbo.aggregate.common.util.Util;

public class TimestampFunction extends TypeConversionFunction
{
  public TimestampFunction()
  {
    super("timestamp", "Date", Cres.get().getString("fDescTimestamp"));
  }
  
  @Override
  public Object convert(Evaluator evaluator, Object parameter) throws EvaluationException
  {
    if (parameter instanceof Data)
    {
      Data data = (Data) parameter;
      parameter = Longs.fromByteArray(data.getData());
    }
    return parameter != null ? Util.convertToDate(parameter, false, false) : null;
  }
}
