Skip to content

dezlov/PascalTZ

Repository files navigation

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:

  1. Identify and fix all data parsing and time zone conversion problems (yes, plenty).
  2. Refactor the existing code to make debugging and maintenance easier.
  3. Expand functionality for more user-friendly workflows.
  4. Add test cases and a test framework.

See CHANGELOG.md for a list of major changes between versions.

Usage

  1. Add uPascalTZ unit to the uses clause of your project.
  2. Create an instance of TPascalTZ class.
  3. 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.
  1. 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:

  1. Test runner project located in test directory.
  2. Test vectors for time zone conversions located in vectors directory.
  3. Test cases (FPCUnit based) for provided test vectors and internal functions.
  4. 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.

  1. Update version number in package/pascaltz.lpk.
  2. Update CHANGELOG.md.
  3. Commit, tag with the version number (e.g. v1.2.3), push to origin.
  4. Update version number and download link in opm/update.json.
  5. 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).

See Also