public void EndOfDayHasCorrectResult()
 {
     DateTime dateTime = new DateTime(1970, 11, 5, 12, 30, 20);
     var actual = dateTime.EndOfDay();
     Assert.AreEqual(dateTime.Date, actual.Date);
     Assert.AreEqual(dateTime.Day + 1, actual.AddSeconds(1).Day);
 }
Example #2
0
            public void EndOfDay()
            {
                var anyDate = new DateTime(2014, 1, 3, 3, 24, 50);
                var expectedResult = DateTime.Parse(
                    string.Format(
                        "{0}-{1}-{2} {3}",
                        anyDate.Year,
                        anyDate.Month,
                        anyDate.Day,
                        "23:59:59.9999999"));

                Assert.Equal(expectedResult, anyDate.EndOfDay());
            }
        public DateTimeRange Parse(string content, DateTime now) {
            var m = _parser.Match(content);
            if (!m.Success)
                return null;

            string value = m.Groups["name"].Value.ToLower();
            if (value == "today")
                return new DateTimeRange(now.Date, now.EndOfDay());
            if (value == "yesterday")
                return new DateTimeRange(now.Date.SubtractDays(1), now.Date.SubtractDays(1).EndOfDay());
            if (value == "tomorrow")
                return new DateTimeRange(now.Date.AddDays(1), now.Date.AddDays(1).EndOfDay());

            return null;
        }
        public IEnumerable<CardWorkedDTO> GetDetailedWorkExtract(DateTime startDate, DateTime endDate, IEnumerable<string> boardIds, IEnumerable<string> workers)
        {
            using (MiniProfiler.Current.Step("Getting Detailed Work Extract"))
            {
                var start = startDate.StartOfDay();
                var end = endDate.EndOfDay();

                return boardIds.SelectMany(boardId =>
                {
                    Policy.Handle<Exception>()
                        .WaitAndRetry(5, attempt => TimeSpan.FromSeconds(attempt))
                        .Execute(() =>
                        {
                            _cardWorkExtractorManateeService.Comments =
                                TrelloServiceManateeUtils.GetComments(boardId)
                                    .Where(c => workers.Contains(c.Creator.Id))
                                    .Select(cc => new CardWorkComment
                                    {
                                        CardId = cc.Data.Card.Id,
                                        CardName = cc.Data.Card.Name,
                                        CardLink = cc.Data.Card.ShortUrl,
                                        Who = cc.Creator.FullName,
                                        When = cc.CreationDate,
                                        RawComment = cc.Data.Text
                                    }).ToList();
                        });

                    return TrelloServiceManateeUtils.GetCardsFromBoard(boardId)
                        .SelectMany(card =>
                            _cardWorkExtractorManateeService.GetConsolidatedCardWorkExtract(card.Id)
                                .Where(c => (start <= c.StartedAt && c.StartedAt <= end) ||
                                            (start <= c.StoppedAt && c.StoppedAt <= end))
                                .Select(w => new CardWorkedDTO
                                {
                                    CardName = card.Name,
                                    CardUrl = card.ShortUrl,
                                    Worked = w
                                }));
                });
            }
        }
        public void TestCurrentDate()
        {
            var date = new DateTime(2015, 1, 30, 10, 30, 5);
            var date1 = new DateTime(2015, 1, 30);
            var date2 = new DateTime(2015, 1, 30, 23, 59, 59);
            var date3 = new DateTime(2015, 1, 31);
            var date4 = new DateTime(2015, 1, 29);
            var date5 = new DateTime(2015, 1, 1);
            var date6 = new DateTime(2015, 1, 31);
            var date7 = new DateTime(2015, 1, 26);
            var date8 = new DateTime(2015, 2, 1);
            var date9 = new DateTime(2015, 1, 29);

            Assert.AreEqual(date1, date.StartOfDay());
            Assert.AreEqual(date2, date.EndOfDay());
            Assert.AreEqual(date3, date.NextDay());
            Assert.AreEqual(date4, date.Yesterday());
            Assert.AreEqual(date5, date.GetFirstDayOfMonth());
            Assert.AreEqual(date6, date.GetLastDayOfMonth());
            Assert.AreEqual(date7, date.GetFirstDayOfWeek());
            Assert.AreEqual(date8, date.GetLastDayOfWeek());
            Assert.AreEqual(date9, date.GetWeekday(DayOfWeek.Thursday));
        }
Example #6
0
 public bool HasJob(DateTime forDate)
 {
     return (CreatedOn >= forDate.StartOfDay()) && (CreatedOn <= forDate.EndOfDay());
 }
 public void TimeZoneTests()
 {
     /* story:
      * 1. a web client submits a request to the server for "today",
      * 2. a developer uses :BeginningOfDay and :EndOfDay to perform clamping server-side.
      * 
      * expected:
      * 3. user expects a timezone-correct utc responses from the server, 
      * 
      * actual:
      * 4. user receives a utc response that is too early (:BeginningOfDay), or
      * 5. user receives a utc response that is too late (:EndOfDay)
      */
     for (var i = -11; i <= 12; i++)
     {
         var beginningOfDayUtc = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Utc);
         var actualDayStart = beginningOfDayUtc.BeginningOfDay(i);
         var actualDayEnd = beginningOfDayUtc.EndOfDay(i);
         var expectedDayStart = beginningOfDayUtc
             .AddHours(i);
         var expectedDayEnd = beginningOfDayUtc
             .SetHour(23).SetMinute(59).SetSecond(59).SetMillisecond(999)
             .AddHours(i);
         DateAssert.AreEqual(expectedDayStart, actualDayStart);
         DateAssert.AreEqual(expectedDayEnd, actualDayEnd);
     }
 }
Example #8
0
 public TimeRange(DateTime start, DateTime end)
 {
     this.start = start;
     this.end = end.EndOfDay();
 }