Bug 484119

Summary: Smart dates in message list still show "today" for messages received yesterday
Product: [Applications] kmail2 Reporter: Thiago Macieira <thiago>
Component: message listAssignee: kdepim bugs <kdepim-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: asturm, axel.braun, kde, vkrause
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 24.08.3
Sentry Crash Report:
Attachments: Screenshot showing the problem
Problem in KMail 6.1.2

Description Thiago Macieira 2024-03-21 01:53:29 UTC
SUMMARY
The smart dates for the message listing appears to be stuck on the day that KMail was launched. So it will display "today" for any message received on that day, but will not update it when the day changes.

STEPS TO REPRODUCE
1. Open KMail
2. Wait for midnight
3. Find a message received before midnight

OBSERVED RESULT
It displays "today"

EXPECTED RESULT
It should display "yesterday"

SOFTWARE/OS VERSIONS
KDE Plasma Version: 6.0.2
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2

ADDITIONAL INFORMATION
Same as #178035, but that was fixed 16 years ago. The problem has reoccurred.
Comment 1 Thiago Macieira 2024-03-21 01:53:59 UTC
Created attachment 167535 [details]
Screenshot showing the problem
Comment 2 Thiago Macieira 2024-06-17 15:43:19 UTC
Still happening as of KMail 6.1.0.
Comment 3 Thiago Macieira 2024-07-22 14:05:47 UTC
Created attachment 171892 [details]
Problem in KMail 6.1.2
Comment 4 Christoph Erhardt 2024-10-04 06:09:14 UTC
*** Bug 484805 has been marked as a duplicate of this bug. ***
Comment 5 Christoph Erhardt 2024-10-04 20:32:05 UTC
I'm not familiar with the KDE PIM code base, but after digging into it I might have a lead.

`MessageList::Core::Manager` - which has singleton characteristics - holds a `MessageCore::DateFormatter` object in a member variable named `mDateFormatter`: https://invent.kde.org/pim/messagelib/-/blob/46b22c6d85a63ae70f6822078b4846ec548d70cc/messagelist/src/core/manager.cpp#L33

`MessageCore::DateFormatterPrivate` has a member variable named `mTodayOneSecondBeforeMidnight`, which holds the reference time point for 'today' (and, by extension, for 'yesterday'). That variable is initialised lazily exactly once: https://invent.kde.org/pim/messagelib/-/blob/46b22c6d85a63ae70f6822078b4846ec548d70cc/messagecore/src/utils/dateformatter.cpp#L161

So, in summary, we have a singleton object holding a long-lived date-formatter object containing a reference time point that never gets updated over the lifetime of the application.
Comment 6 Christoph Erhardt 2024-10-04 21:18:14 UTC
Draft fix, currently untested: https://invent.kde.org/pim/messagelib/-/merge_requests/246
Comment 7 Bug Janitor Service 2024-10-09 16:18:28 UTC
A possibly relevant merge request was started @ https://invent.kde.org/pim/messagelib/-/merge_requests/247