getMaxDayOfMonth.java :  » Scripting » Pnuts » org » pnuts » lib » Java Open Source

Java Open Source » Scripting » Pnuts 
Pnuts » org » pnuts » lib » getMaxDayOfMonth.java
/*
 * @(#)getMaxDayOfMonth.java 1.2 04/12/06
 *
 * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
 *
 * See the file "LICENSE.txt" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */
package org.pnuts.lib;

import pnuts.lang.Context;
import pnuts.lang.PnutsFunction;
import java.util.Calendar;
import java.util.Date;

public class getMaxDayOfMonth extends PnutsFunction {

  public getMaxDayOfMonth(){
    super("getMaxDayOfMonth");
  }

  public boolean defined(int narg){
    return (narg == 1);
  }

  protected Object exec(Object args[], Context context) {
    if (args.length != 1){
      undefined(args, context);
      return null;
    }
    Date d = (Date)args[0];
    Calendar c = (Calendar)date.getCalendar(d, context).clone();
    c.add(Calendar.MONTH, 1);
    c.set(Calendar.DAY_OF_MONTH, 0);
    return new Integer(c.get(Calendar.DAY_OF_MONTH));
  }

  public String toString(){
    return "function getMaxDayOfMonth(Date)";
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.