MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / FormatTime

Function FormatTime

Source/3rdParty/implot/implot.cpp:1113–1151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1111static const char* MONTH_ABRVS[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
1112
1113int FormatTime(const ImPlotTime& t, char* buffer, int size, ImPlotTimeFmt fmt, bool use_24_hr_clk) {
1114 tm& Tm = GImPlot->Tm;
1115 GetTime(t, &Tm);
1116 const int us = t.Us % 1000;
1117 const int ms = t.Us / 1000;
1118 const int sec = Tm.tm_sec;
1119 const int min = Tm.tm_min;
1120 if (use_24_hr_clk) {
1121 const int hr = Tm.tm_hour;
1122 switch(fmt) {
1123 case ImPlotTimeFmt_Us: return ImFormatString(buffer, size, ".%03d %03d", ms, us);
1124 case ImPlotTimeFmt_SUs: return ImFormatString(buffer, size, ":%02d.%03d %03d", sec, ms, us);
1125 case ImPlotTimeFmt_SMs: return ImFormatString(buffer, size, ":%02d.%03d", sec, ms);
1126 case ImPlotTimeFmt_S: return ImFormatString(buffer, size, ":%02d", sec);
1127 case ImPlotTimeFmt_MinSMs: return ImFormatString(buffer, size, ":%02d:%02d.%03d", min, sec, ms);
1128 case ImPlotTimeFmt_HrMinSMs: return ImFormatString(buffer, size, "%02d:%02d:%02d.%03d", hr, min, sec, ms);
1129 case ImPlotTimeFmt_HrMinS: return ImFormatString(buffer, size, "%02d:%02d:%02d", hr, min, sec);
1130 case ImPlotTimeFmt_HrMin: return ImFormatString(buffer, size, "%02d:%02d", hr, min);
1131 case ImPlotTimeFmt_Hr: return ImFormatString(buffer, size, "%02d:00", hr);
1132 default: return 0;
1133 }
1134 }
1135 else {
1136 const char* ap = Tm.tm_hour < 12 ? "am" : "pm";
1137 const int hr = (Tm.tm_hour == 0 || Tm.tm_hour == 12) ? 12 : Tm.tm_hour % 12;
1138 switch(fmt) {
1139 case ImPlotTimeFmt_Us: return ImFormatString(buffer, size, ".%03d %03d", ms, us);
1140 case ImPlotTimeFmt_SUs: return ImFormatString(buffer, size, ":%02d.%03d %03d", sec, ms, us);
1141 case ImPlotTimeFmt_SMs: return ImFormatString(buffer, size, ":%02d.%03d", sec, ms);
1142 case ImPlotTimeFmt_S: return ImFormatString(buffer, size, ":%02d", sec);
1143 case ImPlotTimeFmt_MinSMs: return ImFormatString(buffer, size, ":%02d:%02d.%03d", min, sec, ms);
1144 case ImPlotTimeFmt_HrMinSMs: return ImFormatString(buffer, size, "%d:%02d:%02d.%03d%s", hr, min, sec, ms, ap);
1145 case ImPlotTimeFmt_HrMinS: return ImFormatString(buffer, size, "%d:%02d:%02d%s", hr, min, sec, ap);
1146 case ImPlotTimeFmt_HrMin: return ImFormatString(buffer, size, "%d:%02d%s", hr, min, ap);
1147 case ImPlotTimeFmt_Hr: return ImFormatString(buffer, size, "%d%s", hr, ap);
1148 default: return 0;
1149 }
1150 }
1151}
1152
1153int FormatDate(const ImPlotTime& t, char* buffer, int size, ImPlotDateFmt fmt, bool use_iso_8601) {
1154 tm& Tm = GImPlot->Tm;

Callers 1

FormatDateTimeFunction · 0.85

Calls 2

ImFormatStringFunction · 0.85
GetTimeFunction · 0.70

Tested by

no test coverage detected