use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class HttpGetWithBody method parseCookie.
private void parseCookie(Query cookies, String raw) {
String[] arr = ListUtil.trimItems(ListUtil.trim(ListUtil.listToStringArray(raw, ';')));
if (arr.length == 0)
return;
int row = cookies.addRow();
String item;
int index;
// name/value
if (arr.length > 0) {
item = arr[0];
index = item.indexOf('=');
if (// only name
index == -1)
cookies.setAtEL(KeyConstants._name, row, dec(item));
else {
// name and value
cookies.setAtEL(KeyConstants._name, row, dec(item.substring(0, index)));
cookies.setAtEL(KeyConstants._value, row, dec(item.substring(index + 1)));
}
}
String n, v;
cookies.setAtEL("secure", row, Boolean.FALSE);
cookies.setAtEL("httpOnly", row, Boolean.FALSE);
for (int i = 1; i < arr.length; i++) {
item = arr[i];
index = item.indexOf('=');
if (// only name
index == -1)
cookies.setAtEL(dec(item), row, Boolean.TRUE);
else {
// name and value
n = dec(item.substring(0, index));
v = dec(item.substring(index + 1));
if (n.equalsIgnoreCase("expires")) {
DateTime d = Caster.toDate(v, false, null, null);
if (d != null) {
cookies.setAtEL(n, row, d);
continue;
}
}
cookies.setAtEL(n, row, v);
}
}
}
use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class Cache method doClientCache.
private void doClientCache() {
pageContext.setHeader("Last-Modified", GetHttpTimeString.call(pageContext, now));
if (timespan != null) {
DateTime expires = getExpiresDate();
pageContext.setHeader("Expires", GetHttpTimeString.call(pageContext, expires));
}
}
use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class DateCaster method toTime.
/**
* converts a String to a Time Object, returns null if invalid string
* @param str String to convert
* @param defaultValue
* @return Time Object
* @throws
*/
public static Time toTime(TimeZone timeZone, String str, Time defaultValue) {
if (str == null || str.length() < 3) {
return defaultValue;
}
DateString ds = new DateString(str);
// Timestamp
if (ds.isCurrent('{') && ds.isLast('}')) {
// "^\\{t '([0-9]{1,2}):([0-9]{1,2}):([0-9]{2})'\\}$"
if (ds.fwIfNext('t')) {
// Time
if (!(ds.fwIfNext(' ') && ds.fwIfNext('\'')))
return defaultValue;
ds.next();
// hour
int hour = ds.readDigits();
if (hour == -1)
return defaultValue;
if (!ds.fwIfCurrent(':'))
return defaultValue;
// minute
int minute = ds.readDigits();
if (minute == -1)
return defaultValue;
if (!ds.fwIfCurrent(':'))
return defaultValue;
// second
int second = ds.readDigits();
if (second == -1)
return defaultValue;
if (!(ds.fwIfCurrent('\'') && ds.fwIfCurrent('}')))
return defaultValue;
if (ds.isAfterLast()) {
long time = util.toTime(timeZone, 1899, 12, 30, hour, minute, second, 0, DEFAULT_VALUE);
if (time == DEFAULT_VALUE)
return defaultValue;
return new TimeImpl(time, false);
}
return defaultValue;
}
return defaultValue;
}
// Time start with int
/*else if(ds.isDigit()) {
char sec=ds.charAt(1);
char third=ds.charAt(2);
// 16.10.2004 (02:15)?
if(sec==':' || third==':') {
// hour
int hour=ds.readDigits();
if(hour==-1) return defaultValue;
if(!ds.fwIfCurrent(':'))return defaultValue;
// minutes
int minutes=ds.readDigits();
if(minutes==-1) return defaultValue;
if(ds.isAfterLast()) {
long time=util.toTime(timeZone,1899,12,30,hour,minutes,0,0,DEFAULT_VALUE);
if(time==DEFAULT_VALUE) return defaultValue;
return new TimeImpl(time,false);
}
//else if(!ds.fwIfCurrent(':'))return null;
else if(!ds.fwIfCurrent(':')) {
if(!ds.fwIfCurrent(' '))return defaultValue;
if(ds.fwIfCurrent('a') || ds.fwIfCurrent('A')) {
if(ds.fwIfCurrent('m') || ds.fwIfCurrent('M')) {
if(ds.isAfterLast()) {
long time=util.toTime(timeZone,1899,12,30,hour,minutes,0,0,DEFAULT_VALUE);
if(time==DEFAULT_VALUE) return defaultValue;
return new TimeImpl(time,false);
}
}
return defaultValue;
}
else if(ds.fwIfCurrent('p') || ds.fwIfCurrent('P')) {
if(ds.fwIfCurrent('m') || ds.fwIfCurrent('M')) {
if(ds.isAfterLast()) {
long time=util.toTime(timeZone,1899,12,30,hour<13?hour+12:hour,minutes,0,0,DEFAULT_VALUE);
if(time==DEFAULT_VALUE) return defaultValue;
return new TimeImpl(time,false);
}
}
return defaultValue;
}
return defaultValue;
}
// seconds
int seconds=ds.readDigits();
if(seconds==-1) return defaultValue;
if(ds.isAfterLast()) {
long time=util.toTime(timeZone,1899,12,30,hour,minutes,seconds,0,DEFAULT_VALUE);
if(time==DEFAULT_VALUE) return defaultValue;
return new TimeImpl(time,false);
}
}
}*/
// TODO bessere impl
ds.reset();
DateTime rtn = parseTime(timeZone, new int[] { 1899, 12, 30 }, ds, defaultValue, -1);
if (rtn == defaultValue)
return defaultValue;
return new TimeImpl(rtn);
// return defaultValue;
}
use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class DateCaster method toDateSimple.
/**
* converts the given string to a date following simple and fast parsing rules (no international formats)
* @param str
* @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
* @param alsoMonthString allow that the month is defined as english word (jan,janauary ...)
* @param timeZone
* @param defaultValue
* @return
*/
public static DateTime toDateSimple(String str, short convertingType, boolean alsoMonthString, TimeZone timeZone, DateTime defaultValue) {
str = StringUtil.trim(str, "");
DateString ds = new DateString(str);
// Timestamp
if (ds.isCurrent('{') && ds.isLast('}')) {
return _toDateSimpleTS(ds, timeZone, defaultValue);
}
DateTime res = parseDateTime(str, ds, convertingType, alsoMonthString, timeZone, defaultValue);
if (res == defaultValue && Decision.isNumber(str)) {
return numberToDate(timeZone, Caster.toDoubleValue(str, Double.NaN), convertingType, defaultValue);
}
return res;
}
use of lucee.runtime.type.dt.DateTime in project Lucee by lucee.
the class StorageUtil method toDateTime.
/**
* reads a XML Element Attribute ans cast it to a DateTime
* @param el XML Element to read Attribute from it
* @param attributeName Name of the Attribute to read
* @param defaultValue if attribute doesn't exist return default value
* @return Attribute Value
*/
public DateTime toDateTime(Element el, String attributeName, DateTime defaultValue) {
String value = el.getAttribute(attributeName);
if (value == null)
return defaultValue;
DateTime dtValue = Caster.toDate(value, false, null, null);
if (dtValue == null)
return defaultValue;
return dtValue;
}
Aggregations