Skip to content

Commit

Permalink
chore: calculation logic update
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir Dahal committed Nov 9, 2024
1 parent 64b74f6 commit 5e472ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions SambatWidget.Core/BaseCalendarRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,24 @@ private List<WidgetCalendarCellModel> Populate()

bool isCurrentMonth = _carouselNepDate.Month == NepaliDate.Now.Month && _carouselNepDate.Year == NepaliDate.Now.Year;
int monthStartDayIndex = (int)GetThisMonthNepaliStartDate().DayOfWeek;
int totalDaysInMonth = _carouselNepDate.MonthEndDay;
int totalDaysInPrevMonth = _carouselNepDate.AddMonths(-1).MonthEndDay;
int totalDaysInCurrMonth = _carouselNepDate.MonthEndDay;

// Total cells (42) minus the current month's days and starting offset gives the remaining cells for the end
int trailingDaysCount = 42 - (totalDaysInMonth + monthStartDayIndex);
int trailingDaysCount = 42 - (totalDaysInCurrMonth + monthStartDayIndex);

int currentCellIndex = 0; // To keep track of the current cell position in the calendar grid

// Add trailing days from the previous month
for (int i = 0; i < monthStartDayIndex; i++, currentCellIndex++)
{
_calendarData.Add(new WidgetCalendarCellModel()
.FadeOutCurrentDay((totalDaysInMonth - monthStartDayIndex) + i + 1)
.FadeOutCurrentDay((totalDaysInPrevMonth - monthStartDayIndex) + i + 1)
.SetGridPosition(currentCellIndex));
}

// Add the current month's days
for (int day = 1; day <= totalDaysInMonth; day++, currentCellIndex++)
for (int day = 1; day <= totalDaysInCurrMonth; day++, currentCellIndex++)
{
string yearMonthKey = GetYearMonthKey(day);
_calendarData.Add(new WidgetCalendarCellModel
Expand Down
2 changes: 1 addition & 1 deletion SambatWidget.UI/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:local="clr-namespace:SambatWidget.UI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:SambatWidget.UI.ViewModels"
Title="Settings v1.1.4 (Preview)"
Title="Settings v1.1.5"
Width="400"
Height="450"
Background="{DynamicResource BackgroundColor}"
Expand Down

0 comments on commit 5e472ce

Please sign in to comment.