Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ad5d46a

Browse files
committed
Report timezone offset in pg_dump/pg_dumpall
Use consistent format for all such displays. Report by Gavin Flower
1 parent a74a4aa commit ad5d46a

File tree

2 files changed

+8
-29
lines changed

2 files changed

+8
-29
lines changed

src/bin/pg_dump/pg_backup_archiver.c

+6-15
Original file line numberDiff line numberDiff line change
@@ -964,12 +964,15 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
964964
teSection curSection;
965965
OutputContext sav;
966966
const char *fmtName;
967+
struct tm *tm = localtime(&AH->createDate);
968+
char stamp_str[64];
967969

968970
sav = SaveOutput(AH);
969971
if (ropt->filename)
970972
SetOutput(AH, ropt->filename, 0 /* no compression */ );
971973

972-
ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate));
974+
strftime(stamp_str, sizeof(stamp_str), "%Y-%m-%d %H:%M:%S %z", tm);
975+
ahprintf(AH, ";\n; Archive created at %s\n", stamp_str);
973976
ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
974977
AH->archdbname, AH->tocCount, AH->compression);
975978

@@ -3455,21 +3458,9 @@ checkSeek(FILE *fp)
34553458
static void
34563459
dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim)
34573460
{
3458-
char buf[256];
3461+
char buf[64];
34593462

3460-
/*
3461-
* We don't print the timezone on Win32, because the names are long and
3462-
* localized, which means they may contain characters in various random
3463-
* encodings; this has been seen to cause encoding errors when reading the
3464-
* dump script.
3465-
*/
3466-
if (strftime(buf, sizeof(buf),
3467-
#ifndef WIN32
3468-
"%Y-%m-%d %H:%M:%S %Z",
3469-
#else
3470-
"%Y-%m-%d %H:%M:%S",
3471-
#endif
3472-
localtime(&tim)) != 0)
3463+
if (strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z", localtime(&tim)) != 0)
34733464
ahprintf(AH, "-- %s %s\n\n", msg, buf);
34743465
}
34753466

src/bin/pg_dump/pg_dumpall.c

+2-14
Original file line numberDiff line numberDiff line change
@@ -2039,22 +2039,10 @@ executeCommand(PGconn *conn, const char *query)
20392039
static void
20402040
dumpTimestamp(char *msg)
20412041
{
2042-
char buf[256];
2042+
char buf[64];
20432043
time_t now = time(NULL);
20442044

2045-
/*
2046-
* We don't print the timezone on Win32, because the names are long and
2047-
* localized, which means they may contain characters in various random
2048-
* encodings; this has been seen to cause encoding errors when reading the
2049-
* dump script.
2050-
*/
2051-
if (strftime(buf, sizeof(buf),
2052-
#ifndef WIN32
2053-
"%Y-%m-%d %H:%M:%S %Z",
2054-
#else
2055-
"%Y-%m-%d %H:%M:%S",
2056-
#endif
2057-
localtime(&now)) != 0)
2045+
if (strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z", localtime(&now)) != 0)
20582046
fprintf(OPF, "-- %s %s\n\n", msg, buf);
20592047
}
20602048

0 commit comments

Comments
 (0)