01: /*
02: * @(#)getMaxDayOfMonth.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.Calendar;
14: import java.util.Date;
15:
16: public class getMaxDayOfMonth extends PnutsFunction {
17:
18: public getMaxDayOfMonth() {
19: super ("getMaxDayOfMonth");
20: }
21:
22: public boolean defined(int narg) {
23: return (narg == 1);
24: }
25:
26: protected Object exec(Object args[], Context context) {
27: if (args.length != 1) {
28: undefined(args, context);
29: return null;
30: }
31: Date d = (Date) args[0];
32: Calendar c = (Calendar) date.getCalendar(d, context).clone();
33: c.add(Calendar.MONTH, 1);
34: c.set(Calendar.DAY_OF_MONTH, 0);
35: return new Integer(c.get(Calendar.DAY_OF_MONTH));
36: }
37:
38: public String toString() {
39: return "function getMaxDayOfMonth(Date)";
40: }
41: }
|