package cnp.ew.converter;
import java.util.*;

/**
 * Used to display the seconds portion of a date, using a prespecified
 * format. It is typically used as a component in converting seconds
 * to a full string with a prespecified format, where the seconds output
 * is just one portion of the string.  Example usage:
 * <pre>
 *    CpSecondsToString converter = new CpSecondsToString("ss");
 *    convertedString = converter.convertDate(new Date("3/1/95 11:30"));
 * </pre>
 *
 * @see            cnp.ew.util.CpDateToStringConverter
 * @version        $Version$
 * @author         $Author: Ken $
 */
public class CpSecondToString extends CpDateUnitToString
{
    /**
     * Creates a new converter, with the given format for conversion.
     * @param formatString  Possible formats are:
     *      "s"    seconds in one or two digits, as needed (0 to 59)
     *      "ss"   seconds in two digits (00 to 59).
     */
    public CpSecondToString(String formatString)
    {
        super(formatString);
    }

    /**
     * Converts a given date to the appropriate string for the
     * predefined format.
     */
    public String convertDate(Date d)
    {
        if (formatStyle == 1) {
            return "" + d.getSeconds();
        } else {
            return prefixWithZero(d.getSeconds());
        }
    }
}
