/*
 *  Copyright (C) 2011 The Animo Project
 *  http://animotron.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.animotron.addon.datetime;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import org.junit.Test;


/**
 * @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
 *
 */
public class DateTimeTests {
	
	@Test
	public void formats() throws IllegalArgumentException {
		//year
		check("Y1975");
		
		//month
		check("M02");
		
		try {
			check("M14");
			assertFalse(true);
		} catch (IllegalArgumentException e) {
		}
		
		//hour
		check("h03");
		check("h3");

		try {
			check("h25");
			assertFalse(true);
		} catch (IllegalArgumentException e) {
		}

		//minute
		check("m03");
		check("m3");

		try {
			check("m60");
			assertFalse(true);
		} catch (IllegalArgumentException e) {
		}

		//second
		check("s03");
		check("s3");

		try {
			check("s60");
			assertFalse(true);
		} catch (IllegalArgumentException e) {
		}

		//time
		check("T03-10");
		check("T3-2");

		try {
			check("T24-1");
			assertFalse(true);
		} catch (IllegalArgumentException e) {
		}

		try {
			check("T23-60");
			assertFalse(true);
		} catch (IllegalArgumentException e) {
		}

		check("P3s");
	}
	
	private void check(String str) throws IllegalArgumentException {
		TimestampNode t = TimestampNode.getInstance(null, str);
		
		assertEquals(str, t.getProperty("NAME"));
	}

}

@@ -1828,27 +1828,42 @@
  %7B%0A%09%09%7D%0A%0A
-%09%09try %7B%0A%09%09%09
+        try %7B%0A            
 check(%22T
@@ -1867,27 +1867,36 @@
 (%22T23-60%22);%0A
-%09%09%09
+            
 assertFalse(
@@ -1894,34 +1894,40 @@
 ertFalse(true);%0A
-%09%09
+        
 %7D catch (Illegal
@@ -1953,28 +1953,147 @@
 ) %7B%0A
-%09%09%7D%0A%0A%09%09check(%22P3s%22);
+        %7D%0A%0A        try %7B%0A            check(%22P3s%22);%0A            assertFalse(true);%0A        %7D catch (IllegalArgumentException e) %7B%0A        %7D%0A
 %0A%09%7D%0A

fix DateTime test