01: /*
02: * @(#)setTimeZone.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 pnuts.lang.Context;
12: import pnuts.lang.PnutsFunction;
13: import java.util.TimeZone;
14:
15: public class setTimeZone extends PnutsFunction {
16:
17: public setTimeZone() {
18: super ("setTimeZone");
19: }
20:
21: public boolean defined(int nargs) {
22: return nargs == 1;
23: }
24:
25: protected Object exec(Object[] args, Context context) {
26: if (args.length == 1) {
27: Object arg = args[0];
28: TimeZone tz;
29: if (arg instanceof String) {
30: tz = TimeZone.getTimeZone((String) arg);
31: } else if (arg instanceof TimeZone) {
32: tz = (TimeZone) arg;
33: } else {
34: throw new IllegalArgumentException(String.valueOf(arg));
35: }
36: date.setTimeZone(context, tz);
37: } else {
38: undefined(args, context);
39: }
40: return null;
41: }
42:
43: public String toString() {
44: return "function setTimeZone(String|TimeZone)";
45: }
46: }
|