コード例 #1
0
 public PartialDateEvent(NotDateTime date, string title, bool isWarrantyEvent)
 {
     this.EventDate       = date;
     this.OrderBy         = date.AsDateTime();
     this.Title           = title;
     this.IsWarrantyEvent = isWarrantyEvent;
 }
コード例 #2
0
        public static DateTime?AsDateTime(this NotDateTime input)
        {
            List <DateTime> dt = new List <DateTime>();

            foreach (var ndt in input.Dates)
            {
                int day   = 1;
                int month = 1;
                int year  = DateTime.Now.Year;

                if (ndt.Day.HasValue && ndt.Day > 0 && ndt.Day < 32)
                {
                    day = ndt.Day.Value;
                }

                if (ndt.Month.HasValue && ndt.Month > 0 && ndt.Month <= 12)
                {
                    month = ndt.Month.Value;
                }

                if (ndt.Year.HasValue && ndt.Year > 2000 && ndt.Year < 2100)
                {
                    year = ndt.Year.Value;
                }

                try
                {
                    dt.Add(new DateTime(year, month, day));
                }
                catch
                {
                    dt.Add(DateTime.Now);
                }
            }

            try
            {
                var dtOrdered = dt.Where(dtx => dtx > DateTime.Now.AddDays(-1)).OrderBy(dtx => dtx).Take(1).First();
                return(dtOrdered);
            }
            catch (Exception e)
            {
                return(null);
            }
        }