PostgreSQL Source Code git master
Loading...
Searching...
No Matches
findtimezone.c File Reference
#include "postgres_fe.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include "pgtz.h"
Include dependency graph for findtimezone.c:

Go to the source code of this file.

Data Structures

struct  tztry
 

Macros

#define T_DAY   ((time_t) (60*60*24))
 
#define T_WEEK   ((time_t) (60*60*24*7))
 
#define T_MONTH   ((time_t) (60*60*24*31))
 
#define MAX_TEST_TIMES   (52*100) /* 100 years */
 

Functions

const charselect_default_timezone (const char *share_path)
 
static const charpg_TZDIR (void)
 
int pg_open_tzfile (const char *name, char *canonname)
 
static pg_tzpg_load_tz (const char *name)
 
static bool check_system_link_file (const char *linkname, struct tztry *tt, char *bestzonename)
 
static void scan_available_timezones (char *tzdir, char *tzdirsub, struct tztry *tt, int *bestscore, char *bestzonename)
 
static int get_timezone_offset (struct tm *tm)
 
static time_t build_time_t (int year, int month, int day)
 
static bool compare_tm (struct tm *s, struct pg_tm *p)
 
static int score_timezone (const char *tzname, struct tztry *tt)
 
static bool perfect_timezone_match (const char *tzname, struct tztry *tt)
 
static const charidentify_system_timezone (void)
 
static int zone_name_pref (const char *zonename)
 
static bool validate_zone (const char *tzname)
 

Variables

static char tzdirpath [MAXPGPATH]
 

Macro Definition Documentation

◆ MAX_TEST_TIMES

#define MAX_TEST_TIMES   (52*100) /* 100 years */

Definition at line 143 of file findtimezone.c.

◆ T_DAY

#define T_DAY   ((time_t) (60*60*24))

Definition at line 139 of file findtimezone.c.

◆ T_MONTH

#define T_MONTH   ((time_t) (60*60*24*31))

Definition at line 141 of file findtimezone.c.

◆ T_WEEK

#define T_WEEK   ((time_t) (60*60*24*7))

Definition at line 140 of file findtimezone.c.

Function Documentation

◆ build_time_t()

static time_t build_time_t ( int  year,
int  month,
int  day 
)
static

Definition at line 177 of file findtimezone.c.

178{
179 struct tm tm;
180
181 memset(&tm, 0, sizeof(tm));
182 tm.tm_mday = day;
183 tm.tm_mon = month - 1;
184 tm.tm_year = year - 1900;
185 tm.tm_isdst = -1;
186
187 return mktime(&tm);
188}
static struct pg_tm tm
Definition localtime.c:148
static int fb(int x)
int tm_mday
Definition pgtime.h:39
int tm_mon
Definition pgtime.h:40
int tm_isdst
Definition pgtime.h:44
int tm_year
Definition pgtime.h:41

References fb(), tm, pg_tm::tm_isdst, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by identify_system_timezone().

◆ check_system_link_file()

static bool check_system_link_file ( const char linkname,
struct tztry tt,
char bestzonename 
)
static

Definition at line 531 of file findtimezone.c.

533{
534#ifdef HAVE_READLINK
536 ssize_t len;
537 const char *cur_name;
538
539 /*
540 * Try to read the symlink. If not there, not a symlink, etc etc, just
541 * quietly fail; the precise reason needn't concern us.
542 */
544 if (len < 0 || len >= sizeof(link_target))
545 return false;
546 link_target[len] = '\0';
547
548#ifdef DEBUG_IDENTIFY_TIMEZONE
549 fprintf(stderr, "symbolic link \"%s\" contains \"%s\"\n",
551#endif
552
553 /*
554 * The symlink is probably of the form "/path/to/zones/zone/name", or
555 * possibly it is a relative path. Nobody puts their zone DB directly in
556 * the root directory, so we can definitely skip the first component; but
557 * after that it's trial-and-error to identify which path component begins
558 * the zone name.
559 */
561 while (*cur_name)
562 {
563 /* Advance to next segment of path */
564 cur_name = strchr(cur_name + 1, '/');
565 if (cur_name == NULL)
566 break;
567 /* If there are consecutive slashes, skip all, as the kernel would */
568 do
569 {
570 cur_name++;
571 } while (*cur_name == '/');
572
573 /*
574 * Test remainder of path to see if it is a matching zone name.
575 * Relative paths might contain ".."; we needn't bother testing if the
576 * first component is that. Also defend against overlength names.
577 */
578 if (*cur_name && *cur_name != '.' &&
581 {
582 /* Success! */
584 return true;
585 }
586 }
587
588 /* Couldn't extract a matching zone name */
589 return false;
590#else
591 /* No symlinks? Forget it */
592 return false;
593#endif
594}
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
static bool perfect_timezone_match(const char *tzname, struct tztry *tt)
#define MAXPGPATH
const void size_t len
#define TZ_STRLEN_MAX
Definition pgtime.h:54
#define readlink(path, buf, size)
Definition win32_port.h:243

References fb(), fprintf, len, MAXPGPATH, perfect_timezone_match(), readlink, and TZ_STRLEN_MAX.

Referenced by identify_system_timezone().

◆ compare_tm()

static bool compare_tm ( struct tm s,
struct pg_tm p 
)
static

Definition at line 194 of file findtimezone.c.

195{
196 if (s->tm_sec != p->tm_sec ||
197 s->tm_min != p->tm_min ||
198 s->tm_hour != p->tm_hour ||
199 s->tm_mday != p->tm_mday ||
200 s->tm_mon != p->tm_mon ||
201 s->tm_year != p->tm_year ||
202 s->tm_wday != p->tm_wday ||
203 s->tm_yday != p->tm_yday ||
204 s->tm_isdst != p->tm_isdst)
205 return false;
206 return true;
207}
int tm_hour
Definition pgtime.h:38
int tm_min
Definition pgtime.h:37
int tm_yday
Definition pgtime.h:43
int tm_wday
Definition pgtime.h:42
int tm_sec
Definition pgtime.h:36

References pg_tm::tm_hour, pg_tm::tm_isdst, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_wday, pg_tm::tm_yday, and pg_tm::tm_year.

Referenced by score_timezone().

◆ get_timezone_offset()

static int get_timezone_offset ( struct tm tm)
static

Definition at line 162 of file findtimezone.c.

163{
164#if defined(HAVE_STRUCT_TM_TM_ZONE)
165 return tm->tm_gmtoff;
166#elif defined(HAVE_INT_TIMEZONE)
167 return -TIMEZONE_GLOBAL;
168#else
169#error No way to determine TZ? Can this happen?
170#endif
171}
#define TIMEZONE_GLOBAL
Definition port.h:291
long int tm_gmtoff
Definition pgtime.h:45

References TIMEZONE_GLOBAL, tm, and pg_tm::tm_gmtoff.

Referenced by identify_system_timezone().

◆ identify_system_timezone()

static const char * identify_system_timezone ( void  )
static

Definition at line 318 of file findtimezone.c.

319{
320 static char resultbuf[TZ_STRLEN_MAX + 1];
321 time_t tnow;
322 time_t t;
323 struct tztry tt;
324 struct tm *tm;
325 int thisyear;
326 int bestscore;
327 char tmptzdir[MAXPGPATH];
328 int std_ofs;
331 char cbuf[TZ_STRLEN_MAX + 1];
332
333 /* Initialize OS timezone library */
334 tzset();
335
336 /*
337 * Set up the list of dates to be probed to see how well our timezone
338 * matches the system zone. We first probe January and July of the
339 * current year; this serves to quickly eliminate the vast majority of the
340 * TZ database entries. If those dates match, we probe every week for 100
341 * years backwards from the current July. (Weekly resolution is good
342 * enough to identify DST transition rules, since everybody switches on
343 * Sundays.) This is sufficient to cover most of the Unix time_t range,
344 * and we don't want to look further than that since many systems won't
345 * have sane TZ behavior further back anyway. The further back the zone
346 * matches, the better we score it. This may seem like a rather random
347 * way of doing things, but experience has shown that system-supplied
348 * timezone definitions are likely to have DST behavior that is right for
349 * the recent past and not so accurate further back. Scoring in this way
350 * allows us to recognize zones that have some commonality with the IANA
351 * database, without insisting on exact match. (Note: we probe Thursdays,
352 * not Sundays, to avoid triggering DST-transition bugs in localtime
353 * itself.)
354 */
355 tnow = time(NULL);
356 tm = localtime(&tnow);
357 if (!tm)
358 return NULL; /* give up if localtime is broken... */
359 thisyear = tm->tm_year + 1900;
360
361 t = build_time_t(thisyear, 1, 15);
362
363 /*
364 * Round back to GMT midnight Thursday. This depends on the knowledge
365 * that the time_t origin is Thu Jan 01 1970. (With a different origin
366 * we'd be probing some other day of the week, but it wouldn't matter
367 * anyway unless localtime() had DST-transition bugs.)
368 */
369 t -= (t % T_WEEK);
370
371 tt.n_test_times = 0;
372 tt.test_times[tt.n_test_times++] = t;
373
374 t = build_time_t(thisyear, 7, 15);
375 t -= (t % T_WEEK);
376
377 tt.test_times[tt.n_test_times++] = t;
378
379 while (tt.n_test_times < MAX_TEST_TIMES)
380 {
381 t -= T_WEEK;
382 tt.test_times[tt.n_test_times++] = t;
383 }
384
385 /*
386 * Try to avoid the brute-force search by seeing if we can recognize the
387 * system's timezone setting directly.
388 *
389 * Currently we just check /etc/localtime; there are other conventions for
390 * this, but that seems to be the only one used on enough platforms to be
391 * worth troubling over.
392 */
393 if (check_system_link_file("/etc/localtime", &tt, resultbuf))
394 return resultbuf;
395
396 /* No luck, so search for the best-matching timezone file */
397 strlcpy(tmptzdir, pg_TZDIR(), sizeof(tmptzdir));
398 bestscore = -1;
399 resultbuf[0] = '\0';
401 &tt,
403 if (bestscore > 0)
404 {
405 /* Ignore IANA's rather silly "Factory" zone; use GMT instead */
406 if (strcmp(resultbuf, "Factory") == 0)
407 return NULL;
408 return resultbuf;
409 }
410
411 /*
412 * Couldn't find a match in the database, so next we try constructed zone
413 * names (like "PST8PDT").
414 *
415 * First we need to determine the names of the local standard and daylight
416 * zones. The idea here is to scan forward from today until we have seen
417 * both zones, if both are in use.
418 */
421 std_ofs = 0;
422
423 tnow = time(NULL);
424
425 /*
426 * Round back to a GMT midnight so results don't depend on local time of
427 * day
428 */
429 tnow -= (tnow % T_DAY);
430
431 /*
432 * We have to look a little further ahead than one year, in case today is
433 * just past a DST boundary that falls earlier in the year than the next
434 * similar boundary. Arbitrarily scan up to 14 months.
435 */
436 for (t = tnow; t <= tnow + T_MONTH * 14; t += T_MONTH)
437 {
438 tm = localtime(&t);
439 if (!tm)
440 continue;
441 if (tm->tm_isdst < 0)
442 continue;
443 if (tm->tm_isdst == 0 && std_zone_name[0] == '\0')
444 {
445 /* found STD zone */
446 memset(cbuf, 0, sizeof(cbuf));
447 strftime(cbuf, sizeof(cbuf) - 1, "%Z", tm); /* zone abbr */
450 }
451 if (tm->tm_isdst > 0 && dst_zone_name[0] == '\0')
452 {
453 /* found DST zone */
454 memset(cbuf, 0, sizeof(cbuf));
455 strftime(cbuf, sizeof(cbuf) - 1, "%Z", tm); /* zone abbr */
457 }
458 /* Done if found both */
459 if (std_zone_name[0] && dst_zone_name[0])
460 break;
461 }
462
463 /* We should have found a STD zone name by now... */
464 if (std_zone_name[0] == '\0')
465 {
466#ifdef DEBUG_IDENTIFY_TIMEZONE
467 fprintf(stderr, "could not determine system time zone\n");
468#endif
469 return NULL; /* go to GMT */
470 }
471
472 /* If we found DST then try STD<ofs>DST */
473 if (dst_zone_name[0] != '\0')
474 {
475 snprintf(resultbuf, sizeof(resultbuf), "%s%d%s",
477 if (score_timezone(resultbuf, &tt) > 0)
478 return resultbuf;
479 }
480
481 /* Try just the STD timezone (works for GMT at least) */
483 if (score_timezone(resultbuf, &tt) > 0)
484 return resultbuf;
485
486 /* Try STD<ofs> */
487 snprintf(resultbuf, sizeof(resultbuf), "%s%d",
488 std_zone_name, -std_ofs / 3600);
489 if (score_timezone(resultbuf, &tt) > 0)
490 return resultbuf;
491
492 /*
493 * Did not find the timezone. Fallback to use a GMT zone. Note that the
494 * IANA timezone database names the GMT-offset zones in POSIX style: plus
495 * is west of Greenwich. It's unfortunate that this is opposite of SQL
496 * conventions. Should we therefore change the names? Probably not...
497 */
498 snprintf(resultbuf, sizeof(resultbuf), "Etc/GMT%s%d",
499 (-std_ofs > 0) ? "+" : "", -std_ofs / 3600);
500
501#ifdef DEBUG_IDENTIFY_TIMEZONE
502 fprintf(stderr, "could not recognize system time zone, using \"%s\"\n",
503 resultbuf);
504#endif
505 return resultbuf;
506}
static void scan_available_timezones(char *tzdir, char *tzdirsub, struct tztry *tt, int *bestscore, char *bestzonename)
#define T_DAY
static const char * pg_TZDIR(void)
#define T_MONTH
static time_t build_time_t(int year, int month, int day)
#define T_WEEK
static int get_timezone_offset(struct tm *tm)
static int score_timezone(const char *tzname, struct tztry *tt)
static bool check_system_link_file(const char *linkname, struct tztry *tt, char *bestzonename)
#define MAX_TEST_TIMES
#define snprintf
Definition port.h:261
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45

References build_time_t(), check_system_link_file(), fb(), fprintf, get_timezone_offset(), MAX_TEST_TIMES, MAXPGPATH, pg_TZDIR(), scan_available_timezones(), score_timezone(), snprintf, strlcpy(), T_DAY, T_MONTH, T_WEEK, tm, pg_tm::tm_isdst, pg_tm::tm_year, and TZ_STRLEN_MAX.

Referenced by select_default_timezone().

◆ perfect_timezone_match()

static bool perfect_timezone_match ( const char tzname,
struct tztry tt 
)
static

Definition at line 307 of file findtimezone.c.

308{
309 return (score_timezone(tzname, tt) == tt->n_test_times);
310}

References fb(), and score_timezone().

Referenced by check_system_link_file().

◆ pg_load_tz()

static pg_tz * pg_load_tz ( const char name)
static

Definition at line 91 of file findtimezone.c.

92{
93 static pg_tz tz;
94
96 return NULL; /* not going to fit */
97
98 /*
99 * Let the IANA tzdb code interpret the time zone name.
100 */
101 if (!pg_tzload(name, NULL, &tz.state))
102 return NULL; /* unknown timezone */
103
104 strcpy(tz.TZname, name);
105
106 return &tz;
107}
bool pg_tzload(const char *name, char *canonname, struct state *sp)
Definition localtime.c:1590
Definition pgtz.h:105
char TZname[TZ_STRLEN_MAX+1]
Definition pgtz.h:107
struct state state
Definition pgtz.h:108
const char * name

References fb(), name, pg_tzload(), pg_tz::state, TZ_STRLEN_MAX, and pg_tz::TZname.

Referenced by score_timezone(), and validate_zone().

◆ pg_open_tzfile()

int pg_open_tzfile ( const char name,
char canonname 
)

Definition at line 65 of file findtimezone.c.

66{
67 char fullname[MAXPGPATH];
68
69 if (canonname)
71
72 strlcpy(fullname, pg_TZDIR(), sizeof(fullname));
73 if (strlen(fullname) + 1 + strlen(name) >= MAXPGPATH)
74 return -1; /* not gonna fit */
75 strcat(fullname, "/");
77
78 return open(fullname, O_RDONLY | PG_BINARY, 0);
79}
#define PG_BINARY
Definition c.h:1431

References fb(), MAXPGPATH, name, PG_BINARY, pg_TZDIR(), strlcpy(), and TZ_STRLEN_MAX.

Referenced by tzloadbody().

◆ pg_TZDIR()

static const char * pg_TZDIR ( void  )
static

Definition at line 37 of file findtimezone.c.

38{
39#ifndef SYSTEMTZDIR
40 /* normal case: timezone stuff is under our share dir */
41 return tzdirpath;
42#else
43 /* we're configured to use system's timezone database */
44 return SYSTEMTZDIR;
45#endif
46}
static char tzdirpath[MAXPGPATH]

References fb(), and tzdirpath.

Referenced by identify_system_timezone(), and pg_open_tzfile().

◆ scan_available_timezones()

static void scan_available_timezones ( char tzdir,
char tzdirsub,
struct tztry tt,
int bestscore,
char bestzonename 
)
static

Definition at line 644 of file findtimezone.c.

646{
648 char **names;
649 char **namep;
650
651 names = pgfnames(tzdir);
652 if (!names)
653 return;
654
655 for (namep = names; *namep; namep++)
656 {
657 char *name = *namep;
658 struct stat statbuf;
659
660 /* Ignore . and .., plus any other "hidden" files */
661 if (name[0] == '.')
662 continue;
663
665 "/%s", name);
666
667 if (stat(tzdir, &statbuf) != 0)
668 {
669#ifdef DEBUG_IDENTIFY_TIMEZONE
670 fprintf(stderr, "could not stat \"%s\": %m\n",
671 tzdir);
672#endif
673 tzdir[tzdir_orig_len] = '\0';
674 continue;
675 }
676
677 if (S_ISDIR(statbuf.st_mode))
678 {
679 /* Recurse into subdirectory */
682 }
683 else
684 {
685 /* Load and test this file */
686 int score = score_timezone(tzdirsub, tt);
687
688 if (score > *bestscore)
689 {
690 *bestscore = score;
692 }
693 else if (score == *bestscore)
694 {
695 /* Consider how to break a tie */
698
699 if (namepref > 0 ||
700 (namepref == 0 &&
705 }
706 }
707
708 /* Restore tzdir */
709 tzdir[tzdir_orig_len] = '\0';
710 }
711
712 pgfnames_cleanup(names);
713}
static int zone_name_pref(const char *zonename)
void pgfnames_cleanup(char **filenames)
Definition pgfnames.c:85
char ** pgfnames(const char *path)
Definition pgfnames.c:37
#define stat
Definition win32_port.h:74
#define S_ISDIR(m)
Definition win32_port.h:332

References fb(), fprintf, MAXPGPATH, name, pgfnames(), pgfnames_cleanup(), S_ISDIR, scan_available_timezones(), score_timezone(), snprintf, stat, strlcpy(), TZ_STRLEN_MAX, and zone_name_pref().

Referenced by identify_system_timezone(), and scan_available_timezones().

◆ score_timezone()

static int score_timezone ( const char tzname,
struct tztry tt 
)
static

Definition at line 221 of file findtimezone.c.

222{
223 int i;
225 struct tm *systm;
226 struct pg_tm *pgtm;
227 char cbuf[TZ_STRLEN_MAX + 1];
228 pg_tz *tz;
229
230 /* Load timezone definition */
231 tz = pg_load_tz(tzname);
232 if (!tz)
233 return -1; /* unrecognized zone name */
234
235 /* Reject if leap seconds involved */
236 if (!pg_tz_acceptable(tz))
237 {
238#ifdef DEBUG_IDENTIFY_TIMEZONE
239 fprintf(stderr, "Reject TZ \"%s\": uses leap seconds\n", tzname);
240#endif
241 return -1;
242 }
243
244 /* Check for match at all the test times */
245 for (i = 0; i < tt->n_test_times; i++)
246 {
247 pgtt = (pg_time_t) (tt->test_times[i]);
248 pgtm = pg_localtime(&pgtt, tz);
249 if (!pgtm)
250 return -1; /* probably shouldn't happen */
251 systm = localtime(&(tt->test_times[i]));
252 if (!systm)
253 {
254#ifdef DEBUG_IDENTIFY_TIMEZONE
255 fprintf(stderr, "TZ \"%s\" scores %d: at %ld %04d-%02d-%02d %02d:%02d:%02d %s, system had no data\n",
256 tzname, i, (long) pgtt,
257 pgtm->tm_year + 1900, pgtm->tm_mon + 1, pgtm->tm_mday,
258 pgtm->tm_hour, pgtm->tm_min, pgtm->tm_sec,
259 pgtm->tm_isdst ? "dst" : "std");
260#endif
261 return i;
262 }
263 if (!compare_tm(systm, pgtm))
264 {
265#ifdef DEBUG_IDENTIFY_TIMEZONE
266 fprintf(stderr, "TZ \"%s\" scores %d: at %ld %04d-%02d-%02d %02d:%02d:%02d %s versus %04d-%02d-%02d %02d:%02d:%02d %s\n",
267 tzname, i, (long) pgtt,
268 pgtm->tm_year + 1900, pgtm->tm_mon + 1, pgtm->tm_mday,
269 pgtm->tm_hour, pgtm->tm_min, pgtm->tm_sec,
270 pgtm->tm_isdst ? "dst" : "std",
271 systm->tm_year + 1900, systm->tm_mon + 1, systm->tm_mday,
273 systm->tm_isdst ? "dst" : "std");
274#endif
275 return i;
276 }
277 if (systm->tm_isdst >= 0)
278 {
279 /* Check match of zone names, too */
280 if (pgtm->tm_zone == NULL)
281 return -1; /* probably shouldn't happen */
282 memset(cbuf, 0, sizeof(cbuf));
283 strftime(cbuf, sizeof(cbuf) - 1, "%Z", systm); /* zone abbr */
284 if (strcmp(cbuf, pgtm->tm_zone) != 0)
285 {
286#ifdef DEBUG_IDENTIFY_TIMEZONE
287 fprintf(stderr, "TZ \"%s\" scores %d: at %ld \"%s\" versus \"%s\"\n",
288 tzname, i, (long) pgtt,
289 pgtm->tm_zone, cbuf);
290#endif
291 return i;
292 }
293 }
294 }
295
296#ifdef DEBUG_IDENTIFY_TIMEZONE
297 fprintf(stderr, "TZ \"%s\" gets max score %d\n", tzname, i);
298#endif
299
300 return i;
301}
static pg_tz * pg_load_tz(const char *name)
static bool compare_tm(struct tm *s, struct pg_tm *p)
int i
Definition isn.c:77
bool pg_tz_acceptable(pg_tz *tz)
Definition localtime.c:2028
int64 pg_time_t
Definition pgtime.h:23
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition localtime.c:1289
Definition pgtime.h:35

References compare_tm(), fb(), fprintf, i, pg_load_tz(), pg_localtime(), pg_tz_acceptable(), tm, and TZ_STRLEN_MAX.

Referenced by identify_system_timezone(), perfect_timezone_match(), and scan_available_timezones().

◆ select_default_timezone()

const char * select_default_timezone ( const char share_path)
extern

Definition at line 1744 of file findtimezone.c.

1745{
1746 const char *tzname;
1747
1748 /* Initialize timezone directory path, if needed */
1749#ifndef SYSTEMTZDIR
1750 snprintf(tzdirpath, sizeof(tzdirpath), "%s/timezone", share_path);
1751#endif
1752
1753 /* Check TZ environment variable */
1754 tzname = getenv("TZ");
1755 if (validate_zone(tzname))
1756 return tzname;
1757
1758 /* Nope, so try to identify the system timezone */
1760 if (validate_zone(tzname))
1761 return tzname;
1762
1763 return NULL;
1764}
static const char * identify_system_timezone(void)
static bool validate_zone(const char *tzname)
static char * share_path
Definition initdb.c:135

References fb(), identify_system_timezone(), share_path, snprintf, tzdirpath, and validate_zone().

Referenced by test_config_settings().

◆ validate_zone()

static bool validate_zone ( const char tzname)
static

Definition at line 1715 of file findtimezone.c.

1716{
1717 pg_tz *tz;
1718
1719 if (!tzname || !tzname[0])
1720 return false;
1721
1722 tz = pg_load_tz(tzname);
1723 if (!tz)
1724 return false;
1725
1726 if (!pg_tz_acceptable(tz))
1727 return false;
1728
1729 return true;
1730}

References fb(), pg_load_tz(), and pg_tz_acceptable().

Referenced by select_default_timezone().

◆ zone_name_pref()

static int zone_name_pref ( const char zonename)
static

Definition at line 602 of file findtimezone.c.

603{
604 /*
605 * Prefer UTC over alternatives such as UCT. Also prefer Etc/UTC over
606 * Etc/UCT; but UTC is preferred to Etc/UTC.
607 */
608 if (strcmp(zonename, "UTC") == 0)
609 return 50;
610 if (strcmp(zonename, "Etc/UTC") == 0)
611 return 40;
612
613 /*
614 * We don't want to pick "localtime" or "posixrules", unless we can find
615 * no other name for the prevailing zone. Those aren't real zone names.
616 */
617 if (strcmp(zonename, "localtime") == 0 ||
618 strcmp(zonename, "posixrules") == 0)
619 return -50;
620
621 return 0;
622}

References fb().

Referenced by scan_available_timezones().

Variable Documentation

◆ tzdirpath

char tzdirpath[MAXPGPATH]
static

Definition at line 27 of file findtimezone.c.

Referenced by pg_TZDIR(), and select_default_timezone().