use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class PageSourceImpl method dump.
private void dump() {
Resource res = getResource();
if (res != null && res.isFile()) {
try {
File file = createPath();
IOUtil.write(file, new DateTimeImpl() + " " + res.getAbsolutePath() + "\n", "UTF-8", true);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class PageSourcePool method toDumpData.
@Override
public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
maxlevel--;
Iterator<PageSource> it = pageSources.values().iterator();
DumpTable table = new DumpTable("#FFCC00", "#FFFF00", "#000000");
table.setTitle("Page Source Pool");
table.appendRow(1, new SimpleDumpData("Count"), new SimpleDumpData(pageSources.size()));
while (it.hasNext()) {
PageSource ps = it.next();
DumpTable inner = new DumpTable("#FFCC00", "#FFFF00", "#000000");
inner.setWidth("100%");
inner.appendRow(1, new SimpleDumpData("source"), new SimpleDumpData(ps.getDisplayPath()));
inner.appendRow(1, new SimpleDumpData("last access"), DumpUtil.toDumpData(new DateTimeImpl(pageContext, ps.getLastAccessTime(), false), pageContext, maxlevel, dp));
inner.appendRow(1, new SimpleDumpData("access count"), new SimpleDumpData(ps.getAccessCount()));
table.appendRow(1, new SimpleDumpData("Sources"), inner);
}
return table;
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class COMUtil method toObject.
/**
* translate a Variant Object to Object, when it is a Dispatch translate it to COMWrapper
* @param parent
* @param variant
* @param key
* @return Object from Variant
* @throws ExpressionException
*/
public static Object toObject(COMObject parent, Variant variant, String key) throws ExpressionException {
short type = variant.getvt();
if (type == Variant.VariantEmpty)
return null;
else if (type == Variant.VariantNull)
return null;
else if (type == Variant.VariantShort)
return Short.valueOf(variant.getShort());
else if (type == Variant.VariantInt)
return Integer.valueOf(variant.getInt());
else if (type == Variant.VariantFloat)
return new Float(variant.getFloat());
else if (type == Variant.VariantDouble)
return new Double(variant.getDouble());
else if (type == Variant.VariantCurrency) {
long l;
try {
l = variant.getCurrency().longValue();
}// this reflection allows support for old and new jacob version
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
try {
Method toCurrency = variant.getClass().getMethod("toCurrency", new Class[0]);
Object curreny = toCurrency.invoke(variant, new Object[0]);
Method longValue = curreny.getClass().getMethod("longValue", new Class[0]);
l = Caster.toLongValue(longValue.invoke(curreny, new Object[0]), 0);
} catch (Throwable t2) {
ExceptionUtil.rethrowIfNecessary(t2);
l = 0;
}
}
return Long.valueOf(l);
} else if (type == Variant.VariantObject)
return variant.toEnumVariant();
else if (type == Variant.VariantDate)
return new DateTimeImpl((long) variant.getDate(), true);
else if (type == Variant.VariantString)
return variant.getString();
else if (type == Variant.VariantBoolean)
return variant.getBoolean() ? Boolean.TRUE : Boolean.FALSE;
else if (type == Variant.VariantByte)
return new Byte(variant.getByte());
else if (type == Variant.VariantVariant) {
throw new ExpressionException("type variant is not supported");
// return toObject(variant.getV.get());
} else if (type == Variant.VariantArray) {
Variant[] varr = variant.getVariantArrayRef();
Object[] oarr = new Object[varr.length];
for (int i = 0; i < varr.length; i++) {
oarr[i] = toObject(parent, varr[i], Caster.toString(i));
}
return new ArrayImpl(oarr);
} else if (type == Variant.VariantDispatch) {
return new COMObject(variant, variant.toDispatch(), parent.getName() + "." + key);
}
throw new ExpressionException("COM Type [" + toStringType(type) + "] not supported");
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class DateAdd method _call.
public static DateTime _call(PageContext pc, TimeZone tz, String datepart, double number, DateTime date) throws ExpressionException {
datepart = datepart.toLowerCase();
long l = (long) number;
int n = (int) l;
char first = datepart.length() == 1 ? datepart.charAt(0) : (char) 0;
if (first == 'l')
return new DateTimeImpl(pc, date.getTime() + l, false);
else if (first == 's')
return new DateTimeImpl(pc, date.getTime() + (l * 1000), false);
else if (first == 'n')
return new DateTimeImpl(pc, date.getTime() + (l * 60000), false);
else if (first == 'h')
return new DateTimeImpl(pc, date.getTime() + (l * 3600000), false);
Calendar c = JREDateTimeUtil.getThreadCalendar();
// if (c == null)c=JREDateTimeUtil.newInstance();
// synchronized (c) {
// c.clear();
c.setTimeZone(tz);
c.setTimeInMillis(date.getTime());
if (datepart.equals("yyyy")) {
c.set(Calendar.YEAR, c.get(Calendar.YEAR) + n);
} else if (datepart.equals("ww"))
c.add(Calendar.WEEK_OF_YEAR, n);
else if (first == 'q')
c.add(Calendar.MONTH, (n * 3));
else if (first == 'm')
c.add(Calendar.MONTH, n);
else if (first == 'y')
c.add(Calendar.DAY_OF_YEAR, n);
else if (first == 'd')
c.add(Calendar.DATE, n);
else if (first == 'w') {
int dow = c.get(Calendar.DAY_OF_WEEK);
int offset;
// -
if (n < 0) {
if (Calendar.SUNDAY == dow)
offset = 2;
else
offset = -(6 - dow);
} else // +
{
if (Calendar.SATURDAY == dow)
offset = -2;
else
offset = dow - 2;
}
c.add(Calendar.DAY_OF_WEEK, -offset);
if (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) {
if (n > 0)
n--;
else if (n < 0)
n++;
} else
n += offset;
c.add(Calendar.DAY_OF_WEEK, (n / 5) * 7 + n % 5);
} else {
throw new ExpressionException("invalid datepart identifier [" + datepart + "] for function dateAdd");
}
return new DateTimeImpl(pc, c.getTimeInMillis(), false);
// }
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class DateConvert method call.
public static DateTime call(PageContext pc, String conversionType, DateTime date) throws FunctionException {
// throw new ApplicationException("This function is no longer supported, because it gives you the wrong impression that the timezone is part of the date object, what is wrong!" +
// "When you wanna convert a Date to String based on the UTC timezone, do for example [DateTimeFormat(date:now(),timezone:'UTC')].");
int offset = pc.getTimeZone().getOffset(date.getTime());
conversionType = conversionType.toLowerCase();
if (conversionType.equals("local2utc")) {
return new DateTimeImpl(pc, date.getTime() - offset, false);
} else if (conversionType.equals("utc2local")) {
return new DateTimeImpl(pc, date.getTime() + offset, false);
}
throw new FunctionException(pc, "DateConvert", 1, "conversionType", "invalid conversion-type [" + conversionType + "] for function dateConvert");
}
Aggregations