Beispiel #1
0
        public void IsBitSetIsCorrectForDailyMap()
        {
            // Day Offset             3210 9876     5432 1098     7654 3210
            var map          = new byte[] { 0b_1000_0000, 0b_0010_0000, 0b_0000_0100 };
            var mapStartDate = new DateTime(2019, 1, 1);

            for (var dayOffset = -5; dayOffset < 100; dayOffset++)
            {
                var date  = mapStartDate.AddDays(dayOffset);
                var isSet = StreakTypeService.IsBitSet(map, mapStartDate, date, StreakOccurrenceFrequency.Daily, out var errorMessage);

                if (dayOffset < 0)
                {
                    // Should get error about checking a bit that is pre-start-date
                    Assert.NotEmpty(errorMessage);
                }
                else
                {
                    Assert.Empty(errorMessage);

                    // The day of the month is the offset + 1 since offset 0 is Jan 1, 2019
                    if (date.Year == 2019 && date.Month == 1 && (date.Day == 3 || date.Day == 14 || date.Day == 24))
                    {
                        Assert.True(isSet);
                    }
                    else
                    {
                        Assert.False(isSet);
                    }
                }
            }
        }
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();
        }