enjoy 3.3 release ^_^
This commit is contained in:
@@ -16,12 +16,13 @@
|
||||
|
||||
package com.jfinal.template.ext.directive;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import com.jfinal.template.Directive;
|
||||
import com.jfinal.template.Env;
|
||||
import com.jfinal.template.TemplateException;
|
||||
import com.jfinal.template.expr.ast.ExprList;
|
||||
import com.jfinal.template.io.Writer;
|
||||
import com.jfinal.template.stat.ParseException;
|
||||
import com.jfinal.template.stat.Scope;
|
||||
|
||||
@@ -39,22 +40,21 @@ public class NowDirective extends Directive {
|
||||
}
|
||||
|
||||
public void exec(Env env, Scope scope, Writer writer) {
|
||||
String dataPattern;
|
||||
String datePattern;
|
||||
if (exprList.length() == 0) {
|
||||
dataPattern = env.getEngineConfig().getDatePattern();
|
||||
datePattern = env.getEngineConfig().getDatePattern();
|
||||
} else {
|
||||
Object dp = exprList.eval(scope);
|
||||
if (dp instanceof String) {
|
||||
dataPattern = (String)dp;
|
||||
datePattern = (String)dp;
|
||||
} else {
|
||||
throw new TemplateException("The parameter of #new directive must be String", location);
|
||||
throw new TemplateException("The parameter of #now directive must be String", location);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String value = new SimpleDateFormat(dataPattern).format(new java.util.Date());
|
||||
write(writer, value);
|
||||
} catch (Exception e) {
|
||||
writer.write(new Date(), datePattern);
|
||||
} catch (IOException e) {
|
||||
throw new TemplateException(e.getMessage(), location, e);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user