Beispiel #1
0
        protected override void Execute(CodeActivityContext context)
        {
            DateTime DT1 = Date1DT.Get(context);
            DateTime DT2 = Date2DT.Get(context);

            Dictionary <String, Int32> dict = new Dictionary <string, int>();

            if (DT1 == DateTime.MinValue && DT2 == DateTime.MinValue)
            {
                throw new ArgumentNullException("Input dates", "Input dates are null or have Minimum values.");
            }
            DateTimeSpan dateSpan = DateTimeSpan.CompareDates(DT1, DT2);

            dict["Years"]        = dateSpan.Years;
            dict["Months"]       = dateSpan.Months;
            dict["Days"]         = dateSpan.Days;
            dict["Hours"]        = dateSpan.Hours;
            dict["Minutes"]      = dateSpan.Minutes;
            dict["Seconds"]      = dateSpan.Seconds;
            dict["Milliseconds"] = dateSpan.Milliseconds;

            Difference.Set(context, dict);
        }
        protected override void Execute(CodeActivityContext context)
        {
            Boolean  result = true;
            DateTime DT1    = Date1DT.Get(context);
            DateTime DT2    = Date2DT.Get(context);


            if (DT1 == DateTime.MinValue && DT2 == DateTime.MinValue)
            {
                throw new ArgumentNullException("Input dates", "Input dates are null or have Minimum values.");
            }

            TimeSpan dt = DT2 - DT1;

            if (CheckDay)
            {
                result &= DT1.Day == DT2.Day;
            }
            if (CheckMonth)
            {
                result &= DT1.Month == DT2.Month;
            }
            if (CheckYear)
            {
                result &= DT1.Year == DT2.Year;
            }
            if (CheckHours)
            {
                result &= ((dt.TotalHours < 1) || ((dt.TotalHours > 1) && (dt.TotalHours % 24 == 0)));
            }
            if (CheckMinutes)
            {
                result &= ((dt.TotalMinutes < 1) || ((dt.TotalMinutes > 1) && (dt.TotalMinutes % 60 == 0)));
            }
            if (CheckSecondes)
            {
                result &= ((dt.TotalMilliseconds % 60000) == 0);
            }

            Result.Set(context, result);
            switch (OutputDateDifferenceUnits)
            {
            case TimeBins.Milliseconds:
                DateDifference.Set(context, dt.TotalMilliseconds);
                break;

            case TimeBins.Seconds:
                DateDifference.Set(context, dt.TotalSeconds);
                break;

            case TimeBins.Minutes:
                DateDifference.Set(context, dt.TotalMinutes);
                break;

            case TimeBins.Hours:
                DateDifference.Set(context, dt.TotalHours);
                break;

            case TimeBins.Days:
                DateDifference.Set(context, dt.TotalDays);
                break;

            default:
                DateDifference.Set(context, dt.TotalMilliseconds);
                break;
            }
        }