@@ -28,8 +28,8 @@ export function calculateStreak(
2828 now : Date = new Date ( ) ,
2929 grace : number = 1
3030) : StreakStats {
31- const weeks = calendar . weeks ;
32- const days = weeks . flatMap ( ( week ) => week . contributionDays ) ;
31+ const weeks = calendar ? .weeks || [ ] ;
32+ const days = weeks . flatMap ( ( week ) => week ? .contributionDays || [ ] ) ;
3333
3434 let currentStreak = 0 ;
3535 let longestStreak = 0 ;
@@ -95,7 +95,8 @@ export function calculateMonthlyStats(
9595 timezone : string = 'UTC' ,
9696 now : Date = new Date ( )
9797) : MonthlyStats {
98- const days = calendar . weeks . flatMap ( ( week ) => week . contributionDays ) ;
98+ const weeks = calendar ?. weeks || [ ] ;
99+ const days = weeks . flatMap ( ( week ) => week ?. contributionDays || [ ] ) ;
99100
100101 const localTodayStr = new Intl . DateTimeFormat ( 'en-CA' , { timeZone : timezone } ) . format ( now ) ;
101102 const [ currentYearStr , currentMonthStr ] = localTodayStr . split ( '-' ) ;
@@ -171,13 +172,13 @@ export function aggregateCalendars(calendars: ContributionCalendar[]): Contribut
171172 // Find the calendar with the most weeks to serve as our structural base
172173 let baseCalendar = calendars [ 0 ] ;
173174 for ( const cal of calendars ) {
174- if ( cal . weeks . length > baseCalendar . weeks . length ) {
175+ if ( ( cal . weeks ? .length || 0 ) > ( baseCalendar . weeks ? .length || 0 ) ) {
175176 baseCalendar = cal ;
176177 }
177178
178179 // Populate the Map with all contributions from all calendars
179- cal . weeks . forEach ( ( week ) => {
180- week . contributionDays . forEach ( ( day ) => {
180+ ( cal . weeks || [ ] ) . forEach ( ( week ) => {
181+ ( week ? .contributionDays || [ ] ) . forEach ( ( day ) => {
181182 const currentCount = dateMap . get ( day . date ) || 0 ;
182183 dateMap . set ( day . date , currentCount + day . contributionCount ) ;
183184 } ) ;
@@ -190,8 +191,8 @@ export function aggregateCalendars(calendars: ContributionCalendar[]): Contribut
190191 aggregatedBase . totalContributions = totalContributions ;
191192
192193 // Re-map the structural base using our aggregated date map
193- aggregatedBase . weeks . forEach ( ( week ) => {
194- week . contributionDays . forEach ( ( day ) => {
194+ ( aggregatedBase . weeks || [ ] ) . forEach ( ( week ) => {
195+ ( week ? .contributionDays || [ ] ) . forEach ( ( day ) => {
195196 day . contributionCount = dateMap . get ( day . date ) || 0 ;
196197 } ) ;
197198 } ) ;
@@ -202,7 +203,8 @@ export function aggregateCalendars(calendars: ContributionCalendar[]): Contribut
202203 * Processes a calendar to generate deep insights for "GitHub Wrapped"
203204 */
204205export function calculateWrappedStats ( calendar : ContributionCalendar ) {
205- const days = calendar . weeks . flatMap ( ( w ) => w . contributionDays ) ;
206+ const weeks = calendar ?. weeks || [ ] ;
207+ const days = weeks . flatMap ( ( w ) => w ?. contributionDays || [ ] ) ;
206208
207209 let mostActiveDay = { date : '' , count : 0 } ;
208210 const monthCounts : Record < string , number > = { } ;
0 commit comments