/*
 *  Draco Econometrics
 *  Copyright (C) 2006-2007 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.datamodel;

public class MonthText {

	private static final String[] JANUARY = {"january","jan","enero"};
	
	private static final String[] FEBRUARY = {"february","feb","febrero"};
	
	private static final String[] MARCH = {"march","mar","marzo"};
	
	private static final String[] APRIL = {"april","apr","abril"};
	
	private static final String[] MAY = {"may","mayo"};
	
	private static final String[] JUNE = {"june","jun","junio"};
	
	private static final String[] JULY = {"july","jul","julio"};
	
	private static final String[] AUGUST = {"august","aug","augosto"};
	
	private static final String[] SEPTEMBER = {"september","sep","sept","septiembre"};
	
	private static final String[] OCTOBER = {"october","oct","octubre"};
	
	private static final String[] NOVEMBER = {"november","nov","noviembre"};
	
	private static final String[] DECEMBER = {"december","dec","diciembre"};

	public static int GetMonthFromText(String text) {
		
		String find = text.toLowerCase();
		
		if(CheckMonth(find,JANUARY)) return 1;
		if(CheckMonth(find,FEBRUARY)) return 2;
		if(CheckMonth(find,MARCH)) return 3;
		if(CheckMonth(find,APRIL)) return 4;
		if(CheckMonth(find,MAY)) return 5;
		if(CheckMonth(find,JUNE)) return 6;
		if(CheckMonth(find,JULY)) return 7;
		if(CheckMonth(find,AUGUST)) return 8;
		if(CheckMonth(find,SEPTEMBER)) return 9;
		if(CheckMonth(find,OCTOBER)) return 10;
		if(CheckMonth(find,NOVEMBER)) return 11;
		if(CheckMonth(find,DECEMBER)) return 12;
		
		return -1;
	}
	
	private static boolean CheckMonth(String text, String[] possibles) {
		for(int i=0;i<possibles.length;i++) {
			if(text.indexOf(possibles[i]) != -1) return true;
		}
		return false;
	}
	
}
