On Wed, Sep 3, 2014 at 08:33:31PM -0400, Bruce Momjian wrote: > I can't seem to find a way to get the timezone offset via C; see: > > > http://stackoverflow.com/questions/635780/why-does-glibc-timezone-global-not-agree-with-system-time-on-dst > > On Linux, do 'man timezone' for details. 'timezone' has the non-DST > offset from GMT, and 'daylight' is a boolean which indicates DST, but > not how much time is different for DST, and I am not sure it is always > an hour. In fact 'daylight' is documented as saying whether there is > every a daylight savings time, not that DST is active.
Uh, not sure what I was thinking --- strftime() is the way to go. Here is the new output: ; ; Archive created at 2014-09-04 13:00:15 -0400 <--- ; dbname: test ; TOC Entries: 8 ; Compression: -1 ; Dump Version: 1.12-0 ; Format: CUSTOM ; Integer: 4 bytes ; Offset: 8 bytes ; Dumped from database version: 9.5devel ; Dumped by pg_dump version: 9.5devel I found two other places in our dump code that use strftime with a similar format, but they had problems with the timezone string on Windows, so I switched those over to use a numeric timezone offset as well. Patch attached. -- Bruce Momjian <br...@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. +
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c new file mode 100644 index 0018720..ded9135 *** a/src/bin/pg_dump/pg_backup_archiver.c --- b/src/bin/pg_dump/pg_backup_archiver.c *************** PrintTOCSummary(Archive *AHX, RestoreOpt *** 964,975 **** teSection curSection; OutputContext sav; const char *fmtName; sav = SaveOutput(AH); if (ropt->filename) SetOutput(AH, ropt->filename, 0 /* no compression */ ); ! ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate)); ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n", AH->archdbname, AH->tocCount, AH->compression); --- 964,978 ---- teSection curSection; OutputContext sav; const char *fmtName; + struct tm *tm = localtime(&AH->createDate); + char stamp_str[64]; sav = SaveOutput(AH); if (ropt->filename) SetOutput(AH, ropt->filename, 0 /* no compression */ ); ! strftime(stamp_str, sizeof(stamp_str), "%Y-%m-%d %H:%M:%S %z", tm); ! ahprintf(AH, ";\n; Archive created at %s\n", stamp_str); ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n", AH->archdbname, AH->tocCount, AH->compression); *************** checkSeek(FILE *fp) *** 3455,3475 **** static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim) { ! char buf[256]; ! /* ! * We don't print the timezone on Win32, because the names are long and ! * localized, which means they may contain characters in various random ! * encodings; this has been seen to cause encoding errors when reading the ! * dump script. ! */ ! if (strftime(buf, sizeof(buf), ! #ifndef WIN32 ! "%Y-%m-%d %H:%M:%S %Z", ! #else ! "%Y-%m-%d %H:%M:%S", ! #endif ! localtime(&tim)) != 0) ahprintf(AH, "-- %s %s\n\n", msg, buf); } --- 3458,3466 ---- static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim) { ! char buf[64]; ! if (strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z", localtime(&tim)) != 0) ahprintf(AH, "-- %s %s\n\n", msg, buf); } diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c new file mode 100644 index 4050091..b2b3e6f *** a/src/bin/pg_dump/pg_dumpall.c --- b/src/bin/pg_dump/pg_dumpall.c *************** executeCommand(PGconn *conn, const char *** 2039,2060 **** static void dumpTimestamp(char *msg) { ! char buf[256]; time_t now = time(NULL); ! /* ! * We don't print the timezone on Win32, because the names are long and ! * localized, which means they may contain characters in various random ! * encodings; this has been seen to cause encoding errors when reading the ! * dump script. ! */ ! if (strftime(buf, sizeof(buf), ! #ifndef WIN32 ! "%Y-%m-%d %H:%M:%S %Z", ! #else ! "%Y-%m-%d %H:%M:%S", ! #endif ! localtime(&now)) != 0) fprintf(OPF, "-- %s %s\n\n", msg, buf); } --- 2039,2048 ---- static void dumpTimestamp(char *msg) { ! char buf[64]; time_t now = time(NULL); ! if (strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z", localtime(&now)) != 0) fprintf(OPF, "-- %s %s\n\n", msg, buf); }
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers