Beispiel #1
0
        public ActionResult OnSubmit(DateViewModel model)
        {
            if (ModelState.IsValid)
            {
                ModelState.Clear();
                if (!DateCompare.IsValidDateString(model.FromDate))
                {
                    ModelState.AddModelError("FromDate", "Please Enter Valid Date in dd/MM/yyyy format");
                }
                else if (!DateCompare.IsValidDateString(model.ToDate))
                {
                    ModelState.AddModelError("ToDate", "Please Enter Valid Date in dd/MM/yyyy format");
                }
                else if (!DateCompare.IsFromDateLessThanToDate(model.FromDate, model.ToDate))
                {
                    ModelState.AddModelError("FromDate", "From Date should be less than To Date");
                }
                else
                {
                    model.TotalDays = DateCompare.GetDifference(model.FromDate, model.ToDate);
                }
            }

            return(View("Index", model));
        }
Beispiel #2
0
        /// <summary>
        /// Unlocks delay if the current date is greater than continued date
        /// </summary>
        /// <param name="currDate">The current date</param>
        public void Unlock(DateAndTime currDate)
        {
            if (DateDelayed != null && DateContinued != null)
            {
                DateCompare compare = TimeAndDateUtility.ComputeDiff(DateDelayed, currDate, DateContinued).Comparison;
                Lock = compare != DateCompare.None;

                if (!Lock)
                {
                    DateDelayed   = null;
                    DateContinued = null;
                }
            }
        }
        private string[] CalculateStatus(DateAndTime start, SavedEvent @event, DateAndTime end)
        {
            (TimeSpan TimeDiff, DateCompare Comparison)diff =
                TimeAndDateUtility.ComputeDiff(start, (@event.ActivationDate, @event.DeactivationDate), end);

            DateCompare comparison = diff.Comparison;
            string      template   = string.Empty;

            if (@event.Completed)
            {
                template = COMPLETED;
            }
            else if (comparison == DateCompare.Before)
            {
                template = STARTS_IN;
            }
            else if (comparison == DateCompare.During)
            {
                template = ENDS_IN;
            }
            else if (comparison == DateCompare.After)
            {
                template = OVERDUE_FROM;
            }

            TimeSpan span = diff.TimeDiff;

            string days  = $"{span.Days}D";
            string hours = $"{span.Hours}H";
            string mins  = $"{span.Minutes}M";
            string secs  = $"{span.Seconds}S";

            string resultString =
                template == COMPLETED ?
                template
                    : template
                + (span.Days > 0 ? days + " " : string.Empty)
                + (span.Hours > 0 ? hours + " " : string.Empty)
                + (span.Minutes > 0 ? mins + " " : string.Empty)
                + (span.Seconds > 0 ? secs : string.Empty);

            return(new string[] { @event.Title, resultString.Trim() });
        }
 /// <summary>
 /// Determines if the date fulfills the comparison
 /// </summary>
 /// <param name="Date">Date to check</param>
 /// <param name="Comparison">Comparison type (can be combined, so you can do weekday in the future, etc)</param>
 /// <returns>True if it is, false otherwise</returns>
 public static bool Is(this DateTime Date, DateCompare Comparison)
 {
     if (Comparison.HasFlag(DateCompare.InFuture) && DateTime.Now >= Date)
     {
         return(false);
     }
     if (Comparison.HasFlag(DateCompare.InPast) && DateTime.Now <= Date)
     {
         return(false);
     }
     if (Comparison.HasFlag(DateCompare.Today) && DateTime.Today != Date.Date)
     {
         return(false);
     }
     if (Comparison.HasFlag(DateCompare.WeekDay) && ((int)Date.DayOfWeek == 6 || (int)Date.DayOfWeek == 0))
     {
         return(false);
     }
     if (Comparison.HasFlag(DateCompare.WeekEnd) && (int)Date.DayOfWeek != 6 && (int)Date.DayOfWeek != 0)
     {
         return(false);
     }
     return(true);
 }
 /// <summary>
 /// Determines if the date fulfills the comparison
 /// </summary>
 /// <param name="Date">Date to check</param>
 /// <param name="Comparison">Comparison type (can be combined, so you can do weekday in the future, etc)</param>
 /// <returns>True if it is, false otherwise</returns>
 public static bool Is(this DateTime Date, DateCompare Comparison)
 {
     if (Comparison.HasFlag(DateCompare.InFuture) && DateTime.Now >= Date)
         return false;
     if (Comparison.HasFlag(DateCompare.InPast) && DateTime.Now <= Date)
         return false;
     if (Comparison.HasFlag(DateCompare.Today) && DateTime.Today != Date.Date)
         return false;
     if (Comparison.HasFlag(DateCompare.WeekDay) && ((int)Date.DayOfWeek == 6 || (int)Date.DayOfWeek == 0))
         return false;
     if (Comparison.HasFlag(DateCompare.WeekEnd) && (int)Date.DayOfWeek != 6 && (int)Date.DayOfWeek != 0)
         return false;
     return true;
 }
Beispiel #6
0
 public DateRangeFilter(DateTime date, DateCompare compare)
 {
     _date    = date;
     _compare = compare;
 }