STL.natvis: Fixed time_point visualization of year off-by-one by pzychotic · Pull Request #5389 · microsoft/STL (original) (raw)

When the time_point is sometime in February, the debugger visualization of the year will be off-by-one.

You can test this with this little snippet:

#include <chrono>
#include <iostream>

int main()
{
    using namespace std::chrono;

    constexpr year_month_day ymd = 2025y / 2 / 15;
    constexpr system_clock::time_point tp = sys_days{ ymd };
    std::cout << ymd << " | " << tp << std::endl;
}

The console output will be correct:
2025-02-15 | 2025-02-15 00:00:00.0000000

But the debugger shows a year of 2024 for tp:
Screenshot 2025-04-02 210521

As per the referenced calculation used to construct the debugger visualization, the year should be calculated by this formula:
const Int y = static_cast<Int>(yoe) + era * 400; ... (y + (m <= 2)

But the nativs contains this:
<Intrinsic Name="year" Expression="((long long)yoe()) + era() * 400 + (month() &lt; 2)"/>

Missing the = sign in the less-than-or-equal 2 check.