Awesome
PascalTZ
PascalTZ stands for "Pascal Time Zone". It allows you to convert between local times in various time zones and GMT/UTC, taking into account historical changes to time zone rules.
PascalTZ uses the Time Zone Database (often called tz
or zoneinfo
) to determine how to correctly adjust time for various time zones. The correctness of time zone conversions in future relies on using an up to date database. Beware, time zone rules may be changed by governments around the world, sometimes with a very short notice.
This code is based on PascalTZ originally published by José Mejuto in 2009.
The maintenance of this package has been taken up by Denis Kozlov in 2015 with key goals:
- Identify and fix all data parsing and time zone conversion problems (yes, plenty).
- Refactor the existing code to make debugging and maintenance easier.
- Expand functionality for more user-friendly workflows.
- Add test cases and a test framework.
See CHANGELOG.md for a list of major changes between versions.
Usage
- Add
uPascalTZ
unit to the uses clause of your project. - Create an instance of
TPascalTZ
class. - Load the time zone database into an instance of
TPascalTZ
:
- Download and unpack the latest Time Zone Database, i.e.
tzdata*.tar.gz
. - Set
DatabasePath
property to the location of your time zone database.
- Use
GMTToLocalTime
,LocalTimeToGMT
and other methods to convert date and time between various time zones.
Design and runtime package is available for installation into Lazarus IDE. Users of the Online Package Manager (OPM) for Lazarus IDE can keep the package updated using opm/update.json.
Testing
A testing framework consists of the following ingredients:
- Test runner project located in
test
directory. - Test vectors for time zone conversions located in
vectors
directory. - Test cases (FPCUnit based) for provided test vectors and internal functions.
- PHP script to generate test vectors, and test time zone conversions using PHP and MySQL implementations.
Running the test project requires the time zone database to be available in the tzdata
directory.
Release
Steps for preparing a new release.
- Update version number in package/pascaltz.lpk.
- Update CHANGELOG.md.
- Commit, tag with the version number (e.g.
v1.2.3
), push to origin. - Update version number and download link in opm/update.json.
- Commit, push to origin.
Version numbers must adhere to the semantic versioning specification.
Authors
- 2009 - José Mejuto
- 2015 - Denis Kozlov
License
Modified LGPL (same as the FPC RTL and the Lazarus LCL).