01: /*
02: * @(#)getTimeZone.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 getTimeZone extends PnutsFunction {
16:
17: private final static String TIMEZONE = "pnuts$lib$timezone"
18: .intern();
19:
20: public getTimeZone() {
21: super ("getTimeZone");
22: }
23:
24: public boolean defined(int nargs) {
25: return nargs == 0 || nargs == 1;
26: }
27:
28: protected Object exec(Object[] args, Context context) {
29: if (args.length == 0) {
30: TimeZone zone = (TimeZone) context.get(TIMEZONE);
31: if (zone == null) {
32: context.set(TIMEZONE, zone = TimeZone.getDefault());
33: }
34: return zone;
35: } else if (args.length == 1) {
36: return TimeZone.getTimeZone((String) args[0]);
37: } else {
38: undefined(args, context);
39: return null;
40: }
41: }
42:
43: public String toString() {
44: return "function getTimeZone( { id } )";
45: }
46: }
|