Open peterwilson136 opened 3 years ago
It does in fact look like we have a bug when UseLocalTime
is enabled. It's not immediately clear to me why.
However, because this is 1) still somewhat functional, 2) just convenience feature for time series axes context menus, and 3) an internal API function (use at your own risk!), I'm going to hold off on fixing until more impactful work is complete.
In the meantime, please consider investigating the issue and submitting a PR to fix it. I will happily review it.
@epezent I think I found the same issue rooted elsewhere and may help. I am just documenting it on this thread. Using this code,
ImGui::SetNextWindowSize({ 1173,370 });
ImGui::SetNextWindowPos({ 50,100 });
ImGui::Begin("window");
if (ImPlot::BeginPlot("Plot", nullptr, nullptr, {-1, 0}, 0, ImPlotAxisFlags_Time)) {
static double xs[] = { 1610000000, 1620000000, 1630000000, 1640000000, 1650000000 };
static double ys[5] = { 5, 10, 15, 20, 25 };
ImPlot::PlotLine("Test", xs, ys, 5);
ImPlot::EndPlot();
}
ImGui::End();
the times at the bottom begin as the names of the months. Where there's grid lines up from each month, zoom into October slowly, as the names transition to the Month/Day
format, October becomes 11/1
, which is actually November. What's weird is as you test this for months before it, it works fine, but for some reason on October specifically (in an area around it, and the only one I could find so far), it doesn't work. I should also mention that from the get-go, you can see the axis plot has two April
's next to each other at the beginning.
In my locale, 31 Mar 2024 the Daylight Saving Time has started (at 03:00:00 local = 01:00:00 GMT clocks were turned forward 1 hour to 04:00:00 local = 01:00:00 GMT) and since then time axis ticks started behaving differently. Here's a test case to confirm:
ImPlot::GetStyle().UseLocalTime = true;
ImGui::Checkbox("Local Time", &ImPlot::GetStyle().UseLocalTime);
static double t_min = 1711846799; // Mar 31 2024 00:59:59 GMT+0
ImGui::Text("t_min = not yet DST = OK");
if (ImPlot::BeginPlot("##ok", ImVec2(600, 200))) {
ImPlot::SetupAxisScale(ImAxis_X1, ImPlotScale_Time);
ImPlot::SetupAxesLimits(t_min, t_min + 360 * 86400, 0, 1);
ImPlot::EndPlot();
}
t_min += 1; // Mar 31 2024 01:00:00 GMT+0
ImGui::Text("t_min = is DST = bug");
if (ImPlot::BeginPlot("##bug", ImVec2(600, 200))) {
ImPlot::SetupAxisScale(ImAxis_X1, ImPlotScale_Time);
ImPlot::SetupAxesLimits(t_min, t_min + 360 * 86400, 0, 1);
ImPlot::EndPlot();
}
ImGui::End();
You can observe it by dragging time axis left and right on either plot, the January 1 label keeps changing between --01 and --12 when t_min
crosses the DST point.
The cause is:
FloorTime
call in implot.cpp line 1264 returns Jan 01 2024 00:00:00 local (which is expected)FloorTime
returns Dec 31 2023 23:00:00 local because GetTime
at line 1027 populates the ImPlotContext.Tm
structure with tm_isdst = true
which modifies behavior of MkTime
at line 1039So I think an easy fix would be to always clear gp.Tm.tm_isdst
in FloorTime
but not sure how it affects other functionality.
So I think an easy fix would be to always clear gp.Tm.tm_isdst in FloorTime
Uhh it's complex, FloorTime should behave differently depending on unit
argument
unit==year
, in my locale at least the input value will always leave the DST range, not sure about other localesunit==month
, FloorTime may or may not go outside of DST
gp.Tm.tm_isdst = -1;
this forces MakeTime to infer if it is DST or not from other fields
Using the code below, if you click on
June 2021
->Jan
->1
(and make sure you click on the1
), and then you go back toJanuary 2021
->Jun
, it puts the date to31 May, 2021
. You can repeat this forMay, June, July, August, September, October
, and you will see that it only works up tillApril
and afterNovember
.Edit: I think it has to do with
ImPlot_Style.UseLocalTime = true;
, because removing this solves the issue, however in my main program it messes with the time in the plot axis.