using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Quadarax.Foundation.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 = 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;
        }
    }
}
