diff options
Diffstat (limited to 'src/third_party/timelib/zones')
| -rw-r--r-- | src/third_party/timelib/zones/Makefile | 114 | ||||
| -rw-r--r-- | src/third_party/timelib/zones/README.rst | 22 | ||||
| -rw-r--r-- | src/third_party/timelib/zones/create-timezonedb.php | 171 | ||||
| -rw-r--r-- | src/third_party/timelib/zones/update-package-version.php | 13 | ||||
| -rw-r--r-- | src/third_party/timelib/zones/update-package-xml.php | 17 |
5 files changed, 337 insertions, 0 deletions
diff --git a/src/third_party/timelib/zones/Makefile b/src/third_party/timelib/zones/Makefile new file mode 100644 index 00000000000..914c14ed6bc --- /dev/null +++ b/src/third_party/timelib/zones/Makefile @@ -0,0 +1,114 @@ +all: index + +download: + -@rm -f tzdata20*tar.gz + -@rm -f tzcode20*tar.gz + @echo "Downloading latest Olson TZDB release..." + $(eval VERSION := $(shell curl -s -o - https://www.iana.org/time-zones | grep \"version\" | sed 's/.*version">//' | sed 's/<\/span.*//')) + curl -s -o tzdata$(VERSION).tar.gz https://data.iana.org/time-zones/releases/tzdata$(VERSION).tar.gz + curl -s -o tzcode$(VERSION).tar.gz https://data.iana.org/time-zones/releases/tzcode$(VERSION).tar.gz + @echo " done" + +clean: release-php-clean + -rm -rf code + -rm -f timezonedb.idx.php timezonedb.dta timezonedb.idx version-info.txt timezonedb-20[12]*.tgz timezonedb.tgz timezonedb*.zip + +tzdb: download + -@rm -rf code + @mkdir code + @echo "Unpacking Olson TZDB release..." + tar -C code -xzf tzdata*tar.gz + tar -C code -xzf tzcode*tar.gz + +code/zone.tab: tzdb + @make PACKRATDATA=backzone PACKRATLIST=zone.tab -C code + @echo "Compiling tzdata files..." + cat code/main.zi | ./code/zic -b fat -d code/data - + cat code/main.zi | ./code/zic -b slim -d code/data-slim - + +version-info.txt: download + find . -name tzdata*.tar.gz | sed 's/.*202/202/' | sed 's/\.tar.*//' > version-info.txt + find . -name tzdata*.tar.gz | sed -E "s/^.*(20[0-9]{2}).*$$/\1/" | tr -d '\n' >> version-info.txt + echo -n "." >> version-info.txt + find . -name tzdata*.tar.gz | sed -E "s/^.*20[0-9]{2}(\w).*$$/\1/" | sed "s/\\n//" | od -A n -t d1 -N 1 | awk '{printf "%s", $$1 - 96}' >> version-info.txt + +timezonedb.zip: code/zone.tab version-info.txt + @echo -n "Making archive..." + -@mkdir code/timezonedb-$(VERSION); cp -r code/data/. code/timezonedb-$(VERSION)/; cp version-info.txt code/timezonedb-$(VERSION)/ + -@cd code; zip --quiet -r ../timezonedb.zip timezonedb-$(VERSION) + @cp timezonedb.zip timezonedb-$(VERSION).zip + @echo " done" + +timezonedb.h: code/zone.tab version-info.txt create-timezonedb.php + php create-timezonedb.php + cp timezonedb.h .. + +index: timezonedb.h + +timezonedb.tgz: index + $(eval VERSION := $(shell cat version-info.txt | tail -n 1)) + cp timezonedb.h ~/dev/php/pecl-datetime-timezonedb + php update-package-xml.php ~/dev/php/pecl-datetime-timezonedb + php update-package-version.php ~/dev/php/pecl-datetime-timezonedb + pecl package ~/dev/php/pecl-datetime-timezonedb/package.xml + cp timezonedb-$(VERSION).tgz timezonedb.tgz + +release-pecl: timezonedb.tgz + $(eval VERSION := $(shell cat version-info.txt | tail -n 1)) + $(eval TZVERSION := $(shell cat version-info.txt | head -n 1)) + $(eval TAG := $(shell cat version-info.txt | tail -n 1 | tr "." "_")) + cd ~/dev/php/pecl-datetime-timezonedb; git commit -m "Updated to version $(VERSION) ($(TZVERSION))" timezonedb.c timezonedb.h package.xml php_timezonedb.h + cd ~/dev/php/pecl-datetime-timezonedb; git tag -s RELEASE_$(TAG) -m "Go with $(VERSION)" + cd ~/dev/php/pecl-datetime-timezonedb; git push origin master RELEASE_$(TAG) + +release-docs: timezonedb.tgz + $(eval VERSION := $(shell cat version-info.txt | tail -n 1)) + $(eval TZVERSION := $(shell cat version-info.txt | head -n 1)) + -pecl upgrade -f timezonedb.tgz + cd ~/dev/php/phpdoc/en; git pull + cd ~/dev/php/phpdoc/en/reference/datetime/; php -dextension=timezonedb.so ../../../doc-base/scripts/gen-phpdoc-tz-list.php > timezones.xml + cd ~/dev/php/phpdoc/en/reference/datetime/; git commit -m "Updated to version $(VERSION) ($(TZVERSION))" timezones.xml && git push + +release-php-clean: + -rm -rf /tmp/tz-tmp + +release-php-clone: release-php-clean + git clone git@github.com:/php/php-src /tmp/tz-tmp + +release-php-commit-80: timezonedb.tgz + $(eval VERSION := $(shell cat version-info.txt | tail -n 1)) + $(eval TZVERSION := $(shell cat version-info.txt | head -n 1)) + cd /tmp/tz-tmp; git checkout PHP-8.0 + cp timezonedb.h /tmp/tz-tmp/ext/date/lib + cd /tmp/tz-tmp; git commit -m "Updated to version $(VERSION) ($(TZVERSION))" ext/date/lib/timezonedb.h + +release-php-commit-81: timezonedb.tgz release-php-commit-80 + $(eval VERSION := $(shell cat version-info.txt | tail -n 1)) + $(eval TZVERSION := $(shell cat version-info.txt | head -n 1)) + cd /tmp/tz-tmp; git checkout PHP-8.1 + cd /tmp/tz-tmp; git merge PHP-8.0 --strategy=ours -m "Empty merge" + cp timezonedb.h /tmp/tz-tmp/ext/date/lib + cd /tmp/tz-tmp; git commit -m "Updated to version $(VERSION) ($(TZVERSION))" ext/date/lib/timezonedb.h + +release-php-commit-82: timezonedb.tgz release-php-commit-81 + $(eval VERSION := $(shell cat version-info.txt | tail -n 1)) + $(eval TZVERSION := $(shell cat version-info.txt | head -n 1)) + cd /tmp/tz-tmp; git checkout PHP-8.2 + cd /tmp/tz-tmp; git merge PHP-8.1 --strategy=ours -m "Empty merge" + cp timezonedb.h /tmp/tz-tmp/ext/date/lib + cd /tmp/tz-tmp; git commit -m "Updated to version $(VERSION) ($(TZVERSION))" ext/date/lib/timezonedb.h + +release-php-commit-master: timezonedb.tgz release-php-commit-82 + $(eval VERSION := $(shell cat version-info.txt | tail -n 1)) + $(eval TZVERSION := $(shell cat version-info.txt | head -n 1)) + cd /tmp/tz-tmp; git checkout master + cd /tmp/tz-tmp; git merge PHP-8.2 --strategy=ours -m "Empty merge" + cp timezonedb.h /tmp/tz-tmp/ext/date/lib + cd /tmp/tz-tmp; git commit -m "Updated to version $(VERSION) ($(TZVERSION))" ext/date/lib/timezonedb.h + +release-php-commit: release-php-clone release-php-commit-80 release-php-commit-81 release-php-commit-82 release-php-commit-master + +release-php-push: release-php-commit + cd /tmp/tz-tmp; git push origin PHP-8.0 PHP-8.1 PHP-8.2 master + +release-php: release-php-clean release-php-clone release-php-commit release-php-push diff --git a/src/third_party/timelib/zones/README.rst b/src/third_party/timelib/zones/README.rst new file mode 100644 index 00000000000..a192b0b2a8e --- /dev/null +++ b/src/third_party/timelib/zones/README.rst @@ -0,0 +1,22 @@ +Building the timezone files +--------------------------- + +The building of files is done through the ``Makefile`` with: + +- ``make clean`` (important if data files have changed) +- ``make release-pecl`` (PECL timezonedb extension) +- ``make release-docs`` (documentation updates) +- ``make release-php`` (changes to embed database in PHP) + +It has the following prerequisites: + +- The directory contains **one** ``tzcode2014i.tar.gz`` file and **one** + ``tzdata2014i.tar.gz`` file. +- You have a PECL SVN checkout in ``~/dev/php/pecl`` +- You have a PHPDOC GIT checkout in ``~/dev/php/phpdoc`` +- You can commit to PHP's GIT ``php-src`` repository. +- You can commit to PHP's GIT ``doc-base`` and ``doc-en`` repositories. +- You can commit to PECL's SVN repository. +- ``php`` is in your path. + +Do not run this script, unless you're Derick Rethans. diff --git a/src/third_party/timelib/zones/create-timezonedb.php b/src/third_party/timelib/zones/create-timezonedb.php new file mode 100644 index 00000000000..679a7c047d7 --- /dev/null +++ b/src/third_party/timelib/zones/create-timezonedb.php @@ -0,0 +1,171 @@ +<?php +function readZoneTab( string $tabFile ) : array +{ + $tab = []; + + // process extra info + $f = file( 'code/zone.tab' ); + + foreach ( $f as $line ) + { + $line = trim( $line ); + $comments = ''; + + if ( strlen( $line ) < 5 || $line[0] == '#' ) + { + continue; + } + $fields = explode( "\t", $line ); + list( $countryCode, $coordinates, $tzid ) = $fields; + if ( sizeof( $fields ) > 3 ) { + $comments = $fields[3]; + } + + // format lang/lat + if ( strlen( $coordinates ) == 11 ) + { + sscanf( $coordinates, '%c%2d%2d%c%3d%2d', $xSign, $xH, $xM, $ySign, $yH, $yM ); + $xS = $yS = 0; + } + else + { + sscanf( $coordinates, '%c%2d%2d%2d%c%3d%2d%2d', $xSign, $xH, $xM, $xS, $ySign, $yH, $yM, $yS ); + } + $lat = $xH + ( $xM / 60 ) + ( $xS / 3600 ); + $long = $yH + ( $yM / 60 ) + ( $yS / 3600 ); + $lat = $xSign == '+' ? $lat : -$lat; + $long = $ySign == '+' ? $long : -$long; + + $tab[$tzid] = [ + 'cc' => $countryCode, + 'lat' => ($lat + 90) * 100000, + 'lng' => ($long + 180) * 100000, + 'desc' => $comments ?: '', + ]; + } + + return $tab; +} + +function readDataFile( string $tzid, array $tab ) : array +{ + $originalHeaderSize = 20; + + // obtain data from tz files + $fatData = file_get_contents( "code/data/{$tzid}", false, NULL, $originalHeaderSize ); + $slimData = file_get_contents( "code/data-slim/{$tzid}", false, NULL, $originalHeaderSize ); + + $tabData = array_key_exists( $tzid, $tab ) ? $tab[$tzid] : null; + + if ( $tabData ) { + $header = pack( 'a4ca2a13', 'PHP2', true, $tabData['cc'], '' ); + $footer = pack( 'NNNa*', $tabData['lat'], $tabData['lng'], strlen( $tabData['desc'] ), $tabData['desc'] ); + } else { + $header = pack( 'a4ca2a13', 'PHP2', $tzid == 'UTC', '??', '' ); + $footer = pack( 'NNNa*', 0, 0, 0, '' ); + } + + $fatData = $header . $fatData . $footer; + $slimData = $header . $slimData . $footer; + + return [ $fatData, $slimData ]; +} + +function createDataAndIndex(array $tab) +{ + $files = array_merge(glob("code/data/*"), glob("code/data/*/*"), glob("code/data/*/*/*")); + usort($files, 'strcasecmp'); + + $fatIndex = []; + $slimIndex = []; + $fatData = $slimData = ''; + + foreach ($files as $fileName) { + if (is_dir($fileName)) { + continue; + } + + $tzid = preg_replace('@code/data/@', '', $fileName); + list($tzFatData, $tzSlimData) = readDataFile($tzid, $tab); + + $fatIndex[$tzid] = strlen($fatData); + $slimIndex[$tzid] = strlen($slimData); + + $fatData .= $tzFatData; + $slimData .= $tzSlimData; + } + + return [$fatIndex, $fatData, $slimIndex, $slimData]; +} + +function getVersion() : string +{ + $version_info = file( 'version-info.txt' ); + $version = trim( $version_info[1] ); + + return $version; +} + +function addData(array $index, string $data) +{ + $elements = count( $index ); + $flipIndex = array_flip( $index ); + $dataSize = strlen( $data ); + + $str = "const timelib_tzdb_index_entry timezonedb_idx_builtin[$elements] = {\n"; + foreach ( $index as $tzid => $start ) + { + $str .= sprintf( "\t{ (char*) %-36s, 0x%06X },\n", "\"{$tzid}\"", $start ); + } + $str .= "};\n"; + + $pos = 0; + + $str .= "\n\nconst unsigned char timelib_timezone_db_data_builtin[{$dataSize}] = {"; + for ( $i = 0; $i < $dataSize; $i++ ) + { + if ( isset( $flipIndex[$i] ) ) + { + $str .= "\n\n/* {$flipIndex[$i] } */\n"; + $pos = 0; + } + $str .= sprintf( "0x%02X,", ord( $data[$i] ) ); + if ( $pos % 16 == 15) { + $str .= "\n"; + } else { + $str .= " "; + } + $pos++; + } + $str .= "\n};\n"; + + return $str; +} + +function writeTimelibH(array $fatIndex, string $fatData, array $slimIndex, string $slimData ) +{ + $elements = count( $fatIndex ); + + $data = "/* This is a generated file, do not modify */\n"; + + /* Error out if TIMELIB_SUPPORTS_V2DATA isn't set */ + $data .= "#ifndef TIMELIB_SUPPORTS_V2DATA\n"; + $data .= "#error Your version of timelib does not understand the timzonedb data format, please upgrade\n"; + $data .= "#endif\n\n"; + + $data .= "#ifdef TIMELIB_SUPPORT_SLIM_FILE\n"; + $data .= addData( $slimIndex, $slimData ); + $data .= "#else\n"; + $data .= addData( $fatIndex, $fatData ); + $data .= "#endif\n\n"; + + $version = getVersion(); + $data .= "const timelib_tzdb timezonedb_builtin = { \"{$version}\", {$elements}, timezonedb_idx_builtin, timelib_timezone_db_data_builtin };\n"; + + file_put_contents( 'timezonedb.h', $data ); +} + +$tab = readZoneTab( 'code/zone.tab' ); +list( $fatIndex, $fatData, $slimIndex, $slimData ) = createDataAndIndex( $tab ); +writeTimelibH( $fatIndex, $fatData, $slimIndex, $slimData ); +?> diff --git a/src/third_party/timelib/zones/update-package-version.php b/src/third_party/timelib/zones/update-package-version.php new file mode 100644 index 00000000000..6fb25521586 --- /dev/null +++ b/src/third_party/timelib/zones/update-package-version.php @@ -0,0 +1,13 @@ +<?php +$e = file_get_contents( $argv[1] . '/php_timezonedb.h' ); + +/* Grab version info */ +$version_info = file( 'version-info.txt' ); +$tzversion = trim( $version_info[0] ); +$version = trim( $version_info[1] ); + +/* Use preg_replace to update version in package.xml */ +$f = preg_replace( '@"20[0-2][0-9].*"@', "\"{$version}\"", $e ); + +file_put_contents( $argv[1] . '/php_timezonedb.h', $f ); +?> diff --git a/src/third_party/timelib/zones/update-package-xml.php b/src/third_party/timelib/zones/update-package-xml.php new file mode 100644 index 00000000000..ce5c774a7cc --- /dev/null +++ b/src/third_party/timelib/zones/update-package-xml.php @@ -0,0 +1,17 @@ +<?php +$e = file_get_contents( $argv[1] . '/package.xml' ); + +/* Grab version info */ +$version_info = file( 'version-info.txt' ); +$tzversion = trim( $version_info[0] ); +$version = trim( $version_info[1] ); + +/* Use preg_replace to update version in package.xml */ +$f = preg_replace( '@release>20.*</release>@', "release>{$version}</release>", $e ); +$g = preg_replace( '@api>20.*</api>@', "api>{$version}</api>", $f ); +$h = preg_replace( '@version 20.*@', "version {$version} ({$tzversion})", $g ); +$date = date( 'Y-m-d' ); +$i = preg_replace( '@date>.*</date@', "date>{$date}</date", $h ); + +file_put_contents( $argv[1] . '/package.xml', $i ); +?> |
