/*
 * CampoMayorFechaActual.java
 *
 * Created on 9 de abril de 2007, 02:21 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.fidufosyga.rules;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.fidufosyga.rules.util.ValidarFecha;

/**
 * 
 * @author Julian
 */
public class CampoMayorFechaActualMasUnMes extends AbstractRule {

	String DATE_FORMAT = "dd/MM/yyyy";

	SimpleDateFormat sdf;

	// Create object of SimpleDateFormat and pass the desired date format.

	/** Creates a new instance of CampoVacio */
	public CampoMayorFechaActualMasUnMes() {
		sdf = new SimpleDateFormat(DATE_FORMAT);
		sdf.setLenient(false);
	}

	public boolean performValidation(String field, String registro[],
			String nombreArchivo) {
		
		java.util.Calendar cal=java.util.GregorianCalendar.getInstance();
		cal.setLenient(true);
		cal.add(java.util.Calendar.MONTH, 1);
		cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
		 
		// Ahora lo imprimimos
		java.text.SimpleDateFormat format=new java.text.SimpleDateFormat("dd/MM/yyyy");
		//System.out.println("Fecha Calculada: " + format.format(new java.util.Date(cal.getTimeInMillis())));

		
		String Calculo = format.format(new java.util.Date(cal.getTimeInMillis()));
		if (field.length() != 10) {
			return false;
		}
		
		//System.out.println("Fecha dateOtra: " + dateOtra);
		
		Date dateCampo = null;
		Date dateOtra = null;
		if (!ValidarFecha.esFecha(field))
			return false;
		try {
			dateCampo = sdf.parse(field);
			dateOtra = sdf.parse(Calculo);
			System.out.println(field + " - " + format.format(new java.util.Date(cal.getTimeInMillis())));
			System.out.println(dateCampo + " - " + dateOtra);

		} catch (Exception e) {
			return false;
		}

		if (dateCampo.after(dateOtra)) {
			return true;
		}

		return false;
	}
}
