using JetBrains.Annotations;

namespace AyCode.Utils.Extensions
{
    public static class DateTimeExtension
    {
        public static bool IsNullOrEmpty(this DateTime dateTime) => dateTime == DateTime.MinValue;
        
        [ContractAnnotation("dateTime:null => true; dateTime:notnull <= false")]
        public static bool IsNullOrEmpty(this DateTime? dateTime) => dateTime == null || dateTime == DateTime.MinValue;

        public static bool IsEqualSqlDateTime2(this DateTime dtSource, DateTime dateTime)
        {
            return dtSource == dateTime || 
                   (dtSource.Kind == dateTime.Kind &&
                   dtSource.Millisecond == dateTime.Millisecond && dtSource.Hour == dateTime.Hour && dtSource.Second == dateTime.Second && dtSource.Minute == dateTime.Minute &&
                   dtSource.Day == dateTime.Day && dtSource.Month == dateTime.Month && dtSource.Year == dateTime.Year);
        }
    }
}
