@@ -19,12 +19,14 @@ function generateStreakStats(string $user, array $params = []): array
1919 $ startingYear = isset ($ params ["starting_year " ]) ? intval ($ params ["starting_year " ]) : null ;
2020 $ mode = isset ($ params ["mode " ]) ? strval ($ params ["mode " ]) : null ;
2121 $ excludeDaysRaw = isset ($ params ["exclude_days " ]) ? strval ($ params ["exclude_days " ]) : "" ;
22+ $ timezone = isset ($ params ["timezone " ]) ? strval ($ params ["timezone " ]) : "" ;
2223
2324 // Build cache options based on request parameters
2425 $ cacheOptions = [
2526 "starting_year " => $ startingYear ,
2627 "mode " => $ mode ,
2728 "exclude_days " => $ excludeDaysRaw ,
29+ "timezone " => $ timezone ,
2830 ];
2931
3032 // Check if cache is disabled
@@ -33,13 +35,13 @@ function generateStreakStats(string $user, array $params = []): array
3335 // Check for cached stats first (24 hour cache) unless cache is disabled
3436 $ cachedStats = $ useCache ? getCachedStats ($ user , $ cacheOptions ) : null ;
3537
36- if (!statsMissingOrStale ($ cachedStats )) {
38+ if (!statsMissingOrStale ($ cachedStats, $ timezone )) {
3739 return $ cachedStats ;
3840 }
3941
4042 // Fetch fresh data from GitHub API
4143 $ contributionGraphs = getContributionGraphs ($ user , $ startingYear );
42- $ contributions = getContributionDates ($ contributionGraphs );
44+ $ contributions = getContributionDates ($ contributionGraphs, $ timezone );
4345
4446 if ($ mode === "weekly " ) {
4547 $ stats = getWeeklyContributionStats ($ contributions );
@@ -61,9 +63,10 @@ function generateStreakStats(string $user, array $params = []): array
6163 * Check if cached stats are missing or stale - Streak may be outdated if it ends before today
6264 *
6365 * @param array|null $cachedStats The cached stats to check
66+ * @param string $timezone Timezone identifier, or empty for the server default
6467 * @return bool True if the cached stats are stale and should be refreshed
6568 */
66- function statsMissingOrStale (?array $ cachedStats ): bool
69+ function statsMissingOrStale (?array $ cachedStats, string $ timezone = "" ): bool
6770{
6871 // If there are no cached stats, we need to refresh
6972 if ($ cachedStats === null ) {
@@ -87,9 +90,10 @@ function statsMissingOrStale(?array $cachedStats): bool
8790 $ mode = $ cachedStats ["mode " ] ?? "daily " ;
8891
8992 if ($ mode === "weekly " ) {
90- $ startOfWeek = date ("Y-m-d " , strtotime ("last Sunday " ));
93+ $ today = getCurrentDate ($ timezone );
94+ $ startOfWeek = getPreviousSunday ($ today );
9195 return $ currentStreakEnd < $ startOfWeek ;
9296 } else {
93- return $ currentStreakEnd < date ( " Y-m-d " );
97+ return $ currentStreakEnd < getCurrentDate ( $ timezone );
9498 }
9599}
0 commit comments