package junkutil.common;

import java.util.Calendar;
import java.util.Map;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * 設定ファイルの読み込みをテストする。
 * @author Hiroyuki Shiota
 */
public class DateUtilTest extends TestCase {
	/**
	 * コンストラクタ
	 * @param name
	 */
	public DateUtilTest(String name) {
		super(name);
	}

	/**
	 * @return
	 */
	public static Test suite() {
		TestSuite test = new TestSuite("DateUtilTest");
		test.addTest(new TestSuite(DateUtilTest.class));
		return test;
	}

	/**
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
	}

	/**
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
	}

	/**
	 * @throws Exception
	 */
	public void testDiffString() throws Exception {
		Calendar timeCal = Calendar.getInstance();

		String timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("0秒前"));

		timeCal.add(Calendar.SECOND, -30);
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("30秒前"));

		timeCal.add(Calendar.MINUTE, -15);
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("15分前"));

		timeCal.add(Calendar.HOUR, -3);
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("3時間前"));

		Calendar testCal = Calendar.getInstance();
		timeCal.set(testCal.get(Calendar.YEAR), testCal.get(Calendar.MONTH), testCal.get(Calendar.DAY_OF_MONTH)-8);
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("8日前"));

		timeCal.set(testCal.get(Calendar.YEAR), testCal.get(Calendar.MONTH)-1, testCal.get(Calendar.DAY_OF_MONTH));
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("1ヶ月前"));

		timeCal.set(testCal.get(Calendar.YEAR), testCal.get(Calendar.MONTH)-3, testCal.get(Calendar.DAY_OF_MONTH));
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("3ヶ月前"));

		timeCal.set(testCal.get(Calendar.YEAR)-1, testCal.get(Calendar.MONTH), testCal.get(Calendar.DAY_OF_MONTH));
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("1年前"));

		timeCal.set(testCal.get(Calendar.YEAR)-2, testCal.get(Calendar.MONTH), testCal.get(Calendar.DAY_OF_MONTH));
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("2年前"));

		timeCal.set(testCal.get(Calendar.YEAR)-3, testCal.get(Calendar.MONTH), testCal.get(Calendar.DAY_OF_MONTH));
		timeString = DateUtil.dateDiff(timeCal.getTime());
		assertTrue(timeString.equals("3年前"));
	}

}
