Example #1
0
        public DateTimeRangeArchive CreateArchive(DateTime createAt)
        {
            var dateTimeRangeArchive = new DateTimeRangeArchive();
            var dayDate = createAt.GetDayDate();

            dateTimeRangeArchive.Begin     = dayDate;
            dateTimeRangeArchive.End       = dayDate.AddDays(1).AddMilliseconds(-1);;
            dateTimeRangeArchive.ArchiveId = dayDate.ToString(DateFormat);
            return(dateTimeRangeArchive);
        }
Example #2
0
        public DateTimeRangeArchive TryParseArchive(string archiveId)
        {
            var dateTimeRangeArchive = new DateTimeRangeArchive();

            var beginDate = archiveId.TryParseDate(DateFormat);

            if (beginDate == null)
            {
                return(null);
            }

            dateTimeRangeArchive.Begin     = beginDate.Value;
            dateTimeRangeArchive.End       = beginDate.Value.AddDays(1).AddMilliseconds(-1);
            dateTimeRangeArchive.ArchiveId = archiveId;
            return(dateTimeRangeArchive);
        }
Example #3
0
        public void DateTimeRangeArchive_TryParse_ShouldOk()
        {
            var archiveIds = new List <string>();

            for (int i = 1; i <= 9; i++)
            {
                archiveIds.Add("201905050" + i);
            }
            var archives = DateTimeRangeArchive.TryParse(archiveIds).ToList();

            archives.Log();
            archives.Count.ShouldEqual(9);

            var mockDate = new DateTime(2019, 5, 5, 1, 0, 0);
            var dateTimeRangeArchives = archives.FilterOverlaps(mockDate.AddHours(0), mockDate.AddHours(1)).ToList();

            dateTimeRangeArchives.Log();
            dateTimeRangeArchives.Count.ShouldEqual(1);
            dateTimeRangeArchives.Single().ArchiveId.ShouldEqual("2019050501");
        }
Example #4
0
        public void DateTimeRangeArchive_Create_ShouldOk()
        {
            var mockDate  = new DateTime(2019, 5, 5, 1, 0, 0);
            var mockDate2 = mockDate.AddMinutes(30);
            var mockDate3 = mockDate.AddMinutes(60);
            var archive   = DateTimeRangeArchive.Create(mockDate);

            archive.Log();
            archive.ArchiveId.ShouldEqual("2019050501");

            var archive2 = DateTimeRangeArchive.Create(mockDate2);

            archive2.Log();
            archive2.ArchiveId.ShouldEqual("2019050501");

            var archive3 = DateTimeRangeArchive.Create(mockDate3);

            archive3.Log();
            archive3.ArchiveId.ShouldEqual("2019050502");
        }