/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001-2006 The Mir-coders group
*
* This file is part of Mir.
*
*
* In addition, as a special exception, The Mir-coders gives permission to link
* the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
* and distribute linked combinations including the two. You must obey the
* GNU General Public License in all respects for all of the code used other than
* the above mentioned libraries. If you modify this file, you may extend this
*/
package mir.util;
+import mir.generator.Generator;
+import mir.generator.GeneratorExc;
+import mir.generator.GeneratorFailure;
+
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
-import mir.generator.Generator;
-import mir.generator.GeneratorExc;
-import mir.generator.GeneratorFailure;
-
public class GeneratorDateTimeFunctions {
private GeneratorDateTimeFunctions() {
}
}
public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
- try {
- if (aParameters.size()<2 || aParameters.size()>3)
- throw new GeneratorExc("dateFormatFunction <date> <format> [<timezone>]: 2 or 3 parameters expected");
-
- if (!(aParameters.get(0) instanceof Date) ||
- !(aParameters.get(1) instanceof String) ||
- ( aParameters.size()>2 &&
- !(aParameters.get(2) instanceof String)))
- throw new GeneratorExc("dateFormatFunction <date> <format> [<timezone>]: type mismatch");
+ if (aParameters.size()<2 || aParameters.size()>3) {
+ throw new GeneratorExc("dateFormatFunction <date> <format> [<timezone>]: 2 or 3 parameters expected");
+ }
+ if (!(aParameters.get(0) instanceof Date) || !(aParameters.get(1) instanceof String) ||
+ (aParameters.size() > 2 && !(aParameters.get(2) instanceof String))) {
+ throw new GeneratorExc("dateFormatFunction <date> <format> [<timezone>]: type mismatch");
+ }
- Date date = (Date) aParameters.get(0);
- SimpleDateFormat dateFormat = new SimpleDateFormat( (String) (aParameters.get(1)));
+ Date date = (Date) aParameters.get(0);
+ SimpleDateFormat dateFormat = new SimpleDateFormat( (String) (aParameters.get(1)));
- String timezoneString = "";
- if (aParameters.size()>2)
- timezoneString = (String) aParameters.get(2);
- else
- timezoneString = defaultTimezone;
+ String timezoneString = defaultTimezone;
+ if (aParameters.size()>2) {
+ timezoneString = (String) aParameters.get(2);
+ }
- TimeZone timezone = null;
- try {
- timezone = TimeZone.getTimeZone(defaultTimezone);
- }
- catch (Throwable t) {
- }
+ TimeZone timezone = TimeZone.getTimeZone(timezoneString);
- if (timezone == null)
- timezone = TimeZone.getDefault();
+ if (timezone == null) {
+ timezone = TimeZone.getDefault();
+ }
- dateFormat.setTimeZone(timezone);
+ dateFormat.setTimeZone(timezone);
- return dateFormat.format(date);
- }
- catch (GeneratorExc e) {
- throw e;
- }
- catch (Throwable t) {
- throw new GeneratorFailure("encodeURIGeneratorFunction: " + t.getMessage(), t);
- }
- };
+ return dateFormat.format(date);
+ }
}