Beispiel #1
0
        public void GetFrequencyUnitDifferenceExclusiveDaily()
        {
            var frequency   = StreakOccurrenceFrequency.Daily;
            var isInclusive = false;

            // Month of January is 31 days long
            var startDate = new DateTime(2019, 1, 1);
            var endDate   = new DateTime(2019, 1, 31);
            var result    = StreakTypeService.GetFrequencyUnitDifference(startDate, endDate, frequency, isInclusive);

            Assert.Equal(30, result);

            // Year of 2019 is 365 days long
            startDate = new DateTime(2019, 1, 1);
            endDate   = new DateTime(2019, 12, 31);
            result    = StreakTypeService.GetFrequencyUnitDifference(startDate, endDate, frequency, isInclusive);
            Assert.Equal(364, result);

            // Negative calculation is okay
            startDate = new DateTime(2019, 1, 1);
            endDate   = new DateTime(2018, 12, 31);
            result    = StreakTypeService.GetFrequencyUnitDifference(startDate, endDate, frequency, isInclusive);
            Assert.Equal(-1, result);

            // Same day calculation is 0
            result = StreakTypeService.GetFrequencyUnitDifference(startDate, startDate, frequency, isInclusive);
            Assert.Equal(0, result);
        }
Beispiel #2
0
        /// <summary>
        /// Shows the controls needed
        /// </summary>
        private void RenderCheckboxes()
        {
            nbMessage.Text = string.Empty;
            var streakType = GetStreakType();

            if (streakType == null)
            {
                ShowBlockError(nbMessage, "A streak type is required.");
                return;
            }

            if (!CanEdit())
            {
                SetVisible(false);
                return;
            }

            lTitle.Text = GetTargetMapTitle();
            var map          = GetTargetMap();
            var errorMessage = string.Empty;

            var isDaily   = streakType.OccurrenceFrequency == StreakOccurrenceFrequency.Daily;
            var dateRange = GetDateRange();
            var startDate = dateRange.Start.Value;
            var endDate   = dateRange.End.Value;

            if (!isDaily)
            {
                startDate = startDate.SundayDate();
                endDate   = endDate.SundayDate();
            }

            cblCheckboxes.Label = isDaily ? "Days" : "Weeks";
            cblCheckboxes.Items.Clear();

            var minDate       = GetMinDate();
            var maxDate       = isDaily ? RockDateTime.Today : RockDateTime.Today.SundayDate();
            var checkboxCount = StreakTypeService.GetFrequencyUnitDifference(startDate, endDate, streakType.OccurrenceFrequency, true);

            for (var i = 0; i < checkboxCount; i++)
            {
                var representedDate = startDate.AddDays(isDaily ? i : (i * DaysPerWeek));

                cblCheckboxes.Items.Add(new ListItem
                {
                    Enabled  = representedDate >= minDate && representedDate <= maxDate,
                    Selected = StreakTypeService.IsBitSet(map, streakType.StartDate, representedDate, streakType.OccurrenceFrequency, out errorMessage),
                    Text     = GetLabel(isDaily, representedDate),
                    Value    = representedDate.ToISO8601DateString()
                });
            }

            cblCheckboxes.DataBind();
        }