From f02e150a7e7542498e6875409fd31aa71c93b651 Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 27 Dec 2010 11:14:14 +0000 Subject: [PATCH] adjust to new ELAM context git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@684 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/misc/formula.cpp | 39 +++++++++++++++++++++++++++++++++------ 1 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/misc/formula.cpp b/src/misc/formula.cpp index f5aa12d..92bcaf5 100644 --- a/src/misc/formula.cpp +++ b/src/misc/formula.cpp @@ -17,7 +17,7 @@ using namespace ELAM; -static QVariant toMoneyFunc(const QList&lf,bool local) +inline static QVariant toMoneyFunc(const QList&lf,bool local) { if(lf.size()!=1) return Exception(Exception::ArgumentListError, "expecting exactly one argument"); @@ -25,10 +25,10 @@ static QVariant toMoneyFunc(const QList&lf,bool local) return Exception(Exception::TypeMismatchError,"cannot convert to int"); return cent2str(lf[0].toLongLong(),local); } -static QVariant toMoneyFuncLoc(const QList&lf){return toMoneyFunc(lf,true);} -static QVariant toMoneyFuncNLoc(const QList&lf){return toMoneyFunc(lf,false);} +static QVariant toMoneyFuncLoc(const QList&lf,Engine&){return toMoneyFunc(lf,true);} +static QVariant toMoneyFuncNLoc(const QList&lf,Engine&){return toMoneyFunc(lf,false);} -static QVariant fromMoneyFunc(const QList&lf,bool local) +inline static QVariant fromMoneyFunc(const QList&lf,bool local) { if(lf.size()!=1) return Exception(Exception::ArgumentListError, "expecting exactly one argument"); @@ -36,8 +36,31 @@ static QVariant fromMoneyFunc(const QList&lf,bool local) return Exception(Exception::TypeMismatchError,"cannot convert to string"); return str2cent(lf[0].toString(),local); } -static QVariant fromMoneyFuncLoc(const QList&lf){return fromMoneyFunc(lf,true);} -static QVariant fromMoneyFuncNLoc(const QList&lf){return fromMoneyFunc(lf,false);} +static QVariant fromMoneyFuncLoc(const QList&lf,Engine&){return fromMoneyFunc(lf,true);} +static QVariant fromMoneyFuncNLoc(const QList&lf,Engine&){return fromMoneyFunc(lf,false);} + +inline static QVariant unix2DTFunc(const QList&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()) + 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()) + 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&args,Engine&){return unix2DTFunc(args,0);} +static QVariant unix2TimeFunc(const QList&args,Engine&){return unix2DTFunc(args,1);} +static QVariant unix2DateTimeFunc(const QList&args,Engine&){return unix2DTFunc(args,2);} MElamEngine::MElamEngine(QObject* parent): Engine(parent) { @@ -61,4 +84,8 @@ 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); } -- 1.7.2.5