| 1029 | } |
| 1030 | |
| 1031 | ImPlotTime AddTime(const ImPlotTime& t, ImPlotTimeUnit unit, int count) { |
| 1032 | tm& Tm = GImPlot->Tm; |
| 1033 | ImPlotTime t_out = t; |
| 1034 | switch(unit) { |
| 1035 | case ImPlotTimeUnit_Us: t_out.Us += count; break; |
| 1036 | case ImPlotTimeUnit_Ms: t_out.Us += count * 1000; break; |
| 1037 | case ImPlotTimeUnit_S: t_out.S += count; break; |
| 1038 | case ImPlotTimeUnit_Min: t_out.S += count * 60; break; |
| 1039 | case ImPlotTimeUnit_Hr: t_out.S += count * 3600; break; |
| 1040 | case ImPlotTimeUnit_Day: t_out.S += count * 86400; break; |
| 1041 | case ImPlotTimeUnit_Mo: for (int i = 0; i < abs(count); ++i) { |
| 1042 | GetTime(t_out, &Tm); |
| 1043 | if (count > 0) |
| 1044 | t_out.S += 86400 * GetDaysInMonth(Tm.tm_year + 1900, Tm.tm_mon); |
| 1045 | else if (count < 0) |
| 1046 | t_out.S -= 86400 * GetDaysInMonth(Tm.tm_year + 1900 - (Tm.tm_mon == 0 ? 1 : 0), Tm.tm_mon == 0 ? 11 : Tm.tm_mon - 1); // NOT WORKING |
| 1047 | } |
| 1048 | break; |
| 1049 | case ImPlotTimeUnit_Yr: for (int i = 0; i < abs(count); ++i) { |
| 1050 | if (count > 0) |
| 1051 | t_out.S += 86400 * (365 + (int)IsLeapYear(GetYear(t_out))); |
| 1052 | else if (count < 0) |
| 1053 | t_out.S -= 86400 * (365 + (int)IsLeapYear(GetYear(t_out) - 1)); |
| 1054 | // this is incorrect if leap year and we are past Feb 28 |
| 1055 | } |
| 1056 | break; |
| 1057 | default: break; |
| 1058 | } |
| 1059 | t_out.RollOver(); |
| 1060 | return t_out; |
| 1061 | } |
| 1062 | |
| 1063 | ImPlotTime FloorTime(const ImPlotTime& t, ImPlotTimeUnit unit) { |
| 1064 | ImPlotContext& gp = *GImPlot; |
no test coverage detected