Using IANA time zone database in embedded systems with strict memory requirements and with/without filesystem support by generating C code from IANA time zone database which you can integrate to your C/C++ embedded code. This adds support for world wide time zone and automatic DST switching with just < 200kb size time zone library. The technique used is to intercept the internal function calls of the standard time zone library and route it to a custom implementation of the function which use C arrays for retrieving time zone data. This way the huge time zone database binary files are stripped off from the final build and provides a “TinyTZ” library!
Default build of Time zone database gives a binary database stored in files (zoneinfo/). It is ~2MB in size for supporting ~586 different time zone names. The reference code and the time zone data base are available in the below link, http://www.iana.org/time-zones Current version:
Time Zone Data v. 2013d (Released 2013-07-05) tzdata2013d.tar.gz (213.8kb)
Time Zone Code v. 2013d (Released 2013-07-05) tzcode2013d.tar.gz (135.0kb)
This implementation strips down the original time zone data to few kilo bytes (< 200KB) binary data and avoids the filesystem dependency for use with embedded systems with strict memory constraints. The IANA reference source code is used “as is” from the IANA web site. There are minor Make file changes and a private header file added for removing filesystem dependency. Using few configuration files time zone names are selected for worldwide coverage. 90 – 100 time zone names are more than sufficient for worldwide time zone coverage for a lot of applications which require showing date and time in their local time zone. Below are the configuration files used,
tzr.txt/zn.txt: for tz-strip-new.sh to generate the time zone binary database after removing unwanted time zone data from the binary database.
tz_included.txt: This file contains all the time zones that are included in the database after the build.
tz_omitted.txt: This file contains all the time zones that are omitted in the database after the build.
The file “intercept.h” does the trick of intercepting the calls from the standard time zone library functions and executed a custom implementation of the function which internally uses the generated time zone data files in the form of C arrays. Have a look at the file: tzdata2013d.c.backup.
The interceptor implementation “tzdata2013d_template.c” and “tzdata2013d_template.h” actually access the time zone database compiled from the generated file “tzdata2013d.c.backup”.
You may need to change the tool chain and target paths in linux_install.sh. On successful installation, libtz and the binary database can be found under the build directory.
The following files are additionally added to the original source,
Configuration file for tz-strip-db.sh: tzr.txt, zn.txt
Included and omitted tz names: tz_included.txt*, tz_omitted.txt*
*These files are generated during the build process.
Complete source code download.