Exemplo n.º 1
0
        public void CalendarTest() {
            var timeCalendar = new TimeCalendar();
            var timeRange = new CalendarTimeRange(TimeRange.Anytime, timeCalendar);

            timeRange.TimeCalendar.Should().Be(timeCalendar);
            timeRange.IsAnytime.Should().Be.True();
        }
Exemplo n.º 2
0
        public void DayOfWeekTest() {
            var now = ClockProxy.Clock.Now;
            var timeCalendar = new TimeCalendar();

            var day = new DayRange(now, timeCalendar);
            day.DayOfWeek.Should().Be(timeCalendar.Culture.Calendar.GetDayOfWeek(now));
        }
Exemplo n.º 3
0
 public void EnAuCultureTest() {
     var cultureInfo = new CultureInfo("en-AU");
     //	cultureInfo.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
     var timeCalendar = new TimeCalendar(new TimeCalendarConfig { Culture = cultureInfo });
     var week = new WeekRange(new DateTime(2011, 4, 1, 9, 0, 0), timeCalendar);
     week.Start.Should().Be(new DateTime(2011, 3, 28));
 }
Exemplo n.º 4
0
        public void EndOffsetTest() {
            Assert.AreEqual(TimeCalendar.DefaultEndOffset, new TimeCalendar().EndOffset);

            var offset = DurationUtil.Second.Negate();
            var timeCalendar = new TimeCalendar(new TimeCalendarConfig
                                                {
                                                    StartOffset = TimeSpan.Zero,
                                                    EndOffset = offset
                                                });
            Assert.AreEqual(offset, timeCalendar.EndOffset);
        }
Exemplo n.º 5
0
        public void WeekByCultures() {
            var now = ClockProxy.Clock.Now;

            CultureTestData.Default
                .RunEach(culture => {
                             if(IsDebugEnabled)
                                 log.Debug("culture = " + culture);

                             var timeCalendar = new TimeCalendar(new TimeCalendarConfig() { Culture = culture });
                             var week = new WeekRange(now, timeCalendar);

                             week.StartDayStart.Should().Be(now.StartTimeOfWeek(culture).Date);
                             week.EndDayStart.Should().Be(now.EndTimeOfWeek(culture).Date);
                         });
        }
Exemplo n.º 6
0
        public void CalendarQuarterOfYearTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            TimeCalendar timeCalendar = TimeCalendar.New(YearMonth.October);
            Year         calendarYear = new Year(currentYear, timeCalendar);

            Assert.Equal(YearMonth.October, calendarYear.YearBaseMonth);
            Assert.Equal(calendarYear.BaseYear, currentYear);
            Assert.Equal(calendarYear.Start, new DateTime(currentYear, 10, 1));
            Assert.Equal(calendarYear.End, calendarYear.Calendar.MapEnd(calendarYear.Start.AddYears(1)));

            // Q1
            Quarter q1 = new Quarter(calendarYear.BaseYear, YearQuarter.First, timeCalendar);

            Assert.Equal(q1.YearBaseMonth, calendarYear.YearBaseMonth);
            Assert.Equal(q1.BaseYear, calendarYear.BaseYear);
            Assert.Equal(q1.Start, new DateTime(currentYear, 10, 1));
            Assert.Equal(q1.End, q1.Calendar.MapEnd(q1.Start.AddMonths(3)));

            // Q2
            Quarter q2 = new Quarter(calendarYear.BaseYear, YearQuarter.Second, timeCalendar);

            Assert.Equal(q2.YearBaseMonth, calendarYear.YearBaseMonth);
            Assert.Equal(q2.BaseYear, calendarYear.BaseYear);
            Assert.Equal(q2.Start, new DateTime(currentYear + 1, 1, 1));
            Assert.Equal(q2.End, q2.Calendar.MapEnd(q2.Start.AddMonths(3)));

            // Q3
            Quarter q3 = new Quarter(calendarYear.BaseYear, YearQuarter.Third, timeCalendar);

            Assert.Equal(q3.YearBaseMonth, calendarYear.YearBaseMonth);
            Assert.Equal(q3.BaseYear, calendarYear.BaseYear);
            Assert.Equal(q3.Start, new DateTime(currentYear + 1, 4, 1));
            Assert.Equal(q3.End, q3.Calendar.MapEnd(q3.Start.AddMonths(3)));

            // Q4
            Quarter q4 = new Quarter(calendarYear.BaseYear, YearQuarter.Fourth, timeCalendar);

            Assert.Equal(q4.YearBaseMonth, calendarYear.YearBaseMonth);
            Assert.Equal(q4.BaseYear, calendarYear.BaseYear);
            Assert.Equal(q4.Start, new DateTime(currentYear + 1, 7, 1));
            Assert.Equal(q4.End, q4.Calendar.MapEnd(q4.Start.AddMonths(3)));
        } // CalendarQuarterOfYearTest
Exemplo n.º 7
0
        public void FiscalYearStartMonthTest()
        {
            int year = ClockProxy.Clock.Now.Year;

            for (YearMonth month = YearMonth.January; month <= YearMonth.December; month++)
            {
                int          expectedYear    = month < YearMonth.July ? year : year + 1;
                DateTime     fiscalYearStart = new DateTime(year, (int)month, 1);
                TimeCalendar calendar        = new TimeCalendar(
                    new TimeCalendarConfig
                {
                    YearBaseMonth = month,
                    YearType      = YearType.FiscalYear
                });
                Assert.AreEqual(expectedYear, new Year(fiscalYearStart, calendar).YearValue);
                Assert.AreEqual(expectedYear, new Year(fiscalYearStart.AddTicks(1), calendar).YearValue);
                Assert.AreEqual(expectedYear - 1, new Year(fiscalYearStart.AddTicks(-1), calendar).YearValue);
            }
        }         // FiscalYearStartMonthTest
Exemplo n.º 8
0
        // ----------------------------------------------------------------------
        // see also http://blogs.msdn.com/b/shawnste/archive/2006/01/24/517178.aspx
        public void CalendarWeekSample()
        {
            DateTime testDate = new DateTime(2007, 12, 31);

            // .NET calendar week
            TimeCalendar calendar = new TimeCalendar();

            Console.WriteLine("Calendar Week of {0}: {1}", testDate.ToString("d"), new Week(testDate, calendar).WeekOfYear);
            // > Calendar Week of 31.12.2007: 53

            // ISO 8601 calendar week
            TimeCalendar calendarIso8601 = new TimeCalendar(
                new TimeCalendarConfig {
                YearWeekType = YearWeekType.Iso8601
            });

            Console.WriteLine("ISO 8601 Week of {0}: {1}", testDate.ToString("d"), new Week(testDate, calendarIso8601).WeekOfYear);
            // > ISO 8601 Week of 31.12.2007: 1
        }         // CalendarWeekSample
Exemplo n.º 9
0
        public void FiscalYearNearestDay()
        {
            ITimeCalendar calendar = new TimeCalendar(new TimeCalendarConfig
            {
                YearType              = YearType.FiscalYear,
                YearBaseMonth         = YearMonth.September,
                FiscalFirstDayOfYear  = DayOfWeek.Sunday,
                FiscalYearAlignment   = FiscalYearAlignment.NearestDay,
                FiscalQuarterGrouping = FiscalQuarterGrouping.FourFourFiveWeeks
            });

            Years years = new Years(2005, 14, calendar);

            foreach (Year year in years.GetYears())
            {
                Console.WriteLine("Fiscal year {0}: {1} - {2}", year.YearValue,
                                  year.Start.ToString("yyyy-MM-dd"), year.End.ToString("yyyy-MM-dd"));
            }
        }         // FiscalYearNearestDay
Exemplo n.º 10
0
        public void GetQuartersTest()
        {
            Year year = new Year(TimeCalendar.New(YearMonth.October));

            ITimePeriodCollection quarters = year.GetQuarters();

            Assert.AreNotEqual(quarters, null);

            int index = 0;

            foreach (Quarter quarter in quarters)
            {
                Assert.AreEqual(quarter.BaseYear, year.BaseYear);
                Assert.AreEqual(quarter.Start, year.Start.AddMonths(index * TimeSpec.MonthsPerQuarter));
                Assert.AreEqual(quarter.End, quarter.Calendar.MapEnd(quarter.Start.AddMonths(TimeSpec.MonthsPerQuarter)));
                index++;
            }
            Assert.AreEqual(index, TimeSpec.QuartersPerYear);
        }         // GetQuartersTest
Exemplo n.º 11
0
        public void DefaultQuarterTest()
        {
            const int yearStartMonth = April;
            var       currentYear    = ClockProxy.Clock.Now.Year;

            var timeCalendar = TimeCalendar.New(TimeSpan.Zero, TimeSpan.Zero, yearStartMonth);

            var q1 = new QuarterRange(currentYear, QuarterKind.First, timeCalendar);

            q1.IsReadOnly.Should().Be.True();
            q1.YearBaseMonth.Should().Be(yearStartMonth);
            q1.Quarter.Should().Be(QuarterKind.First);
            q1.BaseYear.Should().Be(currentYear);
            q1.Start.Should().Be(new DateTime(currentYear, 4, 1));
            q1.End.Should().Be(new DateTime(currentYear, 7, 1));

            var q2 = new QuarterRange(currentYear, QuarterKind.Second, timeCalendar);

            q2.IsReadOnly.Should().Be.True();
            q2.YearBaseMonth.Should().Be(yearStartMonth);
            q2.Quarter.Should().Be(QuarterKind.Second);
            q2.BaseYear.Should().Be(currentYear);
            q2.Start.Should().Be(new DateTime(currentYear, 7, 1));
            q2.End.Should().Be(new DateTime(currentYear, 10, 1));

            var q3 = new QuarterRange(currentYear, QuarterKind.Third, timeCalendar);

            q3.IsReadOnly.Should().Be.True();
            q3.YearBaseMonth.Should().Be(yearStartMonth);
            q3.Quarter.Should().Be(QuarterKind.Third);
            q3.BaseYear.Should().Be(currentYear);
            q3.Start.Should().Be(new DateTime(currentYear, 10, 1));
            q3.End.Should().Be(new DateTime(currentYear + 1, 1, 1));

            var q4 = new QuarterRange(currentYear, QuarterKind.Fourth, timeCalendar);

            q4.IsReadOnly.Should().Be.True();
            q4.YearBaseMonth.Should().Be(yearStartMonth);
            q4.Quarter.Should().Be(QuarterKind.Fourth);
            q4.BaseYear.Should().Be(currentYear);
            q4.Start.Should().Be(new DateTime(currentYear + 1, 1, 1));
            q4.End.Should().Be(new DateTime(currentYear + 1, 4, 1));
        }
Exemplo n.º 12
0
        public void GetHalfyearsTest()
        {
            Year year = new Year(TimeCalendar.New(YearMonth.October));

            ITimePeriodCollection halfyears = year.GetHalfyears();

            Assert.NotNull(halfyears);

            int index = 0;

            foreach (Halfyear halfyear in halfyears)
            {
                Assert.Equal(halfyear.BaseYear, year.BaseYear);
                Assert.Equal(halfyear.Start, year.Start.AddMonths(index * TimeSpec.MonthsPerHalfyear));
                Assert.Equal(halfyear.End, halfyear.Calendar.MapEnd(halfyear.Start.AddMonths(TimeSpec.MonthsPerHalfyear)));
                index++;
            }
            Assert.Equal(index, TimeSpec.HalfyearsPerYear);
        }         // GetHalfyearsTest
Exemplo n.º 13
0
        public void FirstCustomCalendarHalfyearsTest()
        {
            TimeCalendar       calendar      = TimeCalendar.New(YearMonth.October);
            const int          startYear     = 2004;
            const YearHalfyear startHalfyear = YearHalfyear.First;
            const int          halfyearCount = 3;
            Halfyears          halfyears     = new Halfyears(startYear, startHalfyear, halfyearCount, calendar);

            Assert.Equal(YearMonth.October, halfyears.YearBaseMonth);
            Assert.Equal <int>(halfyears.HalfyearCount, halfyearCount);
            Assert.Equal(halfyears.StartHalfyear, startHalfyear);
            Assert.Equal <int>(halfyears.StartYear, startYear);
            Assert.Equal(2005, halfyears.EndYear);
            Assert.Equal(YearHalfyear.First, halfyears.EndHalfyear);
            Assert.Equal(halfyears.GetHalfyears().Count, halfyearCount);
            Assert.True(halfyears.GetHalfyears()[0].IsSamePeriod(new Halfyear(2004, YearHalfyear.First, calendar)));
            Assert.True(halfyears.GetHalfyears()[1].IsSamePeriod(new Halfyear(2004, YearHalfyear.Second, calendar)));
            Assert.True(halfyears.GetHalfyears()[2].IsSamePeriod(new Halfyear(2005, YearHalfyear.First, calendar)));
        }         // FirstCustomCalendarHalfyearsTest
Exemplo n.º 14
0
        public void CustomCalendarYearsTest()
        {
            const int startYear  = 2004;
            const int yearCount  = 3;
            const int startMonth = 4;
            Years     years      = new Years(startYear, yearCount, TimeCalendar.New((YearMonth)startMonth));

            Assert.Equal(years.YearCount, yearCount);
            Assert.Equal(years.StartYear, startYear);
            Assert.Equal(years.EndYear, startYear + yearCount);

            int index = 0;

            foreach (Year year in years.GetYears())
            {
                Assert.Equal(year.Start, new DateTime(startYear + index, startMonth, 1));
                index++;
            }
        }         // CustomCalendarYearsTest
        public void CalendarDateAdd1Test()
        {
            TimeCalendar timeCalendar = new TimeCalendar(new TimeCalendarConfig
            {
                Culture   = new CultureInfo("en-AU"),
                EndOffset = TimeSpan.Zero
            });

            CalendarDateAdd calendarDateAdd = new CalendarDateAdd(timeCalendar);

            calendarDateAdd.AddWorkingWeekDays();
            calendarDateAdd.ExcludePeriods.Add(new Day(2011, 4, 4, calendarDateAdd.Calendar));
            calendarDateAdd.WorkingHours.Add(new HourRange(8, 18));

            DateTime start = new DateTime(2011, 4, 1, 9, 0, 0);

            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(22, 0, 0)), new DateTime(2011, 4, 6, 11, 0, 0));
            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(29, 0, 0)), new DateTime(2011, 4, 7, 8, 0, 0));
        }         // CalendarDateAdd1Test
Exemplo n.º 16
0
        public void DefaultQuarterTest()
        {
            int             currentYear    = ClockProxy.Clock.Now.Year;
            const YearMonth yearStartMonth = YearMonth.April;
            TimeCalendar    calendar       = TimeCalendar.New(TimeSpan.Zero, TimeSpan.Zero, yearStartMonth);

            Quarter q1 = new Quarter(currentYear, YearQuarter.First, calendar);

            Assert.True(q1.IsReadOnly);
            Assert.Equal(q1.YearBaseMonth, yearStartMonth);
            Assert.Equal(YearQuarter.First, q1.YearQuarter);
            Assert.Equal(q1.BaseYear, currentYear);
            Assert.Equal(q1.Start, new DateTime(currentYear, 4, 1));
            Assert.Equal(q1.End, new DateTime(currentYear, 7, 1));

            Quarter q2 = new Quarter(currentYear, YearQuarter.Second, calendar);

            Assert.True(q2.IsReadOnly);
            Assert.Equal(q2.YearBaseMonth, yearStartMonth);
            Assert.Equal(YearQuarter.Second, q2.YearQuarter);
            Assert.Equal(q2.BaseYear, currentYear);
            Assert.Equal(q2.Start, new DateTime(currentYear, 7, 1));
            Assert.Equal(q2.End, new DateTime(currentYear, 10, 1));

            Quarter q3 = new Quarter(currentYear, YearQuarter.Third, calendar);

            Assert.True(q3.IsReadOnly);
            Assert.Equal(q3.YearBaseMonth, yearStartMonth);
            Assert.Equal(YearQuarter.Third, q3.YearQuarter);
            Assert.Equal(q3.BaseYear, currentYear);
            Assert.Equal(q3.Start, new DateTime(currentYear, 10, 1));
            Assert.Equal(q3.End, new DateTime(currentYear + 1, 1, 1));

            Quarter q4 = new Quarter(currentYear, YearQuarter.Fourth, calendar);

            Assert.True(q4.IsReadOnly);
            Assert.Equal(q4.YearBaseMonth, yearStartMonth);
            Assert.Equal(YearQuarter.Fourth, q4.YearQuarter);
            Assert.Equal(q4.BaseYear, currentYear);
            Assert.Equal(q4.Start, new DateTime(currentYear + 1, 1, 1));
            Assert.Equal(q4.End, new DateTime(currentYear + 1, 4, 1));
        }         // DefaultQuarterTest
Exemplo n.º 17
0
        public void IsCalendarQuarterTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            foreach (QuarterKind yearQuarter in Enum.GetValues(typeof(QuarterKind)))
            {
                Assert.IsTrue(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(1)).IsCalendarQuarter);
                Assert.IsFalse(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(2)).IsCalendarQuarter);
                Assert.IsFalse(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(3)).IsCalendarQuarter);
                Assert.IsTrue(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(4)).IsCalendarQuarter);
                Assert.IsFalse(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(5)).IsCalendarQuarter);
                Assert.IsFalse(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(6)).IsCalendarQuarter);
                Assert.IsTrue(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(7)).IsCalendarQuarter);
                Assert.IsFalse(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(8)).IsCalendarQuarter);
                Assert.IsFalse(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(9)).IsCalendarQuarter);
                Assert.IsTrue(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(10)).IsCalendarQuarter);
                Assert.IsFalse(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(11)).IsCalendarQuarter);
                Assert.IsFalse(new QuarterRange(currentYear, yearQuarter, TimeCalendar.New(12)).IsCalendarQuarter);
            }
        }
Exemplo n.º 18
0
        public void IsCalendarQuarterTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            foreach (YearQuarter yearQuarter in Enum.GetValues(typeof(YearQuarter)))
            {
                Assert.True(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.January)).IsCalendarQuarter);
                Assert.False(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.February)).IsCalendarQuarter);
                Assert.False(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.March)).IsCalendarQuarter);
                Assert.True(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.April)).IsCalendarQuarter);
                Assert.False(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.May)).IsCalendarQuarter);
                Assert.False(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.June)).IsCalendarQuarter);
                Assert.True(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.July)).IsCalendarQuarter);
                Assert.False(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.August)).IsCalendarQuarter);
                Assert.False(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.September)).IsCalendarQuarter);
                Assert.True(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.October)).IsCalendarQuarter);
                Assert.False(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.November)).IsCalendarQuarter);
                Assert.False(new Quarter(currentYear, yearQuarter, TimeCalendar.New(YearMonth.December)).IsCalendarQuarter);
            }
        }         // IsCalendarQuarterTest
Exemplo n.º 19
0
        public void IsCalendarHalfyearTest()
        {
            DateTime now = ClockProxy.Clock.Now;

            foreach (HalfyearKind yearHalfyear in Enum.GetValues(typeof(HalfyearKind)))
            {
                Assert.IsTrue(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(1)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(2)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(3)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(4)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(5)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(6)).IsCalendarHalfyear);
                Assert.IsTrue(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(7)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(8)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(9)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(10)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(11)).IsCalendarHalfyear);
                Assert.IsFalse(new HalfyearRange(now.Year, yearHalfyear, TimeCalendar.New(12)).IsCalendarHalfyear);
            }
        }
        public void CustomCalendarYearsTest()
        {
            const int startYear  = 2004;
            const int yearCount  = 3;
            const int startMonth = 4;

            var years = new YearRangeCollection(startYear, yearCount, TimeCalendar.New(startMonth));

            years.YearCount.Should().Be(yearCount);
            years.StartYear.Should().Be(startYear);
            years.EndYear.Should().Be(startYear + yearCount);

            var index = 0;

            foreach (var year in years.GetYears())
            {
                year.Start.Should().Be(new DateTime(startYear + index, startMonth, 1));
                index++;
            }
        }
Exemplo n.º 21
0
        public void AddDaysTest()
        {
            DateTime now    = ClockProxy.Clock.Now;
            DateTime nowDay = new DateTime(now.Year, now.Month, now.Day);
            Day      day    = new Day(now, TimeCalendar.NewEmptyOffset());

            Assert.Equal(day.AddDays(0), day);

            DateTime previousDay = nowDay.AddDays(-1);

            Assert.Equal(day.AddDays(-1).Year, previousDay.Year);
            Assert.Equal(day.AddDays(-1).Month, previousDay.Month);
            Assert.Equal(day.AddDays(-1).DayValue, previousDay.Day);

            DateTime nextDay = nowDay.AddDays(1);

            Assert.Equal(day.AddDays(1).Year, nextDay.Year);
            Assert.Equal(day.AddDays(1).Month, nextDay.Month);
            Assert.Equal(day.AddDays(1).DayValue, nextDay.Day);
        }         // AddDaysTest
Exemplo n.º 22
0
        public void CurrentMonthTest()
        {
            DateTime now = ClockProxy.Clock.Now;

            CultureTestData cultures = new CultureTestData();

            foreach (CultureInfo culture in cultures)
            {
                DateTime currentYearMonthStart = new DateTime(now.Year, now.Month, 1);
                DateTime currentYearMonthEnd   =
                    currentYearMonthStart.AddDays(culture.Calendar.GetDaysInMonth(currentYearMonthStart.Year,
                                                                                  currentYearMonthStart.Month));
                Month month = new Month(currentYearMonthStart, TimeCalendar.New(culture, TimeSpan.Zero, TimeSpan.Zero));

                Assert.Equal(month.Year, now.Year);
                Assert.Equal(month.YearMonth, (YearMonth)now.Month);
                Assert.Equal(month.Start, currentYearMonthStart);
                Assert.Equal(month.End, currentYearMonthEnd);
            }
        }         // CurrentMonthTest
Exemplo n.º 23
0
        public void GetMonthsTest()
        {
            int          currentYear  = ClockProxy.Clock.Now.Year;
            TimeCalendar timeCalendar = TimeCalendar.New(YearMonth.October);
            Halfyear     halfyear     = new Halfyear(currentYear, YearHalfyear.First, timeCalendar);

            ITimePeriodCollection months = halfyear.GetMonths();

            Assert.NotNull(months);

            int index = 0;

            foreach (Month month in months)
            {
                Assert.Equal(month.Start, halfyear.Start.AddMonths(index));
                Assert.Equal(month.End, month.Calendar.MapEnd(month.Start.AddMonths(1)));
                index++;
            }
            Assert.Equal(index, TimeSpec.MonthsPerHalfyear);
        }         // GetMonthsTest
Exemplo n.º 24
0
        public void IsCalendarHalfyearTest()
        {
            DateTime now = ClockProxy.Clock.Now;

            foreach (YearHalfyear yearHalfyear in Enum.GetValues(typeof(YearHalfyear)))
            {
                Assert.True(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.January)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.February)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.March)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.April)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.May)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.June)).IsCalendarHalfyear);
                Assert.True(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.July)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.August)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.September)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.October)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.November)).IsCalendarHalfyear);
                Assert.False(new Halfyear(now.Year, yearHalfyear, TimeCalendar.New(YearMonth.December)).IsCalendarHalfyear);
            }
        }         // IsCalendarHalfyearTest
Exemplo n.º 25
0
        public void GetQuartersTest()
        {
            var currentYear  = ClockProxy.Clock.Now.Year;
            var timeCalendar = TimeCalendar.New(10);
            var h1           = new HalfyearRange(currentYear, HalfyearKind.First, timeCalendar);

            var h1Quarters = h1.GetQuarters();

            Assert.IsNotNull(h1Quarters);
            h1Quarters.Count().Should().Be(TimeSpec.QuartersPerHalfyear);

            var h1Index = 0;

            foreach (var h1Quarter in h1Quarters)
            {
                h1Quarter.BaseYear.Should().Be(h1.BaseYear);
                h1Quarter.Quarter.Should().Be(h1Index == 0 ? QuarterKind.First : QuarterKind.Second);
                h1Quarter.Start.Should().Be(h1.Start.AddMonths(h1Index * TimeSpec.MonthsPerQuarter));
                h1Quarter.End.Should().Be(h1Quarter.TimeCalendar.MapEnd(h1Quarter.Start.AddMonths(TimeSpec.MonthsPerQuarter)));

                h1Index++;
            }

            var h2 = new HalfyearRange(currentYear, HalfyearKind.Second, timeCalendar);

            var h2Quarters = h2.GetQuarters();

            Assert.IsNotNull(h2Quarters);
            h2Quarters.Count().Should().Be(TimeSpec.QuartersPerHalfyear);

            var h2Index = 0;

            foreach (var h2Quarter in h2Quarters)
            {
                h2Quarter.BaseYear.Should().Be(h2.BaseYear);
                h2Quarter.Quarter.Should().Be(h2Index == 0 ? QuarterKind.Third : QuarterKind.Fourth);
                h2Quarter.Start.Should().Be(h2.Start.AddMonths(h2Index * TimeSpec.MonthsPerQuarter));
                h2Quarter.End.Should().Be(h2Quarter.TimeCalendar.MapEnd(h2Quarter.Start.AddMonths(TimeSpec.MonthsPerQuarter)));
                h2Index++;
            }
        }
Exemplo n.º 26
0
        public void AddMonthsTest()
        {
            DateTime now = ClockProxy.Clock.Now;

            CultureTestData cultures = new CultureTestData();

            foreach (CultureInfo culture in cultures)
            {
                DateTime currentYearMonthStart = new DateTime(now.Year, now.Month, 1);
                DateTime currentYearMonthEnd   =
                    currentYearMonthStart.AddDays(culture.Calendar.GetDaysInMonth(currentYearMonthStart.Year,
                                                                                  currentYearMonthStart.Month));
                Month currentYearMonth = new Month(currentYearMonthStart,
                                                   TimeCalendar.New(culture, TimeSpan.Zero, TimeSpan.Zero));
                Assert.Equal(currentYearMonth.Start, currentYearMonthStart);
                Assert.Equal(currentYearMonth.End, currentYearMonthEnd);

                Assert.Equal(currentYearMonth.AddMonths(0), currentYearMonth);

                DateTime previousYearMonthStart = new DateTime(now.Year - 1, now.Month, 1);
                DateTime previousYearMonthEnd   =
                    previousYearMonthStart.AddDays(culture.Calendar.GetDaysInMonth(previousYearMonthStart.Year,
                                                                                   previousYearMonthStart.Month));
                Month previousYearMonth = currentYearMonth.AddMonths(TimeSpec.MonthsPerYear * -1);
                Assert.Equal(previousYearMonth.Start, previousYearMonthStart);
                Assert.Equal(previousYearMonth.End, previousYearMonthEnd);
                Assert.Equal(previousYearMonth.YearMonth, currentYearMonth.YearMonth);
                Assert.Equal(previousYearMonth.Start.Year, currentYearMonth.Start.Year - 1);
                Assert.Equal(previousYearMonth.End.Year, currentYearMonth.End.Year - 1);

                DateTime nextYearMonthStart = new DateTime(now.Year + 1, now.Month, 1);
                DateTime nextYearMonthEnd   =
                    nextYearMonthStart.AddDays(culture.Calendar.GetDaysInMonth(nextYearMonthStart.Year, nextYearMonthStart.Month));
                Month nextYearMonth = currentYearMonth.AddMonths(TimeSpec.MonthsPerYear);
                Assert.Equal(nextYearMonth.Start, nextYearMonthStart);
                Assert.Equal(nextYearMonth.End, nextYearMonthEnd);
                Assert.Equal(nextYearMonth.YearMonth, currentYearMonth.YearMonth);
                Assert.Equal(nextYearMonth.Start.Year, currentYearMonth.Start.Year + 1);
                Assert.Equal(nextYearMonth.End.Year, currentYearMonth.End.Year + 1);
            }
        } // AddMonthsTest
Exemplo n.º 27
0
        public void GetMonthsTest()
        {
            var currentYear  = ClockProxy.Clock.Now.Year;
            var timeCalendar = TimeCalendar.New(10);
            var halfyear     = new HalfyearRange(currentYear, HalfyearKind.First, timeCalendar);

            var months = halfyear.GetMonths();

            Assert.IsNotNull(months);
            months.Count().Should().Be(TimeSpec.MonthsPerHalfyear);

            int index = 0;

            foreach (var month in months)
            {
                Assert.AreEqual(month.Start, halfyear.Start.AddMonths(index));
                Assert.AreEqual(month.End, month.TimeCalendar.MapEnd(month.Start.AddMonths(1)));
                index++;
            }
            Assert.AreEqual(index, TimeSpec.MonthsPerHalfyear);
        }
Exemplo n.º 28
0
        public void FirstCustomCalendarQuartersTest()
        {
            TimeCalendar      calendar     = TimeCalendar.New(YearMonth.October);
            const int         startYear    = 2004;
            const YearQuarter startQuarter = YearQuarter.First;
            const int         quarterCount = 5;
            Quarters          quarters     = new Quarters(startYear, startQuarter, quarterCount, calendar);

            Assert.AreEqual(quarters.YearBaseMonth, YearMonth.October);
            Assert.AreEqual(quarters.QuarterCount, quarterCount);
            Assert.AreEqual(quarters.StartQuarter, startQuarter);
            Assert.AreEqual(quarters.StartYear, startYear);
            Assert.AreEqual(quarters.EndYear, 2005);
            Assert.AreEqual(quarters.EndQuarter, YearQuarter.First);
            Assert.AreEqual(quarters.GetQuarters().Count, quarterCount);
            Assert.IsTrue(quarters.GetQuarters()[0].IsSamePeriod(new Quarter(2004, YearQuarter.First, calendar)));
            Assert.IsTrue(quarters.GetQuarters()[1].IsSamePeriod(new Quarter(2004, YearQuarter.Second, calendar)));
            Assert.IsTrue(quarters.GetQuarters()[2].IsSamePeriod(new Quarter(2004, YearQuarter.Third, calendar)));
            Assert.IsTrue(quarters.GetQuarters()[3].IsSamePeriod(new Quarter(2004, YearQuarter.Fourth, calendar)));
            Assert.IsTrue(quarters.GetQuarters()[4].IsSamePeriod(new Quarter(2005, YearQuarter.First, calendar)));
        }         // FirstCustomCalendarQuartersTest
Exemplo n.º 29
0
        public void WeekByCultures()
        {
            var now = ClockProxy.Clock.Now;

            CultureTestData.Default
            .RunEach(culture => {
                if (IsDebugEnabled)
                {
                    log.Debug("culture = " + culture);
                }

                var timeCalendar = new TimeCalendar(new TimeCalendarConfig()
                {
                    Culture = culture
                });
                var week = new WeekRange(now, timeCalendar);

                week.StartDayStart.Should().Be(now.StartTimeOfWeek(culture).Date);
                week.EndDayStart.Should().Be(now.EndTimeOfWeek(culture).Date);
            });
        }
Exemplo n.º 30
0
        public void GetQuartersTest()
        {
            int          currentYear  = ClockProxy.Clock.Now.Year;
            TimeCalendar timeCalendar = TimeCalendar.New(YearMonth.October);
            Halfyear     h1           = new Halfyear(currentYear, YearHalfyear.First, timeCalendar);

            ITimePeriodCollection h1Quarters = h1.GetQuarters();

            Assert.NotNull(h1Quarters);

            int h1Index = 0;

            foreach (Quarter h1Quarter in h1Quarters)
            {
                Assert.Equal(h1Quarter.BaseYear, h1.BaseYear);
                Assert.Equal(h1Quarter.YearQuarter, h1Index == 0 ? YearQuarter.First : YearQuarter.Second);
                Assert.Equal(h1Quarter.Start, h1.Start.AddMonths(h1Index * TimeSpec.MonthsPerQuarter));
                Assert.Equal(h1Quarter.End, h1Quarter.Calendar.MapEnd(h1Quarter.Start.AddMonths(TimeSpec.MonthsPerQuarter)));
                h1Index++;
            }
            Assert.Equal(h1Index, TimeSpec.QuartersPerHalfyear);

            Halfyear h2 = new Halfyear(currentYear, YearHalfyear.Second, timeCalendar);

            ITimePeriodCollection h2Quarters = h2.GetQuarters();

            Assert.NotNull(h2Quarters);

            int h2Index = 0;

            foreach (Quarter h2Quarter in h2Quarters)
            {
                Assert.Equal(h2Quarter.BaseYear, h2.BaseYear);
                Assert.Equal(h2Quarter.YearQuarter, h2Index == 0 ? YearQuarter.Third : YearQuarter.Fourth);
                Assert.Equal(h2Quarter.Start, h2.Start.AddMonths(h2Index * TimeSpec.MonthsPerQuarter));
                Assert.Equal(h2Quarter.End, h2Quarter.Calendar.MapEnd(h2Quarter.Start.AddMonths(TimeSpec.MonthsPerQuarter)));
                h2Index++;
            }
            Assert.Equal(h2Index, TimeSpec.QuartersPerHalfyear);
        }         // GetQuartersTest
Exemplo n.º 31
0
        public void CalendarYearQuarterTest()
        {
            var currentYear  = ClockProxy.Clock.Now.Year;
            var timeCalendar = TimeCalendar.NewEmptyOffset();

            var current = new QuarterRange(currentYear, QuarterKind.First);

            current.GetNextQuarter().GetNextQuarter().GetNextQuarter().GetNextQuarter().Quarter.Should().Be(current.Quarter);
            current.GetPreviousQuarter().GetPreviousQuarter().GetPreviousQuarter().GetPreviousQuarter().Quarter.Should().Be(
                current.Quarter);

            var q1 = new QuarterRange(currentYear, QuarterKind.First, timeCalendar);

            Assert.IsTrue(q1.IsReadOnly);
            q1.Quarter.Should().Be(QuarterKind.First);
            q1.Start.Should().Be(new DateTime(currentYear, TimeSpec.FirstQuarterMonth, 1));
            q1.End.Should().Be(new DateTime(currentYear, TimeSpec.SecondQuarterMonth, 1));

            var q2 = new QuarterRange(currentYear, QuarterKind.Second, timeCalendar);

            Assert.IsTrue(q2.IsReadOnly);
            q2.Quarter.Should().Be(QuarterKind.Second);
            q2.Start.Should().Be(new DateTime(currentYear, TimeSpec.SecondQuarterMonth, 1));
            q2.End.Should().Be(new DateTime(currentYear, TimeSpec.ThirdQuarterMonth, 1));

            var q3 = new QuarterRange(currentYear, QuarterKind.Third, timeCalendar);

            Assert.IsTrue(q3.IsReadOnly);
            q3.Quarter.Should().Be(QuarterKind.Third);
            q3.Start.Should().Be(new DateTime(currentYear, TimeSpec.ThirdQuarterMonth, 1));
            q3.End.Should().Be(new DateTime(currentYear, TimeSpec.FourthQuarterMonth, 1));

            var q4 = new QuarterRange(currentYear, QuarterKind.Fourth, timeCalendar);

            Assert.IsTrue(q4.IsReadOnly);
            q4.Quarter.Should().Be(QuarterKind.Fourth);
            q4.Start.Should().Be(new DateTime(currentYear, TimeSpec.FourthQuarterMonth, 1));
            q4.End.Should().Be(new DateTime(currentYear + 1, TimeSpec.FirstQuarterMonth, 1));
        }
Exemplo n.º 32
0
        public void AddHoursTest()
        {
            var now       = ClockProxy.Clock.Now;
            var nowHour   = now.TrimToMinute();
            var hourRange = new HourRange(now, TimeCalendar.NewEmptyOffset());

            hourRange.AddHours(0).Should().Be(hourRange);

            var previousHour = nowHour.AddHours(-1);

            hourRange.AddHours(-1).Year.Should().Be(previousHour.Year);
            hourRange.AddHours(-1).Month.Should().Be(previousHour.Month);
            hourRange.AddHours(-1).Day.Should().Be(previousHour.Day);
            hourRange.AddHours(-1).Hour.Should().Be(previousHour.Hour);

            var nextHour = nowHour.AddHours(1);

            hourRange.AddHours(1).Year.Should().Be(nextHour.Year);
            hourRange.AddHours(1).Month.Should().Be(nextHour.Month);
            hourRange.AddHours(1).Day.Should().Be(nextHour.Day);
            hourRange.AddHours(1).Hour.Should().Be(nextHour.Hour);
        }
Exemplo n.º 33
0
        public void AddHoursTest()
        {
            DateTime now     = ClockProxy.Clock.Now;
            DateTime nowHour = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0);
            Hour     hour    = new Hour(now, TimeCalendar.New(TimeSpan.Zero, TimeSpan.Zero));

            Assert.AreEqual(hour.AddHours(0), hour);

            DateTime previousHour = nowHour.AddHours(-1);

            Assert.AreEqual(hour.AddHours(-1).Year, previousHour.Year);
            Assert.AreEqual(hour.AddHours(-1).Month, previousHour.Month);
            Assert.AreEqual(hour.AddHours(-1).Day, previousHour.Day);
            Assert.AreEqual(hour.AddHours(-1).HourValue, previousHour.Hour);

            DateTime nextHour = nowHour.AddHours(1);

            Assert.AreEqual(hour.AddHours(1).Year, nextHour.Year);
            Assert.AreEqual(hour.AddHours(1).Month, nextHour.Month);
            Assert.AreEqual(hour.AddHours(1).Day, nextHour.Day);
            Assert.AreEqual(hour.AddHours(1).HourValue, nextHour.Hour);
        }         // AddHoursTest
Exemplo n.º 34
0
        public void FirstCustomCalendarHalfyearsTest()
        {
            var                timeCalendar  = TimeCalendar.New(October);
            const int          startYear     = 2004;
            const HalfyearKind startHalfyear = HalfyearKind.First;
            const int          halfyearCount = 3;
            var                halfyears     = new HalfyearRangeCollection(startYear, startHalfyear, halfyearCount, timeCalendar);

            halfyears.YearBaseMonth.Should().Be(October);
            halfyears.HalfyearCount.Should().Be(halfyearCount);
            halfyears.StartHalfyear.Should().Be(startHalfyear);
            halfyears.StartYear.Should().Be(startYear);
            halfyears.EndYear.Should().Be(2005);
            halfyears.EndHalfyear.Should().Be(HalfyearKind.First);

            var halfyearList = halfyears.GetHalfyears().ToList();

            halfyearList.Count.Should().Be(halfyearCount);
            Assert.IsTrue(halfyearList[0].IsSamePeriod(new HalfyearRange(2004, HalfyearKind.First, timeCalendar)));
            Assert.IsTrue(halfyearList[1].IsSamePeriod(new HalfyearRange(2004, HalfyearKind.Second, timeCalendar)));
            Assert.IsTrue(halfyearList[2].IsSamePeriod(new HalfyearRange(2005, HalfyearKind.First, timeCalendar)));
        }
Exemplo n.º 35
0
        public void Iso8601WithMondayAsStartWeekTest()
        {
            CultureInfo usCulture = new CultureInfo("en-US");

            usCulture.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
            usCulture.DateTimeFormat.FirstDayOfWeek   = DayOfWeek.Monday;

            TimeCalendar isoCalendar = new TimeCalendar(
                new TimeCalendarConfig
            {
                YearWeekType = YearWeekType.Iso8601,
                Culture      = usCulture
            });

            Week weekFrom20131229 = new Week(new DateTime(2013, 12, 29), isoCalendar);

            Assert.AreEqual(weekFrom20131229.Start.Date, new DateTime(2013, 12, 23));
            Assert.AreEqual(weekFrom20131229.End.Date, new DateTime(2013, 12, 29));
            Assert.AreEqual(weekFrom20131229.WeekOfYear, 52);

            Week weekFrom20131230 = new Week(new DateTime(2013, 12, 30), isoCalendar);

            Assert.AreEqual(weekFrom20131230.Start.Date, new DateTime(2013, 12, 30));
            Assert.AreEqual(weekFrom20131230.End.Date, new DateTime(2014, 1, 5));
            Assert.AreEqual(weekFrom20131230.WeekOfYear, 1);

            Week weekFrom20140105 = new Week(new DateTime(2014, 1, 5), isoCalendar);

            Assert.AreEqual(weekFrom20140105.Start.Date, new DateTime(2013, 12, 30));
            Assert.AreEqual(weekFrom20140105.End.Date, new DateTime(2014, 1, 5));
            Assert.AreEqual(weekFrom20140105.WeekOfYear, 1);

            Week weekFrom20140106 = new Week(new DateTime(2014, 1, 6), isoCalendar);

            Assert.AreEqual(weekFrom20140106.Start.Date, new DateTime(2014, 1, 6));
            Assert.AreEqual(weekFrom20140106.End.Date, new DateTime(2014, 1, 12));
            Assert.AreEqual(weekFrom20140106.WeekOfYear, 2);
        }         // Iso8601WithMondayAsStartWeekTest
Exemplo n.º 36
0
        public void CalendarDateAdd1Test() {
            CultureTestData.Default
                .RunEach(culture => {
                             var timeCalendar = new TimeCalendar(new TimeCalendarConfig
                                                                 {
                                                                     Culture = culture,
                                                                     EndOffset = TimeSpan.Zero
                                                                 });

                             var calendarDateAdd = new CalendarDateAdd(timeCalendar);

                             //! 주중 8시~18시가 Working Time 이고, 4월 4일은 제외한다
                             //
                             calendarDateAdd.AddWorkingWeekDays();
                             calendarDateAdd.ExcludePeriods.Add(new DayRange(2011, 4, 4, calendarDateAdd.TimeCalendar));
                             calendarDateAdd.WorkingHours.Add(new HourRangeInDay(8, 18));

                             var start = new DateTime(2011, 4, 1, 9, 0, 0);

                             calendarDateAdd.Add(start, DurationUtil.Hours(22)).Should().Be(new DateTime(2011, 4, 6, 11, 0, 0));
                             calendarDateAdd.Add(start, DurationUtil.Hours(22), SeekBoundaryMode.Fill).Should().Be(new DateTime(2011, 4,
                                                                                                                                6, 11, 0,
                                                                                                                                0));

                             calendarDateAdd.Add(start, DurationUtil.Hours(29)).Should().Be(new DateTime(2011, 4, 7, 8, 0, 0));
                             calendarDateAdd.Add(start, DurationUtil.Hours(29), SeekBoundaryMode.Fill).Should().Be(new DateTime(2011, 4,
                                                                                                                                6, 18, 0,
                                                                                                                                0));
                         });
        }