/*
 * Copyright (c) 2015, StrategyQuant - All rights reserved.
 *
 * Code in this file was made in a good faith that it is correct and does what it should. 
 * If you found a bug in this code OR you have an improvement suggestion OR you want to include 
 * your own code snippet into our standard library please contact us at:
 * http://tasks.strategyquant.com/projects/snippets/
 *
 * This code can be used only within StrategyQuant products. 
 * Every owner of valid (free, trial or commercial) license of any StrategyQuant product 
 * is allowed to freely use, copy, modify or make derivative work of this code without limitations,
 * to be used in all StrategyQuant products and share his/her modifications or derivative work 
 * with the StrategyQuant community.
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES 
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *  
 */
package com.strategyquant.extend.Test;

import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.strategyquant.lib.results.SQResult;
import com.strategyquant.lib.results.SQResultsGroup;
import com.strategyquant.lib.results.SQStats;
import com.strategyquant.lib.scripter.Program;
import com.strategyquant.lib.settings.SQConst;
import com.strategyquant.lib.tests.TestOutput;
import com.strategyquant.lib.tests.TestScript;
import com.strategyquant.lib.time.DateTimeParser;


public class EAADateTimeParser extends TestScript {
	public EAADateTimeParser() {
		setCategory("EAA Loaders");
		setName("EAA DateTime Parser");
	}
	
	@Override
	public void runTest() {

		DateTimeParser fdtp = new DateTimeParser();
		
		try {
			fdtp.recognizeDateFormat(Arrays.asList("12/12/2012", "12/9/2012", "13/1/2012"));
			assertEquals("dd/MM/yyyy", "dd/MM/yyyy", fdtp.getDateFormat());
			assertEquals("12.09.2012", "12.09.2012", fdtp.parse("12/9/2012").toDateString()); //test format "dd.MM.yyyy"
			
			fdtp.recognizeDateFormat(Arrays.asList("12/12/2012", "12/9/2012", "12/25/2012"));
			assertEquals("MM/dd/yyyy", "MM/dd/yyyy", fdtp.getDateFormat());
			assertEquals("09.12.2012", "09.12.2012", fdtp.parse("12/9/2012").toDateString()); //test format "dd.MM.yyyy"

			fdtp.recognizeDateFormat(Arrays.asList("12.12.2012", "12.9.2012", "17.1.2012"));
			assertEquals("dd.MM.yyyy", "dd.MM.yyyy", fdtp.getDateFormat());
			assertEquals("12.09.2012", "12.09.2012", fdtp.parse("12.9.2012").toDateString()); //test format "dd.MM.yyyy"
			
			fdtp.recognizeDateFormat(Arrays.asList("12.12.2012", "12.9.2012", "12.25.2012"));
			assertEquals("MM.dd.yyyy", "MM.dd.yyyy", fdtp.getDateFormat());
			
			fdtp.recognizeDateFormat(Arrays.asList("12-12-2012", "12-9-2012", "12-1-2012"));
			assertEquals("dd-MM-yyyy", "dd-MM-yyyy", fdtp.getDateFormat());
			
			fdtp.recognizeDateFormat(Arrays.asList("12-12-2012", "12-9-2012", "12-25-2012"));
			assertEquals("MM-dd-yyyy", "MM-dd-yyyy", fdtp.getDateFormat());
			
			
			
			fdtp.recognizeDateFormat(Arrays.asList("08/08/11", "07/28/11", "11/01/11"));
			assertEquals("MM/dd/yyyy", "MM/dd/yyyy", fdtp.getDateFormat());
			assertEquals("01.11.2011", "01.11.2011", fdtp.parse("11/01/11").toDateString()); //test format "dd.MM.yyyy"
			
			fdtp.recognizeDateFormat(Arrays.asList("08/08/11", "07/08/11", "21/01/11"));
			assertEquals("dd/MM/yyyy", "dd/MM/yyyy", fdtp.getDateFormat());
			assertEquals("07.08.2011", "07.08.2011", fdtp.parse("07/08/11").toDateString()); //test format "dd.MM.yyyy"
			
			fdtp.recognizeDateFormat(Arrays.asList("08-08-11", "07-28-11", "11-01-11"));
			assertEquals("MM-dd-yyyy", "MM-dd-yyyy", fdtp.getDateFormat());
			
			fdtp.recognizeDateFormat(Arrays.asList("08-08-11", "07-08-11", "21-01-11"));
			assertEquals("dd-MM-yyyy", "dd-MM-yyyy", fdtp.getDateFormat());
			
			fdtp.recognizeDateFormat(Arrays.asList("08.08.11", "07.28.11", "11.01.11"));
			assertEquals("MM.dd.yyyy", "MM.dd.yyyy", fdtp.getDateFormat());			
			
			fdtp.recognizeDateFormat(Arrays.asList("08.08.11", "07.08.11", "21.01.11"));
			assertEquals("dd.MM.yyyy", "dd.MM.yyyy", fdtp.getDateFormat());
			
			
			
			fdtp.recognizeDateFormat(Arrays.asList("2013/10/15 16:16:39", "2013/10/22 16:16:39", "2013/10/25 16:16:39"));
			assertEquals("yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", fdtp.getDateFormat());
			assertEquals("22.10.2013", "22.10.2013", fdtp.parse("2013/10/22 16:16:39").toDateString()); //test format "dd.MM.yyyy"
			
			fdtp.recognizeDateFormat(Arrays.asList("11-08-2013 10:20:56", "21-08-2013 10:20:56", "31-08-2013 10:20:56"));
			assertEquals("dd-MM-yyyy HH:mm:ss", "dd-MM-yyyy HH:mm:ss", fdtp.getDateFormat());

			fdtp.recognizeDateFormat(Arrays.asList("11/08/2013 10:20", "08/21/2013 10:20", "08/30/2013 10:20"));
			assertEquals("MM/dd/yyyy HH:mm", "MM/dd/yyyy HH:mm", fdtp.getDateFormat());
			
			fdtp.recognizeDateFormat(Arrays.asList("2013.12.15", "2013.11.18", "2013.12.15"));
			assertEquals("yyyy.MM.dd", "yyyy.MM.dd", fdtp.getDateFormat());
			
		} catch(Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}
}