예제 #1
0
        public void MultipleCalendarYearsTest()
        {
            DateTime now = ClockProxy.Clock.Now;

            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(1)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(2)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(3)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(4)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(5)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(6)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(7)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(8)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(9)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(10)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(11)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.First, TimeCalendar.New(12)).MultipleCalendarYears);

            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(1)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(2)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(3)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(4)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(5)).MultipleCalendarYears);
            Assert.IsTrue(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(6)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(7)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(8)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(9)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(10)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(11)).MultipleCalendarYears);
            Assert.IsFalse(new HalfyearRange(now.Year, HalfyearKind.Second, TimeCalendar.New(12)).MultipleCalendarYears);
        }
예제 #2
0
        public void YearHalfyearTest()
        {
            var currentYear = ClockProxy.Clock.Now.Year;

            new HalfyearRange(currentYear, HalfyearKind.First, TimeCalendar.New(4)).Halfyear.Should().Be(HalfyearKind.First);
            new HalfyearRange(currentYear, HalfyearKind.Second, TimeCalendar.New(4)).Halfyear.Should().Be(HalfyearKind.Second);
        }
예제 #3
0
        public void DefaultHalfyearTest()
        {
            var       currentYear    = ClockProxy.Clock.Now.Year;
            const int yearStartMonth = 4;
            var       calendar       = TimeCalendar.New(TimeSpan.Zero, TimeSpan.Zero, yearStartMonth);

            var h1 = new HalfyearRange(currentYear, HalfyearKind.First, calendar);

            h1.IsReadOnly.Should().Be.True();
            h1.IsCalendarHalfyear.Should().Be.False();
            h1.YearBaseMonth.Should().Be(yearStartMonth);
            h1.Halfyear.Should().Be(HalfyearKind.First);
            h1.BaseYear.Should().Be(currentYear);
            h1.Start.Should().Be(new DateTime(currentYear, 4, 1));
            h1.End.Should().Be(new DateTime(currentYear, 10, 1));

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

            h2.IsReadOnly.Should().Be.True();
            h2.IsCalendarHalfyear.Should().Be.False();
            h2.YearBaseMonth.Should().Be(yearStartMonth);
            h2.Halfyear.Should().Be(HalfyearKind.Second);
            h2.BaseYear.Should().Be(currentYear);
            h2.Start.Should().Be(new DateTime(currentYear, 10, 1));
            h2.End.Should().Be(new DateTime(currentYear + 1, 4, 1));
        }
예제 #4
0
        public void YearQuarterTest()
        {
            var currentYear = ClockProxy.Clock.Now.Year;

            new QuarterRange(currentYear, QuarterKind.Third, TimeCalendar.New(April)).Quarter.Should().Be(QuarterKind.Third);
            new QuarterRange(currentYear, QuarterKind.Third).Quarter.Should().Be(QuarterKind.Third);
        }
예제 #5
0
        public void GetStartOfWeekTest()
        {
            DateTime        now      = ClockProxy.Clock.Now;
            CultureTestData cultures = new CultureTestData();

            foreach (CultureInfo culture in cultures)
            {
                foreach (CalendarWeekRule weekRule in Enum.GetValues(typeof(CalendarWeekRule)))
                {
                    culture.DateTimeFormat.CalendarWeekRule = weekRule;

                    int year;
                    int weekOfYear;

                    // calendar week
                    TimeTool.GetWeekOfYear(now, culture, YearWeekType.Calendar, out year, out weekOfYear);
                    DateTime     weekStartCalendar = TimeTool.GetStartOfYearWeek(year, weekOfYear, culture, YearWeekType.Calendar);
                    TimeCalendar timeCalendar      = TimeCalendar.New(culture);
                    Assert.Equal <DateTime>(timeCalendar.GetStartOfYearWeek(year, weekOfYear), weekStartCalendar);

                    // iso 8601 calendar week
                    TimeTool.GetWeekOfYear(now, culture, YearWeekType.Iso8601, out year, out weekOfYear);
                    DateTime     weekStartCalendarIso8601 = TimeTool.GetStartOfYearWeek(year, weekOfYear, culture, YearWeekType.Iso8601);
                    TimeCalendar timeCalendarIso8601      = TimeCalendar.New(culture, YearMonth.January, YearWeekType.Iso8601);
                    Assert.Equal <DateTime>(timeCalendarIso8601.GetStartOfYearWeek(year, weekOfYear), weekStartCalendarIso8601);
                }
            }
        }         // GetStartOfWeekTest
예제 #6
0
        public void StartMonthTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            Enumerable.Range(1, TimeSpec.MonthsPerYear)
            .RunEach(m => {
                new QuarterRange(currentYear, QuarterKind.First, TimeCalendar.New(m)).StartMonth.Should().Be(m);
                new QuarterRange(currentYear, QuarterKind.Second, TimeCalendar.New(m)).StartMonth.Should().Be((m +
                                                                                                               TimeSpec.
                                                                                                               MonthsPerQuarter -
                                                                                                               1) %
                                                                                                              TimeSpec.
                                                                                                              MonthsPerYear +
                                                                                                              1);
                new QuarterRange(currentYear, QuarterKind.Third, TimeCalendar.New(m)).StartMonth.Should().Be((m +
                                                                                                              TimeSpec.
                                                                                                              MonthsPerQuarter *
                                                                                                              2 - 1) %
                                                                                                             TimeSpec.
                                                                                                             MonthsPerYear +
                                                                                                             1);
                new QuarterRange(currentYear, QuarterKind.Fourth, TimeCalendar.New(m)).StartMonth.Should().Be((m +
                                                                                                               TimeSpec.
                                                                                                               MonthsPerQuarter *
                                                                                                               3 - 1) %
                                                                                                              TimeSpec.
                                                                                                              MonthsPerYear +
                                                                                                              1);
            });
        }
예제 #7
0
        public void MultipleCalendarYearsTest()
        {
            DateTime now = ClockProxy.Clock.Now;

            Assert.False(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.January)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.February)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.March)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.April)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.May)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.June)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.July)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.August)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.September)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.October)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.November)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.New(YearMonth.December)).MultipleCalendarYears);

            Assert.False(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.January)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.February)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.March)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.April)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.May)).MultipleCalendarYears);
            Assert.True(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.June)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.July)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.August)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.September)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.October)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.November)).MultipleCalendarYears);
            Assert.False(new Halfyear(now.Year, YearHalfyear.Second, TimeCalendar.New(YearMonth.December)).MultipleCalendarYears);
        }         // MultipleCalendarYearsTest
예제 #8
0
        public void CalendarHalfyearTest()
        {
            int          currentYear = ClockProxy.Clock.Now.Year;
            TimeCalendar calendar    = TimeCalendar.New(TimeSpan.Zero, TimeSpan.Zero);

            Halfyear h1 = new Halfyear(currentYear, YearHalfyear.First, calendar);

            Assert.True(h1.IsReadOnly);
            Assert.True(h1.IsCalendarHalfyear);
            Assert.Equal(h1.YearBaseMonth, TimeSpec.CalendarYearStartMonth);
            Assert.Equal(YearHalfyear.First, h1.YearHalfyear);
            Assert.Equal(h1.BaseYear, currentYear);
            Assert.Equal(h1.Start, new DateTime(currentYear, 1, 1));
            Assert.Equal(h1.End, new DateTime(currentYear, 7, 1));

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

            Assert.True(h2.IsReadOnly);
            Assert.True(h2.IsCalendarHalfyear);
            Assert.Equal(h2.YearBaseMonth, TimeSpec.CalendarYearStartMonth);
            Assert.Equal(YearHalfyear.Second, h2.YearHalfyear);
            Assert.Equal(h2.BaseYear, currentYear);
            Assert.Equal(h2.Start, new DateTime(currentYear, 7, 1));
            Assert.Equal(h2.End, new DateTime(currentYear + 1, 1, 1));
        }         // CalendarHalfyearTest
예제 #9
0
        public void YearBaseMonthTest()
        {
            var year = new YearRange(TimeCalendar.New(April));

            year.YearBaseMonth.Should().Be(April);
            new YearRange().YearBaseMonth.Should().Be(January);
        }
예제 #10
0
        public void YearTest()
        {
            var currentYear = ClockProxy.Clock.Now.Year;

            new HalfyearRange(currentYear, HalfyearKind.First, TimeCalendar.New(4)).BaseYear.Should().Be(currentYear);
            new HalfyearRange(2006, HalfyearKind.First).BaseYear.Should().Be(2006);
        }
예제 #11
0
        public void YearTest()
        {
            var currentYear = ClockProxy.Clock.Now.Year;

            new QuarterRange(currentYear, QuarterKind.Fourth, TimeCalendar.New(April)).BaseYear.Should().Be(currentYear);
            new QuarterRange(2006, QuarterKind.Fourth).BaseYear.Should().Be(2006);
        }
예제 #12
0
        public void YearCompareTest()
        {
            DateTime moment             = new DateTime(2008, 2, 18);
            Year     calendarYearSweden = new Year(moment, TimeCalendar.New(YearMonth.January));

            Assert.AreEqual(calendarYearSweden.YearBaseMonth, YearMonth.January);

            Year calendarYearGermany = new Year(moment, TimeCalendar.New(YearMonth.April));

            Assert.AreEqual(calendarYearGermany.YearBaseMonth, YearMonth.April);

            Year calendarYearUnitedStates = new Year(moment, TimeCalendar.New(YearMonth.October));

            Assert.AreEqual(calendarYearUnitedStates.YearBaseMonth, YearMonth.October);

            Assert.AreNotEqual(calendarYearSweden, calendarYearGermany);
            Assert.AreNotEqual(calendarYearSweden, calendarYearUnitedStates);
            Assert.AreNotEqual(calendarYearGermany, calendarYearUnitedStates);

            Assert.AreEqual(calendarYearSweden.BaseYear, calendarYearGermany.BaseYear + 1);
            Assert.AreEqual(calendarYearSweden.BaseYear, calendarYearUnitedStates.BaseYear + 1);

            Assert.AreEqual(calendarYearSweden.GetPreviousYear().BaseYear, calendarYearGermany.GetPreviousYear().BaseYear + 1);
            Assert.AreEqual(calendarYearSweden.GetPreviousYear().BaseYear, calendarYearUnitedStates.GetPreviousYear().BaseYear + 1);

            Assert.AreEqual(calendarYearSweden.GetNextYear().BaseYear, calendarYearGermany.GetNextYear().BaseYear + 1);
            Assert.AreEqual(calendarYearSweden.GetNextYear().BaseYear, calendarYearUnitedStates.GetNextYear().BaseYear + 1);

            Assert.IsTrue(calendarYearSweden.IntersectsWith(calendarYearGermany));
            Assert.IsTrue(calendarYearSweden.IntersectsWith(calendarYearUnitedStates));
            Assert.IsTrue(calendarYearGermany.IntersectsWith(calendarYearUnitedStates));
        }         // YearCompareTest
예제 #13
0
        public void GetMonthsTest()
        {
            const int       startYear  = 2004;
            const int       yearCount  = 10;
            const YearMonth startMonth = YearMonth.October;
            Years           years      = new Years(startYear, yearCount, TimeCalendar.New(startMonth));

            ITimePeriodCollection months = years.GetMonths();

            Assert.NotNull(months);

            int index = 0;

            foreach (Month month in months)
            {
                int       monthYear;
                YearMonth monthMonth;
                TimeTool.AddMonth(startYear, startMonth, index, out monthYear, out monthMonth);
                Assert.Equal(month.Year, monthYear);
                Assert.Equal(month.Start, years.Start.AddMonths(index));
                Assert.Equal(month.End, month.Calendar.MapEnd(month.Start.AddMonths(1)));
                index++;
            }
            Assert.Equal(index, yearCount * TimeSpec.MonthsPerYear);
        }         // GetMonthsTest
예제 #14
0
        public void YearTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            Assert.Equal(new Quarter(currentYear, YearQuarter.Fourth, TimeCalendar.New(YearMonth.April)).BaseYear, currentYear);
            Assert.Equal(2006, new Quarter(2006, YearQuarter.Fourth).BaseYear);
        }         // YearTest
        public void StartMonthTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.January)).StartMonth, YearMonth.January);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.February)).StartMonth, YearMonth.February);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.March)).StartMonth, YearMonth.March);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.April)).StartMonth, YearMonth.April);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.May)).StartMonth, YearMonth.May);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.June)).StartMonth, YearMonth.June);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.July)).StartMonth, YearMonth.July);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.August)).StartMonth, YearMonth.August);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.September)).StartMonth, YearMonth.September);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.October)).StartMonth, YearMonth.October);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.November)).StartMonth, YearMonth.November);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.December)).StartMonth, YearMonth.December);

            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.January)).StartMonth, YearMonth.July);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.February)).StartMonth, YearMonth.August);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.March)).StartMonth, YearMonth.September);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.April)).StartMonth, YearMonth.October);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.May)).StartMonth, YearMonth.November);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.June)).StartMonth, YearMonth.December);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.July)).StartMonth, YearMonth.January);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.August)).StartMonth, YearMonth.February);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.September)).StartMonth, YearMonth.March);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.October)).StartMonth, YearMonth.April);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.November)).StartMonth, YearMonth.May);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.December)).StartMonth, YearMonth.June);
        }         // StartMonthTest
예제 #16
0
        public void YearQuarterTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            Assert.AreEqual(new Quarter(currentYear, YearQuarter.Third, TimeCalendar.New(YearMonth.April)).YearQuarter, YearQuarter.Third);
            Assert.AreEqual(new Quarter(currentYear, YearQuarter.Third).YearQuarter, YearQuarter.Third);
        }         // YearQuarterTest
        public void YearHalfyearTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.April)).YearHalfyear, YearHalfyear.First);
            Assert.AreEqual(new Halfyear(currentYear, YearHalfyear.Second, TimeCalendar.New(YearMonth.April)).YearHalfyear, YearHalfyear.Second);
        }         // YearHalfyearTest
예제 #18
0
        public void YearBaseMonthTest()
        {
            Year year = new Year(TimeCalendar.New(YearMonth.April));

            Assert.Equal(YearMonth.April, year.YearBaseMonth);
            Assert.Equal(YearMonth.January, new Year().YearBaseMonth);
        }         // YearBaseMonthTest
        public void FirstCustomCalendarQuartersTest()
        {
            var               calendar     = TimeCalendar.New(October);
            const int         startYear    = 2004;
            const QuarterKind startQuarter = QuarterKind.First;
            const int         quarterCount = 5;

            var quarterRanges = new QuarterRangeCollection(startYear, startQuarter, quarterCount, calendar);

            quarterRanges.YearBaseMonth.Should().Be(October);
            quarterRanges.QuarterCount.Should().Be(quarterCount);
            quarterRanges.StartQuarter.Should().Be(startQuarter);
            quarterRanges.StartYear.Should().Be(startYear);
            quarterRanges.EndYear.Should().Be(2005);
            quarterRanges.EndQuarter.Should().Be(QuarterKind.First);

            var quarters = quarterRanges.GetQuarters().ToTimePeriodCollection();

            quarters.Count.Should().Be(quarterCount);
            quarters[0].IsSamePeriod(new QuarterRange(2004, QuarterKind.First, calendar)).Should().Be.True();
            quarters[1].IsSamePeriod(new QuarterRange(2004, QuarterKind.Second, calendar)).Should().Be.True();
            quarters[2].IsSamePeriod(new QuarterRange(2004, QuarterKind.Third, calendar)).Should().Be.True();
            quarters[3].IsSamePeriod(new QuarterRange(2004, QuarterKind.Fourth, calendar)).Should().Be.True();
            quarters[4].IsSamePeriod(new QuarterRange(2005, QuarterKind.First, calendar)).Should().Be.True();
        }
예제 #20
0
        public void DefaultHalfyearTest()
        {
            int             currentYear    = ClockProxy.Clock.Now.Year;
            const YearMonth yearStartMonth = YearMonth.April;
            TimeCalendar    calendar       = TimeCalendar.New(TimeSpan.Zero, TimeSpan.Zero, yearStartMonth);

            Halfyear h1 = new Halfyear(currentYear, YearHalfyear.First, calendar);

            Assert.True(h1.IsReadOnly);
            Assert.False(h1.IsCalendarHalfyear);
            Assert.Equal(h1.YearBaseMonth, yearStartMonth);
            Assert.Equal(YearHalfyear.First, h1.YearHalfyear);
            Assert.Equal(h1.BaseYear, currentYear);
            Assert.Equal(h1.Start, new DateTime(currentYear, 4, 1));
            Assert.Equal(h1.End, new DateTime(currentYear, 10, 1));

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

            Assert.True(h2.IsReadOnly);
            Assert.False(h2.IsCalendarHalfyear);
            Assert.Equal(h2.YearBaseMonth, yearStartMonth);
            Assert.Equal(YearHalfyear.Second, h2.YearHalfyear);
            Assert.Equal(h2.BaseYear, currentYear);
            Assert.Equal(h2.Start, new DateTime(currentYear, 10, 1));
            Assert.Equal(h2.End, new DateTime(currentYear + 1, 4, 1));
        }         // DefaultHalfyearTest
예제 #21
0
        public void YearCompareTest()
        {
            var moment             = new DateTime(2008, 2, 18);
            var calendarYearSweden = new YearRange(moment, TimeCalendar.New(January));

            calendarYearSweden.YearBaseMonth.Should().Be(January);

            var calendarYearGermany = new YearRange(moment, TimeCalendar.New(April));

            calendarYearGermany.YearBaseMonth.Should().Be(April);

            var calendarYearUnitedStates = new YearRange(moment, TimeCalendar.New(October));

            calendarYearUnitedStates.YearBaseMonth.Should().Be(October);

            calendarYearSweden.Should().Not.Be.EqualTo(calendarYearGermany);
            calendarYearSweden.Should().Not.Be.EqualTo(calendarYearUnitedStates);
            calendarYearGermany.Should().Not.Be.EqualTo(calendarYearUnitedStates);

            calendarYearSweden.BaseYear.Should().Be(calendarYearGermany.BaseYear + 1);
            calendarYearSweden.BaseYear.Should().Be(calendarYearUnitedStates.BaseYear + 1);

            calendarYearSweden.GetPreviousYear().BaseYear.Should().Be(calendarYearGermany.GetPreviousYear().BaseYear + 1);
            calendarYearSweden.GetPreviousYear().BaseYear.Should().Be(calendarYearUnitedStates.GetPreviousYear().BaseYear + 1);

            calendarYearSweden.GetNextYear().BaseYear.Should().Be(calendarYearGermany.GetNextYear().BaseYear + 1);
            calendarYearSweden.GetNextYear().BaseYear.Should().Be(calendarYearUnitedStates.GetNextYear().BaseYear + 1);

            calendarYearSweden.IntersectsWith(calendarYearGermany).Should().Be.True();
            calendarYearSweden.IntersectsWith(calendarYearUnitedStates).Should().Be.True();
            calendarYearGermany.IntersectsWith(calendarYearUnitedStates).Should().Be.True();
        }
예제 #22
0
        public void GetStartOfWeekTest()
        {
            var now = ClockProxy.Clock.Now;

            foreach (CultureInfo culture in CultureTestData.Default)
            {
#if !SILVERLIGHT
                foreach (CalendarWeekRule weekRule in Enum.GetValues(typeof(CalendarWeekRule)))
#else
                foreach (CalendarWeekRule weekRule in Enumerable.Range(0, 2))
#endif
                {
                    culture.DateTimeFormat.CalendarWeekRule = weekRule;

                    // calendar week
                    var yearWeek          = TimeTool.GetWeekOfYear(now, culture, WeekOfYearRuleKind.Calendar);
                    var weekStartCalendar = TimeTool.GetStartOfYearWeek(yearWeek.Year ?? 0, yearWeek.Week ?? 1, culture,
                                                                        WeekOfYearRuleKind.Calendar);
                    var timeCalendar = TimeCalendar.New(culture);

                    timeCalendar.GetStartOfYearWeek(yearWeek.Year ?? 0, yearWeek.Week ?? 1).Should().Be(weekStartCalendar);

                    // iso 8601 calendar week
                    yearWeek = TimeTool.GetWeekOfYear(now, culture, WeekOfYearRuleKind.Iso8601);
                    var weekStartCalendarIso8601 = TimeTool.GetStartOfYearWeek(yearWeek.Year ?? 0, yearWeek.Week ?? 1, culture,
                                                                               WeekOfYearRuleKind.Iso8601);
                    var timeCalendarIso8601 = TimeCalendar.New(culture, January, WeekOfYearRuleKind.Iso8601);

                    timeCalendarIso8601.GetStartOfYearWeek(yearWeek.Year ?? 0, yearWeek.Week ?? 1).Should().Be(weekStartCalendarIso8601);
                }
            }
        }
예제 #23
0
        public void DefaultCalendarTest()
        {
            const int startWeek   = 1;
            var       currentTime = ClockProxy.Clock.Now;
            var       currentYear = ClockProxy.Clock.Now.Year;

            Action <CultureInfo> @weekRangeTestAction =
                (culture) => {
                foreach (WeekOfYearRuleKind yearWeekType in WeekOfYearRules)
                {
                    var yearWeek = WeekTool.GetYearAndWeek(currentTime, culture, yearWeekType);

                    for (int weekOfYear = startWeek; weekOfYear < yearWeek.Week; weekOfYear++)
                    {
                        var week = new WeekRange(currentYear, weekOfYear, TimeCalendar.New(culture, 1, yearWeekType));
                        week.Year.Should().Be(currentYear);

                        var weekStart = WeekTool.GetWeekRange(new YearAndWeek(currentYear, weekOfYear), culture, yearWeekType).Start;
                        var weekEnd   = weekStart.AddDays(TimeSpec.DaysPerWeek);

                        week.UnmappedStart.Should().Be(weekStart);
                        week.UnmappedEnd.Should().Be(weekEnd);
                    }
                }
            };

            Parallel.For(0, CultureTestData.Default.Count(), i => @weekRangeTestAction(CultureTestData.Default[i]));

            //!++ BUG:Silverlight 용 Paralell.ForEach 에 버그가 있습니다.
            // Parallel.ForEach(CultureTestData.Default.Cultures, @weekRangeTestAction);
        }
예제 #24
0
        public void YearTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;

            Assert.Equal(new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.April)).BaseYear, currentYear);
            Assert.Equal(2006, new Halfyear(2006, YearHalfyear.First).BaseYear);
        }         // YearTest
예제 #25
0
        public void YearBaseMonthTest()
        {
            Year year = new Year(TimeCalendar.New(YearMonth.April));

            Assert.AreEqual(year.YearBaseMonth, YearMonth.April);
            Assert.AreEqual(new Year().YearBaseMonth, YearMonth.January);
        }         // YearBaseMonthTest
예제 #26
0
        public void YearBaseMonthTest()
        {
            int      currentYear = ClockProxy.Clock.Now.Year;
            Halfyear halfyear    = new Halfyear(currentYear, YearHalfyear.First, TimeCalendar.New(YearMonth.April));

            Assert.Equal(YearMonth.April, halfyear.YearBaseMonth);
            Assert.Equal(YearMonth.January, new Halfyear(currentYear, YearHalfyear.Second).YearBaseMonth);
        }         // YearBaseMonthTest
예제 #27
0
        public void YearBaseMonthTest()
        {
            var currentYear = ClockProxy.Clock.Now.Year;
            var halfyear    = new HalfyearRange(currentYear, HalfyearKind.First, TimeCalendar.New(April));

            halfyear.YearBaseMonth.Should().Be(April);
            new HalfyearRange(currentYear, HalfyearKind.Second).YearBaseMonth.Should().Be(1);
        }
예제 #28
0
        public void YearBaseMonthTest()
        {
            DateTime  moment    = new DateTime(2009, 2, 15);
            int       year      = TimeTool.GetYearOf(YearMonth.April, moment.Year, moment.Month);
            Halfyears halfyears = new Halfyears(moment, YearHalfyear.First, 3, TimeCalendar.New(YearMonth.April));

            Assert.Equal(YearMonth.April, halfyears.YearBaseMonth);
            Assert.Equal <DateTime>(halfyears.Start, new DateTime(year, (int)YearMonth.April, 1));
        }         // YearBaseMonthTest
예제 #29
0
 public void IsCalendarYearTest()
 {
     Assert.IsFalse(new Year(TimeCalendar.New(YearMonth.April)).IsCalendarYear);
     Assert.IsTrue(new Year(TimeCalendar.New(YearMonth.January)).IsCalendarYear);
     Assert.IsFalse(new Year(2008, TimeCalendar.New(YearMonth.April)).IsCalendarYear);
     Assert.IsTrue(new Year(2008).IsCalendarYear);
     Assert.IsTrue(new Year().IsCalendarYear);
     Assert.IsTrue(new Year(2008).IsCalendarYear);
 }         // IsCalendarYearTest
        public void YearBaseMonthTest()
        {
            DateTime moment   = new DateTime(2009, 2, 15);
            int      year     = TimeTool.GetYearOf(YearMonth.April, moment.Year, moment.Month);
            Quarters quarters = new Quarters(moment, YearQuarter.First, 3, TimeCalendar.New(YearMonth.April));

            Assert.AreEqual(quarters.YearBaseMonth, YearMonth.April);
            Assert.AreEqual(quarters.Start, new DateTime(year, (int)YearMonth.April, 1));
        }         // YearBaseMonthTest