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