Example #1
0
        public void test_complete_date_range_5()
        {
            var start = new TruncatedDate(null, 12, 22);
            var end   = new TruncatedDate(null, 12, 27);

            var trdRange = new TruncatedDateRange(start, end);
            var comp     = trdRange.ToCompleteDateRanges(2016, 2018);

            //should be 3 ranges, one for each year
            Assert.NotNull(comp);
            Assert.AreEqual(3, comp.Length);

            Assert.AreEqual(12, comp[0].DateStart.Month);
            Assert.AreEqual(22, comp[0].DateStart.Day);

            Assert.AreEqual(12, comp[2].DateEnd.Month);
            Assert.AreEqual(27, comp[2].DateEnd.Day);

            Assert.AreEqual(2016, comp[0].DateStart.Year);
            Assert.AreEqual(2017, comp[1].DateStart.Year);
            Assert.AreEqual(2018, comp[2].DateStart.Year);

            Assert.AreEqual(2016, comp[0].DateEnd.Year);
            Assert.AreEqual(2017, comp[1].DateEnd.Year);
            Assert.AreEqual(2018, comp[2].DateEnd.Year);
        }
Example #2
0
 public void test_within_truncated_3()
 {
     trd = new TruncatedDate(null, 7, 22);
     Assert.False(trd.IsWithin(new CompleteDate(2017, 7, 21)));
     Assert.False(trd.IsWithin(new CompleteDate(2011, 7, 31)));
     Assert.False(trd.IsWithin(new CompleteDate(1901, 6, 21)));
     Assert.True(trd.IsWithin(new CompleteDate(2018, 7, 22)));
 }
Example #3
0
 public void test_create_truncated_dates()
 {
     trd = new TruncatedDate(2017, 7, null);
     Assert.AreEqual("year 2017 month 7 any day", trd.Explanation);
     trd = new TruncatedDate(null, 7, null);
     Assert.AreEqual("any year month 7 any day", trd.Explanation);
     trd = new TruncatedDate(null, null, 4);
     Assert.AreEqual("any year any month day 4", trd.Explanation);
 }
Example #4
0
 /// <summary>
 /// Create new range using start- and end dates
 /// </summary>
 /// <param name="dateStart"></param>
 /// <param name="dateEnd"></param>
 public TruncatedDateRange(TruncatedDate dateStart, TruncatedDate dateEnd)
 {
     this.dateStart = dateStart;
     this.dateEnd   = dateEnd;
     if (dateStart.TruncationType != dateEnd.TruncationType)
     {
         throw new TimeHandlerException("Truncated date range must contain dates of same type.");
     }
 }
Example #5
0
        public void test_complete_date_range_4()
        {
            var start = new TruncatedDate(2014, null, null);
            var end   = new TruncatedDate(2015, null, null);

            var trdRange = new TruncatedDateRange(start, end);
            var comp     = trdRange.ToCompleteDateRanges(2016, 2018);

            //Not within given period of interest
            Assert.Null(comp);
        }
Example #6
0
        public void test_within_truncated_range_2()
        {
            //each year 2017-07-22 .. 08-12
            var start = new TruncatedDate(2017, 7, null);
            var end   = new TruncatedDate(2017, 8, null);

            var trdRange = new TruncatedDateRange(start, end);

            Assert.False(trdRange.IsWithin(new CompleteDate(2016, 7, 22)));
            Assert.True(trdRange.IsWithin(new CompleteDate(2017, 7, 1)));
            Assert.True(trdRange.IsWithin(new CompleteDate(2017, 8, 12)));
        }
Example #7
0
        public void test_within_truncated_range_3()
        {
            var start = new TruncatedDate(2017, null, 12);
            var end   = new TruncatedDate(2017, null, 15);

            var trdRange = new TruncatedDateRange(start, end);

            Assert.False(trdRange.IsWithin(new CompleteDate(2017, 7, 16)));
            Assert.False(trdRange.IsWithin(new CompleteDate(2016, 7, 13)));
            Assert.True(trdRange.IsWithin(new CompleteDate(2017, 7, 15)));
            Assert.True(trdRange.IsWithin(new CompleteDate(2017, 1, 12)));
        }
Example #8
0
        public void test_complete_date_range_3()
        {
            var start = new TruncatedDate(2014, null, null);
            var end   = new TruncatedDate(2017, null, null);

            var trdRange = new TruncatedDateRange(start, end);
            var comp     = trdRange.ToCompleteDateRanges(2016, 2018);

            Assert.AreEqual(1, comp.Length);
            Assert.NotNull(comp);

            Assert.AreEqual("20140101", comp[0].DateStart.BasicFormat);
            Assert.AreEqual("20171231", comp[0].DateEnd.BasicFormat);
        }
Example #9
0
        public void test_within_truncated_range_1()
        {
            //each year 07-22 .. 08-12
            var start = new TruncatedDate(null, 7, 22);
            var end   = new TruncatedDate(null, 8, 12);

            var trdRange = new TruncatedDateRange(start, end);

            Assert.True(trdRange.IsWithin(new CompleteDate(1730, 7, 22)));
            Assert.True(trdRange.IsWithin(new CompleteDate(1730, 7, 31)));
            Assert.True(trdRange.IsWithin(new CompleteDate(1730, 8, 12)));

            Assert.False(trdRange.IsWithin(new CompleteDate(1730, 7, 21)));
            Assert.False(trdRange.IsWithin(new CompleteDate(2017, 7, 21)));
        }
Example #10
0
        public void test__truncated_type()
        {
            trd = new TruncatedDate(null, null, 22);
            Assert.AreEqual(1, trd.TruncationType);

            trd = new TruncatedDate(null, 7, null);
            Assert.AreEqual(2, trd.TruncationType);

            trd = new TruncatedDate(null, 7, 22);
            Assert.AreEqual(3, trd.TruncationType);

            trd = new TruncatedDate(2017, null, null);
            Assert.AreEqual(4, trd.TruncationType);

            trd = new TruncatedDate(2017, null, 22);
            Assert.AreEqual(5, trd.TruncationType);

            trd = new TruncatedDate(2017, 7, null);
            Assert.AreEqual(6, trd.TruncationType);

            trd = new TruncatedDate(2017, 7, 22);
            Assert.AreEqual(7, trd.TruncationType);
        }