using PlcSiemens.Core.Common;

namespace PlcSiemens.Core.Extension
{
    /// <summary>
    ///     时间帮助扩展类
    /// </summary>
    public static class DateTimeExtension
    {
        private static readonly DateTime MinDate = new DateTime(1970, 1, 1);
        private static readonly DateTime MaxDate = new DateTime(9999, 12, 31, 23, 59, 59, 999);

        /// <summary>
        /// 当前时间是否有效范围之内
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static bool IsValid(this DateTime target)
        {
            return (target >= MinDate) && (target <= MaxDate);
        }

        /// <summary>时间日期转为yyyy-MM-dd HH:mm:ss完整字符串，支持指定最小时间的字符串</summary>
        public static string ToFullString(this DateTime value, string emptyValue = null)
        {
            return new DefaultConvert().ToFullString(value, emptyValue);
        }

        /// <summary>时间日期转为指定格式字符串</summary>
        public static string ToString(this DateTime value, string format, string emptyValue)
        {
            return new DefaultConvert().ToString(value, format, emptyValue);
        }
    }
}
