cachethq / cachet

🚦 The open-source status page system.
https://cachethq.io
MIT License
13.79k stars 1.55k forks source link

Bug in Incidents Display Logic Identified, Have Proposed Fix #4333

Closed crit100 closed 10 months ago

crit100 commented 1 year ago

Today I created an incident, but it would not display. After changing some settings I discovered that it would only display if I set the time the incident occurred to several hours in the past. Eventually, I discovered that if I set it to 7:00 PM or later, it would not show. 6:59 PM or earlier would make it display. I thought this was curious, as my timezone offset is -0500. After digging through the Cachet code for awhile I discovered the issue.

I have my Cachet set to "Only show days containing incidents in the timeline" to yes in the settings. If I turn this off then my incident with a time of after 7:00 PM will display. I looked at the logic in app/Http/Controllers/StatusPageController.php and noticed that it is creating an array called $allIncidentDays, and populating it with the dates incidents occurred. However, it is doing a timezone conversion on these dates. Later, some logic changes the $startDate and $endDate variables' values using information from dates derived from $allIncidentDays. When $allIncidents array gets populated later, it is using an incorrect date range, as the date range will not include the most recent incident day if that incident was created after 23:59:59 minus your timezone offset. In my case, this magic time was 7:00 PM since my offset is -0500.

To fix this issue, I changed a line in $allIncidentDays from this: return app(DateFactory::class)->make($incident->occurred_at)->toDateString(); to this: return $incident->occurred_at->toDateString();

This removes the timezone conversion loss which causes the date range to be set incorrectly. I could explain further, but I'm sure once a developer looks at this logic they will understand how the timezone conversion would later affect the database query to not include the most recent incident under these specific circumstances.

This is my first time looking this deeply at the Cachet code. I am also an amateur programmer (my expertise is in networking), so my change could be inadvertently affecting some other logic which would cause problems. There may also be a more elegant way to address this issue.

Anyway, if any developers would like to test this issue, please enable the setting "Only show days containing incidents in the timeline", set your timezone to a negative offset, subtract that offset from midnight, and create an incident with an occurrence time after that time.

I see there was someone who also seemed to have my same issue, but there was never anyone who was able to offer them a solution. https://github.com/CachetHQ/Cachet/issues/3998

To anyone who has the same issue, please try my recommend edit I proposed above.

Thank you and take care.

welcome[bot] commented 1 year ago

:wave: Thank you for opening your first issue. I'm just an automated bot that's here to help you get the information you need quicker, so please ignore this message if it doesn't apply to your issue. If you're looking for support, you should try the Slack group by registering your email address at https://cachethq-slack.herokuapp.com. Alternatively, email support@alt-three.com for our Professional support service (please note, this a paid service.) If you're issue is with documentation, you can suggest edits by clicking the Suggest Edits link on any page, or open an issue at https://github.com/CachetHQ/Docs

jbrooksuk commented 10 months ago

Thank you for your input on Cachet 2.x. We are shifting our attention and resources to Cachet 3.x and will no longer be supporting the 2.x version. If your feedback or issue is relevant to the 3.x series, we encourage you to engage with the new branch.

For more information on the Cachet rebuild and our plans for 3.x, you can read the announcement here.

We appreciate your understanding and look forward to your contributions to the new version.