using System;
using System.Threading;

namespace Quadarax.Foundation.Core.QConsole.Value
{
    public class DateValue : AbstractValue
    {
        protected string _dateformat;

        public DateValue() : base()
        {

        }

        public DateValue(DateTime value, string dateFormat) : base(typeof(DateTime), value)
        {
            _dateformat = dateFormat;
        }
        public DateValue(DateTime value) : base(typeof(DateTime), value)
        {
            _dateformat = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern;
        }

        protected override object ConvertStringToValue(string valueAsString)
        {
            return DateTime.Parse(valueAsString);
        }

        public override string AsString()
        {
            return HasValue ? ((DateTime)Get()).ToString(_dateformat) : string.Empty;
        }
    }
}
