Search in sources :

Example 6 with DateTime

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();
}
Also used : PageException(lucee.runtime.exp.PageException) TimeFormat(lucee.runtime.format.TimeFormat) ParserString(lucee.commons.lang.ParserString) DateFormat(lucee.runtime.format.DateFormat) DateTime(lucee.runtime.type.dt.DateTime)

Example 7 with DateTime

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());
}
Also used : TimeZone(java.util.TimeZone) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) DateTime(lucee.runtime.type.dt.DateTime)

Example 8 with DateTime

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);
}
Also used : Locale(java.util.Locale) CasterException(lucee.runtime.exp.CasterException) DateTime(lucee.runtime.type.dt.DateTime)

Example 9 with DateTime

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);
}
Also used : Locale(java.util.Locale) DateTime(lucee.runtime.type.dt.DateTime) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 10 with DateTime

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);
}
Also used : Locale(java.util.Locale) DateTime(lucee.runtime.type.dt.DateTime) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

DateTime (lucee.runtime.type.dt.DateTime)16 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)5 Locale (java.util.Locale)4 Date (java.util.Date)3 List (java.util.List)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TimeZone (java.util.TimeZone)2 CasterException (lucee.runtime.exp.CasterException)2 ExpressionException (lucee.runtime.exp.ExpressionException)2 PageException (lucee.runtime.exp.PageException)2 ObjectWrap (lucee.runtime.type.ObjectWrap)2 TimeImpl (lucee.runtime.type.dt.TimeImpl)2 TimeSpan (lucee.runtime.type.dt.TimeSpan)2 Node (org.w3c.dom.Node)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1