This library is composed of two main parts:
Part 1: TimeZoneDatabaseCreator
This part is designed for use on Windows with Visual Studio 2022. It allows you to convert the time zone database from https://www.iana.org/time-zones into a format suitable for embedded systems.
Steps:
- Download the compressed database file from the IANA website. It is recommended to download the "Data Only Distribution" option.
- Extract the downloaded file.
- Provide the path to the extracted files to the TimeZoneDatabaseCreator application.
- The application will process the data and create a folder named
timezone_database
within your project directory. This folder will contain the following six files:timezone_database.h
: Defines the necessary structures, variables, and constants.timezone_database.c
: Contains the compiled time zone database for efficient use in your embedded firmware. This file is optimized for performance and speed.tz_zi.txt
: Contains time zone index information.tz_zd.txt
: Contains time zone data.tz_ri.txt
: Contains rule index information.tz_rd.txt
: Contains rule data.
Part 2: TimeZoneCalculator
This part provides functions for calculating and converting time between Greenwich Mean Time (GMT) or Coordinated Universal Time (UTC) and local time for any given date and time.
Functionality:
You provide the desired date, time, and time zone code to the TimeZoneCalculator library, and it returns the corresponding local time.
Structure:
This part consists of two components:
timezone_database
: This is the same folder generated by the TimeZoneDatabaseCreator in Part 1. It needs to be copied into the TimeZoneCalculator directory.timezone_calculator
: This component contains the functions responsible for time calculations.
Usage:
To use the TimeZoneCalculator, include the time_zone.h
file in your project.
Example:
For usage examples and to understand how the functions work, refer to the test.c
file located in the TimeZoneCalculator folder.
- IANA Time Zone Database: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
- tz database: https://github.com/eggert/tz
Disclaimer: This library is under active development and may contain bugs or limitations.