package com.tandbergtv.watchpoint.pmm.web.validators;

import java.text.SimpleDateFormat;
import java.util.ResourceBundle;

import com.tandbergtv.watchpoint.pmm.web.util.CommonUtils;

/**
 * Utility class for validation classes.
 * 
 * @author Raj Prakash
 */
class ValidatorUtil {

	/**
	 * Checks if the given value is a valid date.
	 * 
	 * @see ValidatorUtil#DATE_FORMAT
	 */
	static boolean isValidDate(String value) {
		try {
			String pattern = CommonUtils.getApplicationUIResourceBundle().getString(CommonUtils.DATE_FORMAT);
			SimpleDateFormat df = new SimpleDateFormat(pattern);
			df.setLenient(false); // this is important!
			df.parse(value);
			return value.length() == 10;
		} catch (Exception e) {
			return false;
		}
	}

	/* Get the Date Pattern used for dates in the user interface */
	static String getDatePattern() {
		ResourceBundle bundle = CommonUtils.getApplicationUIResourceBundle();
		return bundle.getString(CommonUtils.DATE_FORMAT);
	}

}
