using namespace ELAM;
-static QVariant toMoneyFunc(const QList<QVariant>&lf,bool local)
+inline static QVariant toMoneyFunc(const QList<QVariant>&lf,bool local)
{
if(lf.size()!=1)
return Exception(Exception::ArgumentListError, "expecting exactly one argument");
return Exception(Exception::TypeMismatchError,"cannot convert to int");
return cent2str(lf[0].toLongLong(),local);
}
-static QVariant toMoneyFuncLoc(const QList<QVariant>&lf){return toMoneyFunc(lf,true);}
-static QVariant toMoneyFuncNLoc(const QList<QVariant>&lf){return toMoneyFunc(lf,false);}
+static QVariant toMoneyFuncLoc(const QList<QVariant>&lf,Engine&){return toMoneyFunc(lf,true);}
+static QVariant toMoneyFuncNLoc(const QList<QVariant>&lf,Engine&){return toMoneyFunc(lf,false);}
-static QVariant fromMoneyFunc(const QList<QVariant>&lf,bool local)
+inline static QVariant fromMoneyFunc(const QList<QVariant>&lf,bool local)
{
if(lf.size()!=1)
return Exception(Exception::ArgumentListError, "expecting exactly one argument");
return Exception(Exception::TypeMismatchError,"cannot convert to string");
return str2cent(lf[0].toString(),local);
}
-static QVariant fromMoneyFuncLoc(const QList<QVariant>&lf){return fromMoneyFunc(lf,true);}
-static QVariant fromMoneyFuncNLoc(const QList<QVariant>&lf){return fromMoneyFunc(lf,false);}
+static QVariant fromMoneyFuncLoc(const QList<QVariant>&lf,Engine&){return fromMoneyFunc(lf,true);}
+static QVariant fromMoneyFuncNLoc(const QList<QVariant>&lf,Engine&){return fromMoneyFunc(lf,false);}
+
+inline static QVariant unix2DTFunc(const QList<QVariant>&args,int mode)
+{
+ if(args.size()<1 || args.size()>2)
+ return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 or 2 arguments");
+ if(!args[0].canConvert<qlonglong>())
+ return ELAM::Exception(ELAM::Exception::TypeMismatchError,"argument 1 must be int");
+ qint64 tm=args[0].toLongLong();
+ bool loc=true;
+ if(args.size()>1){
+ if(!args[1].canConvert<bool>())
+ return ELAM::Exception(ELAM::Exception::TypeMismatchError,"argument 2 must be boolean");
+ loc=args[1].toBool();
+ }
+ switch(mode){
+ case 0:return unix2date(tm,loc);
+ case 1:return unix2time(tm,loc);
+ default:return unix2dateTime(tm,loc);
+ }
+}
+static QVariant unix2DateFunc(const QList<QVariant>&args,Engine&){return unix2DTFunc(args,0);}
+static QVariant unix2TimeFunc(const QList<QVariant>&args,Engine&){return unix2DTFunc(args,1);}
+static QVariant unix2DateTimeFunc(const QList<QVariant>&args,Engine&){return unix2DTFunc(args,2);}
MElamEngine::MElamEngine(QObject* parent): Engine(parent)
{
setFunction("fromMoney",fromMoneyFuncLoc);
setFunction("fromMoneyLocal",fromMoneyFuncLoc);
setFunction("fromMoneyNL",fromMoneyFuncNLoc);
+ //add datetime conversion
+ setFunction("unix2date",unix2DateFunc);
+ setFunction("unix2time",unix2TimeFunc);
+ setFunction("unix2datetime",unix2DateTimeFunc);
}