Skip to content

Commit b943588

Browse files
ISSUE #1617: Streaks widget not displaying streaks correctly
1 parent 58884b6 commit b943588

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

config/reference.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,17 @@
10981098
* doctrine?: DoctrineConfig,
10991099
* doctrine_migrations?: DoctrineMigrationsConfig,
11001100
* twig?: TwigConfig,
1101+
* "when@dev"?: array{
1102+
* imports?: ImportsConfig,
1103+
* parameters?: ParametersConfig,
1104+
* services?: ServicesConfig,
1105+
* framework?: FrameworkConfig,
1106+
* flysystem?: FlysystemConfig,
1107+
* monolog?: MonologConfig,
1108+
* doctrine?: DoctrineConfig,
1109+
* doctrine_migrations?: DoctrineMigrationsConfig,
1110+
* twig?: TwigConfig,
1111+
* },
11011112
* "when@prod"?: array{
11021113
* imports?: ImportsConfig,
11031114
* parameters?: ParametersConfig,
@@ -1200,6 +1211,7 @@ public static function config(array $config): array
12001211
* deprecated?: array{package:string, version:string, message?:string},
12011212
* }
12021213
* @psalm-type RoutesConfig = array{
1214+
* "when@dev"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
12031215
* "when@prod"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
12041216
* "when@test"?: array<string, RouteConfig|ImportConfig|AliasConfig>,
12051217
* ...<string, RouteConfig|ImportConfig|AliasConfig>

src/Domain/Rewind/FindStreaks/FindStreaksQueryHandler.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ private function computeStreaks(array $days): FindStreaksResponse
8484
$longestMonthStreak = $runningMonthStreak = 1;
8585

8686
$previousDay = array_first($days);
87-
$keepTrackOfCurrentDayStreak = $previousDay->format('Ymd') === $today->format('Ymd');
87+
$keepTrackOfCurrentDayStreak = $today->diff($previousDay)->days < 2;
8888
$currentDayStreak = $keepTrackOfCurrentDayStreak ? 1 : 0;
8989

90-
$keepTrackOfCurrentWeekStreak = $previousDay->modify(self::FIRST_DAY_OF_THE_WEEK)->format('Ymd') === $today->modify(self::FIRST_DAY_OF_THE_WEEK)->format('Ymd');
90+
$keepTrackOfCurrentWeekStreak = $today->diff($previousDay)->days < 7;
9191
$currentWeekStreak = $keepTrackOfCurrentWeekStreak ? 1 : 0;
9292

93-
$keepTrackOfCurrentMonthStreak = $previousDay->modify(self::FIRST_DAY_OF_THE_MONTH)->format('Ymd') === $today->modify(self::FIRST_DAY_OF_THE_MONTH)->format('Ymd');
93+
$monthDiff =
94+
(($today->getYear() - $previousDay->getYear()) * 12)
95+
+ ($today->getMonthWithoutLeadingZero() - $previousDay->getMonthWithoutLeadingZero());
96+
$keepTrackOfCurrentMonthStreak = $monthDiff <= 1;
9497
$currentMonthStreak = $keepTrackOfCurrentMonthStreak ? 1 : 0;
9598

9699
for ($i = 1; $i < count($days); ++$i) {

0 commit comments

Comments
 (0)