Ejemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            String DateS1 = Date1String.Get(context);
            String DateS2 = Date2String.Get(context);
            Dictionary <String, Int32> dict = new Dictionary <string, int>();
            String format = Format.Get(context);

            if (String.IsNullOrEmpty(format))
            {
                format = "dd/MM/yyyy";
            }
            DateTime DT1 = DateTime.ParseExact(DateS1, format, null);
            DateTime DT2 = DateTime.ParseExact(DateS2, format, null);

            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);
        }
Ejemplo n.º 2
0
        protected override void Execute(CodeActivityContext context)
        {
            Boolean result = true;

            String DateS1 = Date1String.Get(context);
            String DateS2 = Date2String.Get(context);
            String format = Format.Get(context);

            if (String.IsNullOrEmpty(format))
            {
                format = "dd/MM/yyyy";
            }

            DateTime DT1 = DateTime.ParseExact(DateS1, format, null);
            DateTime DT2 = DateTime.ParseExact(DateS2, format, null);

            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;

            case TimeBins.Months:
                DateDifference.Set(context, dt.TotalDays / 30.4375);
                break;

            case TimeBins.Years:
                DateDifference.Set(context, dt.TotalDays / 365.25);
                break;

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