Skip to content

Commit 319a234

Browse files
authored
Merge pull request #2398 from jamescowens/fix_backupwallet
Fix breakage introduced by use of FormatISO8601DateTime
2 parents 088e0f3 + 3bdec99 commit 319a234

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/gridcoin/backup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ std::string GRC::GetBackupFilename(const std::string& basename, const std::strin
2525
{
2626
std::string sBackupFilename;
2727
fs::path rpath;
28-
sBackupFilename = basename + "-" + std::string(FormatISO8601DateTime(GetTime()));
28+
sBackupFilename = basename + "-" + std::string(FormatISO8601DateTimeDashSep(GetTime()));
2929
if (!suffix.empty())
3030
sBackupFilename = sBackupFilename + "-" + suffix;
3131
rpath = GetBackupPath() / sBackupFilename;

src/util/time.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ std::string FormatISO8601DateTime(int64_t nTime) {
151151
return strprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
152152
}
153153

154+
std::string FormatISO8601DateTimeDashSep(int64_t nTime) {
155+
struct tm ts;
156+
time_t time_val = nTime;
157+
#ifdef HAVE_GMTIME_R
158+
if (gmtime_r(&time_val, &ts) == nullptr) {
159+
#else
160+
if (gmtime_s(&ts, &time_val) != 0) {
161+
#endif
162+
return {};
163+
}
164+
return strprintf("%04i-%02i-%02iT%02i-%02i-%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
165+
}
166+
154167
std::string FormatISO8601Date(int64_t nTime) {
155168
struct tm ts;
156169
time_t time_val = nTime;

src/util/time.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ T GetTime();
9090
* helper functions if possible.
9191
*/
9292
std::string FormatISO8601DateTime(int64_t nTime);
93+
std::string FormatISO8601DateTimeDashSep(int64_t nTime);
9394
std::string FormatISO8601Date(int64_t nTime);
9495
int64_t ParseISO8601DateTime(const std::string& str);
9596

0 commit comments

Comments
 (0)