public IDateProjection Monthly(int periodCount, EWeeksInMonth weeksInMonth, EDaysOfWeekExt daysOfWeek)
 {
     return(new MonthlyRelativeProjection()
     {
         MonthCount = periodCount, WeeksInMonth = weeksInMonth, DaysOfWeekExt = daysOfWeek
     });
 }
 public IDateProjection Yearly(EMonth month, EWeeksInMonth weeksInMonth, EDaysOfWeekExt daysOfWeek)
 {
     return(new YearlyRelativeProjection()
     {
         Month = month, WeeksInMonth = weeksInMonth, DaysOfWeekExt = daysOfWeek
     });
 }
        public void GetPrevious()
        {
            EMonth         month          = EMonth.March;
            EWeeksInMonth  weeksInMonth   = EWeeksInMonth.Second;
            EDaysOfWeekExt daysOfWeek     = EDaysOfWeekExt.Monday;
            DateProjection dateProjection = DateProjection(month, weeksInMonth, daysOfWeek);

            Assert.That(dateProjection.GetPrevious(new DateTime(2017, 2, 28)), Is.EqualTo(new DateTime(2016, 3, 14)));
        }
        public void GetPreviousMonthCountLessThan1Exception()
        {
            int            monthCount     = 0;
            EWeeksInMonth  weeksInMonth   = EWeeksInMonth.Second;
            EDaysOfWeekExt daysOfWeek     = EDaysOfWeekExt.Monday;
            DateProjection dateProjection = DateProjection(monthCount, weeksInMonth, daysOfWeek);

            Assert.That(() => dateProjection.GetPrevious(new DateTime(2017, 2, 28)), Throws.TypeOf <InvalidOperationException>());
        }
        public void GetPrevious()
        {
            int            monthCount     = 3;
            EWeeksInMonth  weeksInMonth   = EWeeksInMonth.Second;
            EDaysOfWeekExt daysOfWeek     = EDaysOfWeekExt.Monday;
            DateProjection dateProjection = DateProjection(monthCount, weeksInMonth, daysOfWeek);

            Assert.That(dateProjection.GetPrevious(new DateTime(2017, 2, 28)), Is.EqualTo(new DateTime(2016, 12, 12)));
        }
        private static DateProjection DateProjection(EMonth month, EWeeksInMonth weeksInMonth, EDaysOfWeekExt daysOfWeek)
        {
            var projection = new YearlyRelativeProjection()
            {
                Month         = month,
                WeeksInMonth  = weeksInMonth,
                DaysOfWeekExt = daysOfWeek,
            };
            var dateProjection = new DateProjection(projection);

            return(dateProjection);
        }
        private static DateProjection DateProjection(int monthCount, EWeeksInMonth weeksInMonth, EDaysOfWeekExt daysOfWeek)
        {
            var projection = new MonthlyRelativeProjection()
            {
                MonthCount    = monthCount,
                WeeksInMonth  = weeksInMonth,
                DaysOfWeekExt = daysOfWeek,
            };
            var dateProjection = new DateProjection(projection);

            return(dateProjection);
        }
예제 #8
0
        public static DateTime GetDate(int year, EMonth month, EWeeksInMonth weekInMonth, EDaysOfWeekExt dayOfWeekExt)
        {
            int  monthNumber = Month.GetMonthNumber(month);
            bool lookForward = true;

            DateTime date;

            switch (weekInMonth)
            {
            case EWeeksInMonth.First:
                date = new DateTime(year, monthNumber, 1);
                break;

            case EWeeksInMonth.Second:
                date = new DateTime(year, monthNumber, 8);
                break;

            case EWeeksInMonth.Third:
                date = new DateTime(year, monthNumber, 15);
                break;

            case EWeeksInMonth.Fourth:
                date = new DateTime(year, monthNumber, 22);
                break;

            case EWeeksInMonth.Last:
                date        = new DateTime(year, monthNumber, DateTime.DaysInMonth(year, monthNumber));
                lookForward = false;
                break;

            default:
                throw new ArgumentException($"Unrecognized Week in Month ({weekInMonth})!");
            }

            if (lookForward)
            {
                while (!date.DateMatches(dayOfWeekExt))
                {
                    date = date.AddDays(1);
                }
            }
            else
            {
                while (!date.DateMatches(dayOfWeekExt))
                {
                    date = date.AddDays(-1);
                }
            }

            return(date);
        }
        public void TranslateProjectionType()
        {
            const int              periodCount    = 1;
            const EMonth           month          = EMonth.February;
            const int              dayOfMonth     = 3;
            const EDaysOfWeekExt   dayOfWeekExt   = EDaysOfWeekExt.Thursday;
            const EDaysOfWeekFlags dayOfWeekFlags = EDaysOfWeekFlags.Friday;
            const EWeeksInMonth    weekInMonth    = EWeeksInMonth.Last;

            DateProjection prj = new DateProjection(EDateProjectionType.Daily)
            {
                PeriodCount     = periodCount,
                Month           = month,
                DayOfMonth      = dayOfMonth,
                DaysOfWeekExt   = dayOfWeekExt,
                DaysOfWeekFlags = dayOfWeekFlags,
                WeeksInMonth    = weekInMonth,
            };

            prj.ProjectionType = EDateProjectionType.Weekly;
            Assert.That(DateProjection.ToShortDescription(prj), Is.EqualTo("Weekly"));
            prj.ProjectionType = EDateProjectionType.Monthly;
            Assert.That(DateProjection.ToShortDescription(prj), Is.EqualTo("Monthly"));
            prj.ProjectionType = EDateProjectionType.MonthlyRelative;
            Assert.That(DateProjection.ToShortDescription(prj), Is.EqualTo("Monthly Relative"));
            prj.ProjectionType = EDateProjectionType.Yearly;
            Assert.That(DateProjection.ToShortDescription(prj), Is.EqualTo("Yearly"));
            prj.ProjectionType = EDateProjectionType.YearlyRelative;
            Assert.That(DateProjection.ToShortDescription(prj), Is.EqualTo("Yearly Relative"));
            prj.ProjectionType = EDateProjectionType.Daily;
            Assert.That(DateProjection.ToShortDescription(prj), Is.EqualTo("Daily"));

            Assert.That(prj.PeriodCount, Is.EqualTo(periodCount));
            Assert.That(prj.Month, Is.EqualTo(month));
            Assert.That(prj.DayOfMonth, Is.EqualTo(dayOfMonth));
            Assert.That(prj.DaysOfWeekExt, Is.EqualTo(dayOfWeekExt));
            Assert.That(prj.DaysOfWeekFlags, Is.EqualTo(dayOfWeekFlags));
            Assert.That(prj.WeeksInMonth, Is.EqualTo(weekInMonth));

            Assert.That(DateProjection.ToShortDescription(null), Is.EqualTo("None"));
        }
예제 #10
0
 public static DateTime GetDate(int year, int month, EWeeksInMonth weekInMonth, EDaysOfWeek dayOfWeek)
 {
     return(GetDate(year, Month.GetMonth(month), weekInMonth, DaysOfWeekExt.ConvertFrom(dayOfWeek)));
 }
예제 #11
0
 public static DateTime GetDate(int year, int month, EWeeksInMonth weekInMonth, EDaysOfWeekExt dayOfWeekExt)
 {
     return(GetDate(year, Month.GetMonth(month), weekInMonth, dayOfWeekExt));
 }
 public TReturn YearlyLeadTime(EMonth month, EWeeksInMonth weeksInMonth, EDaysOfWeekExt daysOfWeek)
 {
     this.Activity.LeadTime = new DateProjection(new DateProjectionCreateHelper().Yearly(month, weeksInMonth, daysOfWeek));
     return((TReturn)this);
 }
 public TReturn MonthlyLeadTime(int periodCount, EWeeksInMonth weeksInMonth, EDaysOfWeekExt daysOfWeek)
 {
     this.Activity.LeadTime = new DateProjection(new DateProjectionCreateHelper().Monthly(periodCount, weeksInMonth, daysOfWeek));
     return((TReturn)this);
 }