package hibergui.verify;

import java.text.DateFormat;
import java.text.ParseException;

public abstract class DateFormatConstraint implements Constraint {

    private static DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
    private static DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);

    public static boolean parseDate(String s) {
    	if (s == null)
    		return false;
        try {
        	dateFormat.parse(s);
        } catch (ParseException e) {
            return false;
        }
        return true;
    }

    public static boolean parseTime(String s) {
    	if (s == null)
    		return false;
        try {
        	timeFormat.parse(s);
        } catch (ParseException e) {
            return false;
        }
        return true;
    }

    public boolean check(Object o) {
    	return DateFormatConstraint.parseDate((String) o);
    }

}
