package app.android.gambit.test;


import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

import android.test.AndroidTestCase;
import app.android.gambit.InternetDateTime;


public class InternetDateTimeTests extends AndroidTestCase
{
	public void testFromStringPositiveOffset() {
		InternetDateTime dateTime = new InternetDateTime("2000-10-21T21:56:12.123+01:10");

		Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
		calendar.setTime(dateTime.toDate());

		assertEquals(2000, calendar.get(Calendar.YEAR));
		assertEquals(10, calendar.get(Calendar.MONTH) + 1); // January is 0 for GregorianCalendar
		assertEquals(21, calendar.get(Calendar.DAY_OF_MONTH));
		assertEquals(23, calendar.get(Calendar.HOUR_OF_DAY));
		assertEquals(6, calendar.get(Calendar.MINUTE));
		assertEquals(12, calendar.get(Calendar.SECOND));
	}

	public void testFromStringNegativeOffset() {
		InternetDateTime dateTime = new InternetDateTime("2000-10-21T21:56:12.123-01:10");

		Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
		calendar.setTime(dateTime.toDate());

		assertEquals(2000, calendar.get(Calendar.YEAR));
		assertEquals(10, calendar.get(Calendar.MONTH) + 1); // January is 0 for GregorianCalendar
		assertEquals(21, calendar.get(Calendar.DAY_OF_MONTH));
		assertEquals(20, calendar.get(Calendar.HOUR_OF_DAY));
		assertEquals(46, calendar.get(Calendar.MINUTE));
		assertEquals(12, calendar.get(Calendar.SECOND));
	}

	public void testFromStringZeroOffset() {
		InternetDateTime dateTime = new InternetDateTime("2000-10-21T21:56:12.123Z");

		Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
		calendar.setTime(dateTime.toDate());

		assertEquals(2000, calendar.get(Calendar.YEAR));
		assertEquals(10, calendar.get(Calendar.MONTH) + 1); // January is 0 for GregorianCalendar
		assertEquals(21, calendar.get(Calendar.DAY_OF_MONTH));
		assertEquals(21, calendar.get(Calendar.HOUR_OF_DAY));
		assertEquals(56, calendar.get(Calendar.MINUTE));
		assertEquals(12, calendar.get(Calendar.SECOND));
	}

	public void testToStringPositiveOffset() {
		InternetDateTime dateTime = new InternetDateTime("2000-10-21T21:56:12.123+01:10");
		String converted = dateTime.toString();

		assertEquals("2000-10-21T23:06:12.123Z", converted);
	}

	public void testToNegativeZeroOffset() {
		InternetDateTime dateTime = new InternetDateTime("2000-10-21T21:56:12.123-01:10");
		String converted = dateTime.toString();

		assertEquals("2000-10-21T20:46:12.123Z", converted);
	}

	public void testToStringZeroOffset() {
		InternetDateTime dateTime = new InternetDateTime("2000-10-21T21:56:12.123Z");
		String converted = dateTime.toString();

		assertEquals("2000-10-21T21:56:12.123Z", converted);
	}
}

@@ -725,17 +725,17 @@
 Equals(2
-3
+0
 , calend
@@ -780,16 +780,17 @@
 tEquals(
+4
 6, calen
@@ -1325,33 +1325,33 @@
 %09%09assertEquals(2
-0
+3
 , calendar.get(C
@@ -1380,33 +1380,32 @@
 %0A%09%09assertEquals(
-4
 6, calendar.get(
@@ -2281,19 +2281,19 @@
 21T2
-3:0
+0:4
 6:12.
-123
+000
 Z%22, 
@@ -2510,19 +2510,19 @@
 21T2
-0:4
+3:0
 6:12.
-123
+000
 Z%22, 
@@ -2736,19 +2736,19 @@
 1:56:12.
-123
+000
 Z%22, conv

Fix tests for internet date-time.