use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class DateCaster method toDateTime.
/**
* parse a string to a Datetime Object, returns null if can't convert
* @param locale
* @param str String representation of a locale Date
* @param tz
* @param defaultValue
* @return datetime object
*/
public static DateTime toDateTime(Locale locale, String str, TimeZone tz, DateTime defaultValue, boolean useCommomDateParserAsWell) {
str = str.trim();
tz = ThreadLocalPageContext.getTimeZone(tz);
DateFormat[] df;
// get Calendar
Calendar c = JREDateTimeUtil.getThreadCalendar(locale, tz);
// datetime
ParsePosition pp = new ParsePosition(0);
// dfc[FORMATS_DATE_TIME];
df = FormatUtil.getDateTimeFormats(locale, tz, false);
Date d;
for (int i = 0; i < df.length; i++) {
pp.setErrorIndex(-1);
pp.setIndex(0);
df[i].setTimeZone(tz);
d = df[i].parse(str, pp);
if (pp.getIndex() == 0 || d == null || pp.getIndex() < str.length())
continue;
optimzeDate(c, tz, d);
return new DateTimeImpl(c.getTime());
}
// date
df = FormatUtil.getDateFormats(locale, tz, false);
for (int i = 0; i < df.length; i++) {
pp.setErrorIndex(-1);
pp.setIndex(0);
df[i].setTimeZone(tz);
d = df[i].parse(str, pp);
if (pp.getIndex() == 0 || d == null || pp.getIndex() < str.length())
continue;
optimzeDate(c, tz, d);
return new DateTimeImpl(c.getTime());
}
// time
// dfc[FORMATS_TIME];
df = FormatUtil.getTimeFormats(locale, tz, false);
for (int i = 0; i < df.length; i++) {
pp.setErrorIndex(-1);
pp.setIndex(0);
df[i].setTimeZone(tz);
d = df[i].parse(str, pp);
if (pp.getIndex() == 0 || d == null || pp.getIndex() < str.length())
continue;
c.setTimeZone(tz);
c.setTime(d);
c.set(Calendar.YEAR, 1899);
c.set(Calendar.MONTH, 11);
c.set(Calendar.DAY_OF_MONTH, 30);
c.setTimeZone(tz);
return new DateTimeImpl(c.getTime());
}
if (useCommomDateParserAsWell)
return DateCaster.toDateSimple(str, CONVERTING_TYPE_NONE, true, tz, defaultValue);
return defaultValue;
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class DateCaster method numberToDate.
/**
* @param timeZone
* @param d
* @param convertingType one of the following values:
* - CONVERTING_TYPE_NONE: number are not converted at all
* - CONVERTING_TYPE_YEAR: integers are handled as years
* - CONVERTING_TYPE_OFFSET: numbers are handled as offset from 1899-12-30 00:00:00 UTC
* @return
*/
private static DateTime numberToDate(TimeZone timeZone, double d, short convertingType, DateTime defaultValue) {
if (!Decision.isValid(d))
return defaultValue;
if (convertingType == CONVERTING_TYPE_YEAR) {
int i = (int) d;
if (i == d) {
timeZone = ThreadLocalPageContext.getTimeZone(timeZone);
Calendar c = Calendar.getInstance(timeZone);
c.set(Calendar.MILLISECOND, 0);
c.set(i, 0, 1, 0, 0, 0);
return new DateTimeImpl(c);
}
}
if (convertingType == CONVERTING_TYPE_OFFSET)
return util.toDateTime(d);
return defaultValue;
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class TaskFileFilter method addQueryRow.
private void addQueryRow(lucee.runtime.type.Query qry, SpoolerTask task) {
int row = qry.addRow();
try {
qry.setAt(KeyConstants._type, row, task.getType());
qry.setAt(KeyConstants._name, row, task.subject());
qry.setAt(KeyConstants._detail, row, task.detail());
qry.setAt(KeyConstants._id, row, task.getId());
qry.setAt(LAST_EXECUTION, row, new DateTimeImpl(task.lastExecution(), true));
qry.setAt(NEXT_EXECUTION, row, new DateTimeImpl(task.nextExecution(), true));
qry.setAt(CLOSED, row, Caster.toBoolean(task.closed()));
qry.setAt(TRIES, row, Caster.toDouble(task.tries()));
qry.setAt(TRIES_MAX, row, Caster.toDouble(task.tries()));
qry.setAt(KeyConstants._exceptions, row, translateTime(task.getExceptions()));
int triesMax = 0;
ExecutionPlan[] plans = task.getPlans();
for (int y = 0; y < plans.length; y++) {
triesMax += plans[y].getTries();
}
qry.setAt(TRIES_MAX, row, Caster.toDouble(triesMax));
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class TaskFileFilter method translateTime.
private Array translateTime(Array exp) {
exp = (Array) Duplicator.duplicate(exp, true);
Iterator<Object> it = exp.valueIterator();
Struct sct;
while (it.hasNext()) {
sct = (Struct) it.next();
sct.setEL(KeyConstants._time, new DateTimeImpl(Caster.toLongValue(sct.get(KeyConstants._time, null), 0), true));
}
return exp;
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class Admin method doGetRemoteClientTasks.
private int doGetRemoteClientTasks(lucee.runtime.type.Query qry, SpoolerTask[] tasks, int row) {
SpoolerTask task;
for (int i = 0; i < tasks.length; i++) {
row++;
task = tasks[i];
try {
qry.setAt("type", row, task.getType());
qry.setAt("name", row, task.subject());
qry.setAt("detail", row, task.detail());
qry.setAt("id", row, task.getId());
qry.setAt("lastExecution", row, new DateTimeImpl(pageContext, task.lastExecution(), true));
qry.setAt("nextExecution", row, new DateTimeImpl(pageContext, task.nextExecution(), true));
qry.setAt("closed", row, Caster.toBoolean(task.closed()));
qry.setAt("tries", row, Caster.toDouble(task.tries()));
qry.setAt("triesmax", row, Caster.toDouble(task.tries()));
qry.setAt("exceptions", row, translateTime(task.getExceptions()));
int triesMax = 0;
ExecutionPlan[] plans = task.getPlans();
for (int y = 0; y < plans.length; y++) {
triesMax += plans[y].getTries();
}
qry.setAt("triesmax", row, Caster.toDouble(triesMax));
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
return row;
}
Aggregations