示例#1
0
        public void TestCalendarAdjust()
        {
            var d1 = new Date(2014, 01, 30);
            var d2 = new Date(2014, 01, 31);
            var d3 = new Date(2014, 02, 06);
            var d4 = new Date(2014, 02, 12);

            Assert.AreEqual(new Date(2014, 02, 07), _cal.Adjust(d2, BusinessDayConvention.Following));
            Assert.AreEqual(new Date(2014, 01, 30), _cal.Adjust(d2, BusinessDayConvention.ModifiedFollowing));
            Assert.AreEqual(new Date(2014, 01, 30), _cal.Adjust(d3, BusinessDayConvention.Previous));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.Adjust(d3, BusinessDayConvention.ModifiedPrevious));

            Assert.AreEqual(new Date(2014, 01, 31), _cal.AddDays(d1, 1));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.AddBizDays(d1, 1));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.AddDays(d1, 1, BusinessDayConvention.Following));
            Assert.AreEqual(new Date(2014, 01, 30), _cal.AddDays(d1, 1, BusinessDayConvention.ModifiedFollowing));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.AddBizDays(d1, 1, BusinessDayConvention.Previous));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.AddBizDays(d1, 1, BusinessDayConvention.ModifiedFollowing));

            Assert.AreEqual(new Date(2014, 02, 01), _cal.AddDays(d2, 1));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.AddBizDays(d2, 1));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.AddDays(d2, 1, BusinessDayConvention.Following));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.AddDays(d2, 1, BusinessDayConvention.ModifiedFollowing));
            Assert.AreEqual(new Date(2014, 02, 10), _cal.AddBizDays(d2, 1, BusinessDayConvention.Following));
            Assert.AreEqual(new Date(2014, 02, 07), _cal.AddBizDays(d2, 1, BusinessDayConvention.Previous));

            Assert.AreEqual(false, _cal.BizDaysBetweenDates(d2, d3).Any());
            Assert.AreEqual(4, _cal.BizDaysBetweenDates(d1, d4).Count);
        }
示例#2
0
 /// <summary>
 /// 根据日历和基准日期得到目标日期
 /// </summary>
 /// <param name="calendar">日历</param>
 /// <param name="date">基准日期</param>
 /// <returns>目标日期</returns>
 public Date Get(ICalendar calendar, Date date)
 {
     return(IsBizDay ?
            calendar.AddBizDays(date, Offset, BusinessDayConvention)
                         : calendar.AddDays(date, Offset, BusinessDayConvention));
 }