MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / FormatTimestamp

Method FormatTimestamp

pcsx2/GameList.cpp:1186–1225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1184}
1185
1186std::string GameList::FormatTimestamp(std::time_t timestamp)
1187{
1188 std::string ret;
1189
1190 if (timestamp == 0)
1191 {
1192 ret = TRANSLATE_STR("GameList", "Never");
1193 }
1194 else
1195 {
1196 struct tm ctime = {};
1197 struct tm ttime = {};
1198 const std::time_t ctimestamp = std::time(nullptr);
1199#ifdef _MSC_VER
1200 localtime_s(&ctime, &ctimestamp);
1201 localtime_s(&ttime, &timestamp);
1202#else
1203 localtime_r(&ctimestamp, &ctime);
1204 localtime_r(&timestamp, &ttime);
1205#endif
1206
1207 if (ctime.tm_year == ttime.tm_year && ctime.tm_yday == ttime.tm_yday)
1208 {
1209 ret = TRANSLATE_STR("GameList", "Today");
1210 }
1211 else if ((ctime.tm_year == ttime.tm_year && ctime.tm_yday == (ttime.tm_yday + 1)) ||
1212 (ctime.tm_yday == 0 && (ctime.tm_year - 1) == ttime.tm_year))
1213 {
1214 ret = TRANSLATE_STR("GameList", "Yesterday");
1215 }
1216 else
1217 {
1218 char buf[128];
1219 std::strftime(buf, std::size(buf), "%x", &ttime);
1220 ret.assign(buf);
1221 }
1222 }
1223
1224 return ret;
1225}
1226
1227std::string GameList::FormatTimespan(const std::time_t timespan, const bool long_format)
1228{

Callers

nothing calls this directly

Calls 2

sizeFunction · 0.50
assignMethod · 0.45

Tested by

no test coverage detected