package com.jxml.quick.examples.timesheet;

import java.beans.*;

public class YYYYMMDDEditor extends PropertyEditorSupport 
{
	public static final int[] maxDay=
	{
		31,29,31,30,31,30,31,31,30,31,30,31
	};

	public void setAsText(String text) throws java.lang.IllegalArgumentException 
	{
		if (text.length()!=8)
			throw new IllegalArgumentException("YYYYMMDD length is not 8: "+text);
		int i=Integer.parseInt(text);
		int d=i%100;
		int m=(i/100)%100;
		if (m==0 || m>12)
			throw new IllegalArgumentException("YYYYMMDD month is invalid: "+text);
		if (d==0 || d>maxDay[m])
			throw new IllegalArgumentException("YYYYMMDD day is invalid: "+text);
		Date date=new Date(i);
		setValue(date);
	}
}
