From 7ec8f1c52c0f1fb0d214a8d6695d263758e592b5 Mon Sep 17 00:00:00 2001 From: shrddr Date: Sat, 11 May 2024 14:20:57 +0300 Subject: [PATCH 1/2] handle possible DST change within FloorTime() --- implot.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/implot.cpp b/implot.cpp index 597b043b..f120bd60 100644 --- a/implot.cpp +++ b/implot.cpp @@ -1036,6 +1036,7 @@ ImPlotTime FloorTime(const ImPlotTime& t, ImPlotTimeUnit unit) { case ImPlotTimeUnit_Min: gp.Tm.tm_sec = 0; break; default: return t; } + if (unit >= ImPlotTimeUnit_Day) gp.Tm.tm_isdst = -1; return MkTime(&gp.Tm); } From 13d27464df085bbc6ff58b8f8955e2cf404e4cba Mon Sep 17 00:00:00 2001 From: shrddr Date: Sat, 11 May 2024 20:57:50 +0300 Subject: [PATCH 2/2] =?UTF-8?q?adjust=20major=20time=20ticks=20=C2=B11=20h?= =?UTF-8?q?our=20on=20DST=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- implot.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/implot.cpp b/implot.cpp index f120bd60..217a454d 100644 --- a/implot.cpp +++ b/implot.cpp @@ -1254,9 +1254,20 @@ void Locator_Time(ImPlotTicker& ticker, const ImPlotRange& range, float pixels, const int step = GetTimeStep(minor_per_major, unit0); // generate ticks ImPlotTime t1 = FloorTime(ImPlotTime::FromDouble(range.Min), unit1); + ImPlotContext& gp = *GImPlot; + GetTime(t1, &gp.Tm); + int prev_major_is_dst = gp.Tm.tm_isdst; while (t1 < t_max) { // get next major - const ImPlotTime t2 = AddTime(t1, unit1, 1); + ImPlotTime t2 = AddTime(t1, unit1, 1); + if (GetStyle().UseLocalTime && (unit1 == ImPlotTimeUnit_Day || unit1 == ImPlotTimeUnit_Mo)) { + GetTime(t2, &gp.Tm); + if (prev_major_is_dst == 0 && gp.Tm.tm_isdst == 1) // local clock adjusted ahead, current day/month is shorter + t2 = AddTime(t2, ImPlotTimeUnit_Hr, -1); + if (prev_major_is_dst == 1 && gp.Tm.tm_isdst == 0) // local clock adjusted back, current day/month is longer + t2 = AddTime(t2, ImPlotTimeUnit_Hr, 1); + prev_major_is_dst = gp.Tm.tm_isdst; + } // add major tick if (t1 >= t_min && t1 <= t_max) { // minor level 0 tick