01: /*
02: * @(#)formatDateTime.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lib;
10:
11: import java.util.Date;
12: import pnuts.lang.Context;
13: import pnuts.lang.PnutsFunction;
14:
15: public class formatDateTime extends PnutsFunction {
16:
17: public formatDateTime() {
18: super ("formatDateTime");
19: }
20:
21: public boolean defined(int nargs) {
22: return nargs >= 1 && nargs <= 3;
23: }
24:
25: protected Object exec(Object[] args, Context context) {
26: int nargs = args.length;
27: if (nargs == 1) {
28: return DateTimeFormat.formatDateTime((Date) args[0],
29: context);
30: } else if (nargs == 2) {
31: return DateTimeFormat.formatDateTime((Date) args[0],
32: (String) args[1], context);
33: } else if (nargs == 3) {
34: return DateTimeFormat.formatDateTime((Date) args[0],
35: (String) args[1], (String) args[2], context);
36: } else {
37: undefined(args, context);
38: return null;
39: }
40: }
41:
42: public String toString() {
43: return "function formatDateTime(date {, pattern }) or (date, style1, style2)";
44: }
45: }
|