

import java.util.Date;
import com.ibm.websphere.scheduler.*;

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

	/**
	 * Checks that a given delta String is suitable for use with this calendar.
	 * 
	 * @param calendar The calendar to check
	 * @param delta    The delta to be checked
	 * @exception UserCalendarSpecifierInvalid
	 *                   if the calendar parameter is not "seconds"
	 * @exception UserCalendarPeriodInvalid
	 *                   if the delta is not suitable for use with this calendar
	 */
	public void validate(String calendar, String delta)
		throws UserCalendarSpecifierInvalid, UserCalendarPeriodInvalid
	{
		//to check the delta specified, just call applyDelta with the current time
		try
		{
			Date currentTime = new Date(System.currentTimeMillis());
			applyDelta(currentTime, calendar, delta);
		}
		catch (UserCalendarSpecifierInvalid e)
		{
		}
		catch (UserCalendarPeriodInvalid e)
		{
		}
	}

	/**
	 * Increments the base time by a delta. The only supported
	 * 
	 * @param baseTime The base time to which the increment will be added
	 * @param calendar Used by this calendar bean to specify the unit to be scaled.
	 *                 
	 *                 The only accepted value at this time is "seconds"
	 * @param delta    A scalar which determines how much to add onto the base time. The
	 *                 unit to be scaled is determined by the calendar parameter.
	 * @return The new date which is the baseTime + delta
	 * @exception UserCalendarSpecifierInvalid
	 *                   if the calendar parameter is not "seconds"
	 * @exception UserCalendarPeriodInvalid
	 *                   if the delta is not suitable for use with this calendar
	 */
	public java.util.Date applyDelta(
		java.util.Date baseTime,
		String calendar,
		String delta)
		throws UserCalendarSpecifierInvalid, UserCalendarPeriodInvalid
	{
		//check to see if the calendar specified is seconds
		if (calendar.equals("seconds"))
		{
			try
			{
				//the delta should be an integer, but must be converted from it's String representation
				//when the time is incremented, the millisecond value of this number will be used, so calculate this as well
				long incrementMillis = Long.parseLong(delta) * 1000;

				//now calculate the new time by adding the base time to the increment value
				Date returnValue =
					new Date(baseTime.getTime() + incrementMillis);

				return (returnValue);
			}
			catch (NumberFormatException e)
			{
				throw new UserCalendarPeriodInvalid("Only positive whole numbers are supported.");
			}
		}
		else
		{
			throw new UserCalendarSpecifierInvalid("\"seconds\" is the only supported calendar specifier");
		}
	}	
