use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class SQLPrettyfier method prettyfie.
public static String prettyfie(String sql, boolean validZql) {
ParserString ps = new ParserString(sql.trim());
boolean insideString = false;
// short insideKlammer=0;
StringBuilder sb = new StringBuilder(sql.length());
outer: while (!ps.isAfterLast()) {
if (insideString) {
if (ps.isCurrent('\'')) {
if (!ps.hasNext() || !ps.isNext('\''))
insideString = false;
}
} else {
if (ps.isCurrent('\''))
insideString = true;
else if (ps.isCurrent('?')) {
sb.append(" " + PLACEHOLDER_QUESTION + " ");
ps.next();
continue;
} else if (ps.isCurrent('{')) {
StringBuilder date = new StringBuilder();
int pos = ps.getPos();
while (true) {
if (ps.isAfterLast()) {
ps.setPos(pos);
break;
} else if (ps.isCurrent('}')) {
date.append('}');
DateTime d;
try {
d = DateCaster.toDateAdvanced(date.toString(), null);
} catch (PageException e) {
ps.setPos(pos);
break;
}
sb.append('\'');
sb.append(new DateFormat(Locale.US).format(d, "yyyy-mm-dd"));
sb.append(' ');
sb.append(new TimeFormat(Locale.US).format(d, "HH:mm:ss"));
sb.append('\'');
ps.next();
continue outer;
} else {
date.append(ps.getCurrent());
ps.next();
}
}
} else if (ps.isCurrent('*')) {
sb.append(" " + PLACEHOLDER_ASTERIX + " ");
ps.next();
// last=ps.getCurrent();
continue;
} else if (validZql && ps.isCurrent('a')) {
if (ps.isPreviousWhiteSpace() && ps.isNext('s') && ps.isNextNextWhiteSpace()) {
ps.next();
ps.next();
ps.removeSpace();
continue;
}
}
/*for(int i=0;i<reseved_words.length;i++) {
if(ps.isCurrent(reseved_words[i])) {
int pos=ps.getPos();
ps.setPos(pos+4);
if(ps.isCurrentWhiteSpace()) {
sb.append(" placeholder_"+reseved_words[i]+" ");
continue;
}
if(ps.isCurrent(',')) {
sb.append(" placeholder_"+reseved_words[i]+",");
continue;
}
ps.setPos(pos);
}
}*/
/*if(ps.isCurrent("char")) {
int pos=ps.getPos();
ps.setPos(pos+4);
if(ps.isCurrentWhiteSpace()) {
sb.append(" "+PLACEHOLDER_CHAR+" ");
continue;
}
if(ps.isCurrent(',')) {
sb.append(" "+PLACEHOLDER_CHAR+",");
continue;
}
ps.setPos(pos);
}*/
}
sb.append(ps.getCurrent());
ps.next();
}
;
if (!ps.isLast(';'))
sb.append(';');
// print.err("---------------------------------------------------------------------------------");
return sb.toString();
}
use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class Beat method call.
public static double call(PageContext pc, Object obj) throws PageException {
if (obj == null)
obj = new DateTimeImpl(pc);
TimeZone tz = ThreadLocalPageContext.getTimeZone(pc);
DateTime date = DateCaster.toDateAdvanced(obj, tz);
return format(date.getTime());
}
use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class DateFormat method _call.
private static String _call(PageContext pc, Object object, String mask, TimeZone tz) throws PageException {
Locale locale = Locale.US;
DateTime datetime = DateCaster.toDateAdvanced(object, tz, null);
// Caster.toDate(object,true,tz,null);
if (datetime == null) {
if (StringUtil.isEmpty(object, true))
return "";
throw new CasterException(object, "datetime");
// if(!Decision.isSimpleValue(object))
// throw new ExpressionException("can't convert object of type "+Type.getName(object)+" to a datetime value");
// throw new ExpressionException("can't convert value "+object+" to a datetime value");
}
return new lucee.runtime.format.DateFormat(locale).format(datetime, mask, tz);
}
use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class DateTimeFormatClassic method _call.
private static String _call(PageContext pc, Object object, String mask, TimeZone tz) throws ExpressionException {
// :pc.getConfig().getLocale();
Locale locale = Locale.US;
DateTime datetime = Caster.toDate(object, true, tz, null);
if (datetime == null) {
if (object.toString().trim().length() == 0)
return "";
throw new ExpressionException("can't convert value " + object + " to a datetime value");
}
return new lucee.runtime.format.DateTimeFormat(locale).format(datetime, mask, tz);
// return new lucee.runtime.text.TimeFormat(locale).format(datetime,mask);
}
use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class TimeFormat method _call.
private static String _call(PageContext pc, Object object, String mask, TimeZone tz) throws ExpressionException {
// :pc.getConfig().getLocale();
Locale locale = Locale.US;
DateTime datetime = Caster.toDate(object, true, tz, null);
if (datetime == null) {
if (StringUtil.isEmpty(object, true))
return "";
throw new ExpressionException("can't convert value " + object + " to a datetime value");
}
return new lucee.runtime.format.TimeFormat(locale).format(datetime, mask, tz);
// return new lucee.runtime.text.TimeFormat(locale).format(datetime,mask);
}
Aggregations