using System;
using System.Collections;
using System.Text;

using Medivators.Common;
using Medivators.Common.Enums;
using Medivators.Common.Logging;

namespace Medivators.BusinessObjects
{
	class DSD201DateTime 
	{
		private DateTime			_date = DateTime.MinValue;

		public string DateString
		{
			get { return DSD201DateConverter(_date); }
			set { _date = DSD201DateConverter(value); }
		}
		public DateTime Date 
		{
			get { return _date; }
			set { _date = value; }
		}
		public static DateTime DSD201DateConverter(string DSD201DateString)
		{
			try
			{				
				string day = DSD201DateString.Substring(0, 2);
				string month = DSD201DateString.Substring(2, 3);
				string hour = DSD201DateString.Substring(5, 2);
				string minute = DSD201DateString.Substring(7, 2);
				string year = DSD201DateString.Substring(9, 2);
				
				return Convert.ToDateTime(string.Format("{0} {1} {2} {3}:{4}", day, month, year, hour, minute));
			}
			catch (Exception ex)
			{
				ErrorHandler.GetInstance().LogException(LogEntryType.DebugTrace, "Error casting from DSD201 Date: " + ex.ToString());
				return DateTime.MinValue;
			}
		}
		public static string DSD201DateConverter(DateTime Date)
		{
			try
			{
				return string.Format("{0}{1}{2}{3}{4}",
					Date.Day.ToString("00"),
					Date.ToString("MMM"),
					Date.Hour.ToString("00"),
					Date.Minute.ToString("00"), 
					Date.Year.ToString("00"));										
			}
			catch (Exception ex)
			{
				ErrorHandler.GetInstance().LogException(LogEntryType.DebugTrace, "Error casting to DSD201 Date: " + ex.ToString());
				return "01JAN000000";
			}
		}
	}
}
