8000 Sync back-branch copies of the timezone code with IANA release tzcode… · linearregression/postgres@5db14fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 5db14fa

Browse files
committed
Sync back-branch copies of the timezone code with IANA release tzcode2016c.
Back-patch commit 1c1a7cb, along with subsequent portability fixes, into all active branches. Also, back-patch commits 6960277 and 5968570 (addition of zic -P option) into 9.1 and 9.2, just to reduce differences between the branches. src/timezone/ is now largely identical in all active branches, except that in 9.1, pgtz.c retains the initial-timezone-selection code that was moved over to initdb in 9.2. Ordinarily we wouldn't risk this much code churn in back branches, but it seems necessary in this case, because among the changes are two feature additions in the "zic" zone data file compiler (a larger limit on the number of allowed DST transitions, and addition of a "%z" escape in zone abbreviations). IANA have not yet started to use those features in their tzdata files, but presumably they will before too long. If we don't update then we'll be unable to adopt new timezone data. Also, installations built with --with-system-tzdata (which includes most distro-supplied builds, I believe) might fail even if we don't update our copies of the data files. There are assorted bug fixes too, mostly affecting obscure timezones or post-2037 dates. Discussion: <13601.1468868947@sss.pgh.pa.us>
1 parent 84d6792 commit 5db14fa

File tree

12 files changed

+2188
-1404
lines changed

12 files changed

+2188
-1404
lines changed

src/timezone/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/zic
2+
/abbrevs.txt

src/timezone/Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ include $(top_builddir)/src/Makefile.global
1616
OBJS= localtime.o strftime.o pgtz.o
1717

1818
# files needed to build zic utility program
19-
ZICOBJS= zic.o ialloc.o scheck.o localtime.o
19+
ZICOBJS= zic.o
2020

2121
# timezone data files
2222
TZDATA = africa antarctica asia australasia europe northamerica southamerica \
@@ -40,8 +40,8 @@ endif
4040

4141
# We could do this test in the action section:
4242
# $(if $(ZIC),$(ZIC),./zic)
43-
# but gmake versions <= 3.78.1 or perhaps later have a bug
44-
# that causes a segfault; gmake 3.81 or later fixes this.
43+
# but GNU make versions <= 3.78.1 or perhaps later have a bug
44+
# that causes a segfault; GNU make 3.81 or later fixes this.
4545
ifeq (,$(ZIC))
4646
ZIC= ./zic
4747
endif
@@ -55,6 +55,11 @@ ifeq (,$(with_system_tzdata))
5555
endif
5656
$(MAKE) -C tznames $@
5757

58+
abbrevs.txt: zic $(TZDATAFILES)
59+
mkdir junkdir
60+
$(ZIC) -P -d junkdir -p '$(POSIXRULES)' $(TZDATAFILES) | LANG=C sort | uniq >abbrevs.txt
61+
rm -rf junkdir
62+
5863
installdirs:
5964
$(MKDIR_P) '$(DESTDIR)$(datadir)'
6065

@@ -65,4 +70,4 @@ endif
6570
$(MAKE) -C tznames $@
6671

6772
clean distclean maintainer-clean:
68-
rm -f zic$(X) $(ZICOBJS)
73+
rm -f zic$(X) $(ZICOBJS) abbrevs.txt

src/timezone/README

Lines changed: 87 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,103 @@
11
src/timezone/README
22

3-
Timezone
4-
========
3+
This is a PostgreSQL adapted version of the IANA timezone library from
54

6-
This is a PostgreSQL adapted version of the timezone library from
7-
http://www.iana.org/time-zones
5+
http://www.iana.org/time-zones
86

9-
The source code can be found at:
7+
The latest versions of both the tzdata and tzcode tarballs are normally
8+
available right from that page. Historical versions can be found
9+
elsewhere on the site.
1010

11-
ftp://ftp.iana.org/tz/releases/tzcode*.tar.gz
12-
13-
The code is currently synced with release 2010c. There are many cosmetic
14-
(and not so cosmetic) differences from the original tzcode library, but
15-
diffs in the upstream version should usually be propagated to our version.
11+
Since time zone rules change frequently in some parts of the world,
12+
we should endeavor to update the data files before each PostgreSQL
13+
release. The code need not be updated as often, but we must track
14+
changes that might affect interpretation of the data files.
1615

17-
The data files under data/ are an exact copy of the latest data set from:
1816

19-
ftp://ftp.iana.org/tz/releases/tzdata*.tar.gz
17+
Time Zone data
18+
==============
2019

21-
Since time zone rules change frequently in some parts of the world,
22-
we should endeavor to update the data files before each PostgreSQL
23-
release.
20+
The data files under data/ are an exact copy of the latest tzdata set,
21+
except that we omit some files that are not of interest for our purposes.
2422

25-
At each update, we should check if time zone offsets have changed.
26-
Just search for the current or previous year and see what has changed.
27-
Sometimes a country changes its time zone offsets, for example Georgia
28-
in 2004. Just grepping in the zic database files for 2004 is enough to
29-
spot such a change. Then the files under tznames/ should be updated.
23+
While the files under data/ can just be duplicated when updating, manual
24+
effort is needed to update the time zone abbreviation lists under tznames/.
25+
These need to be changed whenever new abbreviations are invented or the
26+
UTC offset associated with an existing abbreviation changes. To detect
27+
if this has happened, after installing new files under data/ do
28+
make abbrevs.txt
29+
which will produce a file showing all abbreviations that are in current
30+
use according to the data/ files. Compare this to known_abbrevs.txt,
31+
which is the list that existed last time the tznames/ files were updated.
32+
Update tznames/ as seems appropriate, then replace known_abbrevs.txt
33+
in the same commit. Usually, if a known abbreviation has changed meaning,
34+
the appropriate fix is to make it refer to a long-form zone name instead
35+
of a fixed GMT offset.
3036

3137
When there has been a new release of Windows (probably including Service
3238
Packs), the list of matching timezones need to be updated. Run the
3339
script in src/tools/win32tzlist.pl on a Windows machine running this new
3440
release and apply any new timezones that it detects. Never remove any
3541
mappings in case they are removed in Windows, since we still need to
3642
match properly on the old version.
43+
44+
45+
Time Zone code
46+
==============
47+
48+
The code in this directory is currently synced with tzcode release 2016c.
49+
There are many cosmetic (and not so cosmetic) differences from the
50+
original tzcode library, but diffs in the upstream version should usually
51+
be propagated to our version. Here are some notes about that.
52+
53+
For the most part we want to use the upstream code as-is, but there are
54+
several considerations preventing an exact match:
55+
56+
* For readability/maintainability we reformat the code to match our own
57+
conventions; this includes pgindent'ing it and getting rid of upstream's
58+
overuse of "register" declarations. (It used to include conversion of
59+
old-style function declarations to C89 style, but thank goodness they
60+
fixed that.)
61+
62+
* We need the code to follow Postgres' portability conventions; this
63+
includes relying on configure's results rather than hand-hacked #defines,
64+
and not relying on <stdint.h> features that may not exist on old systems.
65+
(In particular this means using Postgres' definitions of the int32 and
66+
int64 typedefs, not int_fast32_t/int_fast64_t.)
67+
68+
* Since Postgres is typically built on a system that has its own copy
69+
of the <time.h> functions, we must avoid conflicting with those. This
70+
mandates renaming typedef time_t to pg_time_t, and similarly for most
71+
other exposed names.
72+
73+
* We have exposed the tzload() and tzparse() internal functions, and
74+
slightly modified the API of the former, in part because it now relies
75+
on our own pg_open_tzfile() rather than opening files for itself.
76+
77+
* There's a fair amount of code we don't need and have removed,
78+
including all the nonstandard optional APIs. We have also added
79+
a few functions of our own at the bottom of localtime.c.
80+
81+
* In zic.c, we have added support for a -P (print_abbrevs) switch, which
82+
is used to create the "abbrevs.txt" summary of currently-in-use zone
83+
abbreviations that was described above.
84+
85+
86+
The most convenient way to compare a new tzcode release to our code is
87+
to first run the tzcode source files through a sed filter like this:
88+
89+
sed -r \
90+
-e 's/^([ \t]*)\*\*([ \t])/\1 *\2/' \
91+
-e 's/^([ \t]*)\*\*$/\1 */' \
92+
-e 's|^\*/| */|' \
93+
-e 's/\bregister[ \t]//g' \
94+
-e 's/int_fast32_t/int32/g' \
95+
-e 's/int_fast64_t/int64/g' \
96+
-e 's/struct[ \t]+tm\b/struct pg_tm/g' \
97+
-e 's/\btime_t\b/pg_time_t/g' \
98+
99+
and then run them through pgindent. (The first three sed patterns deal
100+
with conversion of their block comment style to something pgindent
101+
won't make a hash of; the remainder address other points noted above.)
102+
After that, the files can be diff'd directly against our corresponding
103+
files.

src/timezone/ialloc.c

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0