package china.jiangkai.tool;

public class DateTool
{
	private static DateTool dt = null;

	public static final int YEAR_BASE = 360;
	public static final int MONTH_BASE = 30;
	public static final int WEEK_BASE = 10;

	public static final int JANUARY = 0;
	public static final int FEBRUARY = 1;
	public static final int MARCH = 2;
	public static final int APRIL = 3;
	public static final int MAY = 4;
	public static final int JUNE = 5;
	public static final int JULY = 6;
	public static final int AUGUST = 7;
	public static final int SEPTEMBER = 8;
	public static final int OCTOBER = 9;
	public static final int NOVEMBER = 10;
	public static final int DECEMBER = 11;

	public static final int SPRING = 0;
	public static final int SUMMER = 1;
	public static final int AUTUMN = 2;
	public static final int WINTER = 3;

	public static final int EARLY_WEEK = 0;
	public static final int MIDDLE_WEEK = 1;
	public static final int LATE_WEEK = 2;

	private static final String[] NUM_TO_STR_LIST =
	{
			"〇", "一", "二", "三", "四", "五", "六", "七", "八", "九",
	};
	private static final String[] MONTH_TO_STR_LIST =
	{
			"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月",
			"十二月",
	};
	private static final String[] SEASON_TO_STR_LIST =
	{
			"春", "夏", "秋", "冬",
	};
	private static final String[] WEEK_TO_STR_LIST =
	{
			"上旬", "中旬", "下旬",
	};

	private DateTool()
	{

	}

	public static DateTool getInstance()
	{
		if ( dt == null )
		{
			dt = new DateTool();
		}
		return dt;
	}

	public static int getCurrentYear( int days )
	{
		return (int)(days / YEAR_BASE);
	}

	public static int getCurrentMonth( int days )
	{
		return (int)((days % YEAR_BASE) / MONTH_BASE);
	}

	public static int getCurrentSeason( int days )
	{
		switch ( getCurrentMonth( days ) )
		{
		case MARCH:
		case APRIL:
		case MAY:
			return 0;
		case JUNE:
		case JULY:
		case AUGUST:
			return 1;
		case SEPTEMBER:
		case OCTOBER:
		case NOVEMBER:
			return 2;
		case DECEMBER:
		case JANUARY:
		case FEBRUARY:
			return 3;
		}
		return -1;
	}

	public static int getCurrentWeek( int days )
	{
		return (int)((days % MONTH_BASE) / WEEK_BASE);
	}

	public static int getCurrentDay( int days )
	{
		return (int)(days % MONTH_BASE + 1);
	}

	public static String showCurrentYear( int days, int base )
	{
		int year = getCurrentYear( days ) + base;
		StringBuilder sb = new StringBuilder();
		while ( year > 0 )
		{
			sb.insert( 0, NUM_TO_STR_LIST[ year % 10 ] );
			year = year / 10;
		}
		while ( sb.charAt( 0 ) == '〇' )
		{
			sb.deleteCharAt( 0 );
		}
		sb.append( "年" );
		return sb.toString();
	}

	public static String showCurrentMonth( int days )
	{
		return MONTH_TO_STR_LIST[ getCurrentMonth( days ) ];
	}

	public static String showCurrentSeason( int days )
	{
		return SEASON_TO_STR_LIST[ getCurrentSeason( days ) ];
	}

	public static String showCurrentWeek( int days )
	{
		return WEEK_TO_STR_LIST[ getCurrentWeek( days ) ];
	}

	public static String showCurrentDay( int days )
	{
		int day = getCurrentDay( days );
		StringBuilder sb = new StringBuilder();
		int ten = day / 10;
		switch ( ten )
		{
		case 0:
			sb.append( NUM_TO_STR_LIST[ day ] );
			sb.append( "日" );
			break;
		case 1:
			sb.append( "十" );
			if ( day > 10 )
			{
				sb.append( NUM_TO_STR_LIST[ day - 10 ] );
			}
			sb.append( "日" );
			break;
		default:
			sb.append( NUM_TO_STR_LIST[ ten ] );
			sb.append( "十" );
			if ( day % 10 != 0 )
			{
				sb.append( NUM_TO_STR_LIST[ day % 10 ] );
			}
			sb.append( "日" );
			break;
		}
		return sb.toString();
	}

	public static String showCurrentDate( int days, int base )
	{
		return showCurrentYear( days, base ) + " " + showCurrentMonth( days )
				+ " " + showCurrentDay( days ) + " " + showCurrentSeason( days )
				+ " " + showCurrentWeek( days );
	}
}
