package com.flytxt.tp.translator;

import static org.junit.Assert.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.junit.Test;

import com.flytxt.tp.marker.Marker;
import com.flytxt.tp.translator.TpDate;

public class TpDateTest extends TpAbsTest {

	TpDate tpDate = new TpDate();

	@Test
	public final void testConvertDate() {
		//fail("Not yet implemented");
	}

	@Test
	public final void testAfter() {
		SimpleDateFormat sdf = new SimpleDateFormat("ddmmyyy HH:mm:ss");
		String d1 = "01022012 12:00:00";
		String d2 = "01022013 12:00:00";
		Marker m1 = getMarker(d1);
		Marker m2 = getMarker(d2);
		try {
			assertEquals(sdf.parse(d1).after(sdf.parse(d2)), tpDate.after(m1,  m2));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Test
	public final void testBefore() {
		SimpleDateFormat sdf = new SimpleDateFormat("ddmmyyy HH:mm:ss");
		String d1 = "01022012 12:00:00";
		String d2 = "01022013 12:00:00";
		Marker m1 = getMarker(d1);
		Marker m2 = getMarker(d2);
		try {
			assertEquals(sdf.parse(d1).before(sdf.parse(d2)), tpDate.before( m1,  m2));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Test
	public final void testDifferenceInMillis() {
		//fail("Not yet implemented");
	}

	@Test
	public void extractDateFromLine(){
		final String str = 
				//"1,22,1,1,,45,30,False$2011-11-11T12:00:00-05:00+FAlse*,,,-False^False,1,0,,,,,,,,,,,1,1";
				"1,22,1,1,,45,30,False$2011-11-11T12:00:00+FAlse*,,,-False^False,1,0,,,,,,,,,,,1,1";
        final Marker line = getMarker(str);
		Marker tmp = markerFactory.createMarker(null, 0, 0);
		Marker tmp1 = markerFactory.createMarker(null, 0, 0);
		line.splitAndGetMarkers("$".getBytes(), new int[]{1}, markerFactory, tmp);
		tmp.splitAndGetMarkers("+".getBytes(), new int[]{0}, markerFactory, tmp1);
		try {
			tmp1 = tpDate.convertDate(tmp1, markerFactory, "yyyy-mm-dd'T'HH:mm:ss");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

@@ -2071,10 +2071,671 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void extractDateWithZFromLine()%7B%0A%09%09final String str = %0A%09%09%09%09%221,22,1,1,,45,30,False$2011-11-11T12:00:00-05:00+FAlse*,,,-False%5EFalse,1,0,,,,,,,,,,,1,1%22;%0A        final Marker line = getMarker(str);%0A%09%09Marker tmp = markerFactory.createMarker(null, 0, 0);%0A%09%09Marker tmp1 = markerFactory.createMarker(null, 0, 0);%0A%09%09line.splitAndGetMarkers(%22$%22.getBytes(), new int%5B%5D%7B1%7D, markerFactory, tmp);%0A%09%09tmp.splitAndGetMarkers(%22+%22.getBytes(), new int%5B%5D%7B0%7D, markerFactory, tmp1);%0A%09%09try %7B%0A%09%09%09tmp1 = tpDate.convertDate(tmp1, markerFactory, %22yyyy-mm-dd'T'HH:mm:ssX%22);%0A%09%09%7D catch (ParseException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

test cases for parsing date with time zone