PascalTZ: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: PascalTZ
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ### About | |
| 2 | + | ||
| 3 | + | PascalTZ stands for "Pascal Time Zone". It allows you to convert between local times in various [time zones](http://en.wikipedia.org/wiki/Time_zone) and [GMT](http://en.wikipedia.org/wiki/Gmt)/[UTC](http://en.wikipedia.org/wiki/Coordinated_Universal_Time), taking into account historical changes to time zone rules. PascalTZ uses the [Time Zone Database](https://www.iana.org/time-zones) (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. | |
| 4 | + | ||
| 5 | + | PascalTZ component can be used in pure FPC projects or installed as a design and runtime package in Lazarus IDE. It also comes with a testing framework, a collection of time zone conversion test vectors and test cases for internal functions. | |
| 6 | + | ||
| 7 | + | More information can be found at [GitHub:PascalTZ](https://github.com/dezlov/PascalTZ). | |
| 8 | + | ||
| 9 | + | ### Example | |
| 10 | + | ||
| 11 | + | ``` pascal | |
| 12 | + | uses | |
| 13 | + | SysUtils, DateUtils, uPascalTZ; | |
| 14 | + | ||
| 15 | + | var | |
| 16 | + | PascalTZ: TPascalTZ; | |
| 17 | + | DateTime: TDateTime; | |
| 18 | + | ||
| 19 | + | begin | |
| 20 | + | PascalTZ := TPascalTZ.Create; | |
| 21 | + | ||
| 22 | + | // Load time zone database from "tzdata" directory | |
| 23 | + | // Download from: https://www.iana.org/time-zones | |
| 24 | + | PascalTZ.DatabasePath := 'tzdata'; | |
| 25 | + | ||
| 26 | + | // Current local and UTC time | |
| 27 | + | DateTime := Now; | |
| 28 | + | WriteLn('Local time: ', DateTimeToStr(DateTime)); | |
| 29 | + | DateTime := LocalTimeToUniversal(DateTime); | |
| 30 | + | WriteLn('UTC time: ', DateTimeToStr(DateTime)); | |
| 31 | + | ||
| 32 | + | // Convert current time to Paris time | |
| 33 | + | DateTime := PascalTZ.GMTToLocalTime(DateTime, 'Europe/Paris'); | |
| 34 | + | WriteLn('Time in Paris: ', DateTimeToStr(DateTime)); | |
| 35 | + | ||
| 36 | + | // Convert Paris time to Chicago time | |
| 37 | + | DateTime := PascalTZ.Convert(DateTime, 'Europe/Paris', 'America/Chicago'); | |
| 38 | + | WriteLn('Time in Chicago: ', DateTimeToStr(DateTime)); | |
| 39 | + | ||
| 40 | + | // Check if a time zone exists | |
| 41 | + | WriteLn('Africa/Lagos exists? ', PascalTZ.TimeZoneExists('Africa/Lagos')); | |
| 42 | + | WriteLn('Australia/Darwin exists? ', PascalTZ.TimeZoneExists('Australia/Darwin')); | |
| 43 | + | ||
| 44 | + | PascalTZ.Free; | |
| 45 | + | end. | |
| 46 | + | ``` | |
| 47 | + | ||
| 48 | + | ### Authors | |
| 49 | + | ||
| 50 | + | This library was originally published by José Mejuto in 2009 and is maintained by Denis Kozlov since 2015. | |
| 51 | + | ||
| 52 | + | ### License | |
| 53 | + | ||
| 54 | + | [Modified](http://svn.freepascal.org/svn/lazarus/trunk/COPYING.modifiedLGPL) [LGPL](http://svn.freepascal.org/svn/lazarus/trunk/COPYING.LGPL) (same as the FPC RTL and the Lazarus LCL). | |
| 55 | + | ||
| 56 | + | ### Download | |
| 57 | + | ||
| 58 | + | [GitHub:PascalTZ releases](https://github.com/dezlov/PascalTZ/releases) | |
| 59 | + | ||
| 60 | + | ### Change Log | |
| 61 | + | ||
| 62 | + | - Version 1.0 (2009-11-10) [1](https://github.com/dezlov/PascalTZ/blob/v2.0/CHANGELOG.md) | |
| 63 | + | - Version 2.0 (2016-07-19) [2](https://github.com/dezlov/PascalTZ/blob/v2.0/CHANGELOG.md) | |
| 64 | + | ||
| 65 | + | ### Bug Reports | |
| 66 | + | ||
| 67 | + | Bug reports and suggestions can be logged at [GitHub:PascalTZ issues](https://github.com/dezlov/PascalTZ/issues). | |
| 68 | + | ||
| 69 | + | ### See also | |
| 70 | + | ||
| 71 | + | Since 2.6.2, FPC has the functions `LocalTimeToUniversal` and `UniversalTimeToLocal` in the *dateutils* unit to convert between local time and UTC time. These functions can be useful and an alternative for PascalTZ if you are not interested in historical/future date/times (i.e. the functions use current daylight saving time etc to convert to/from UTC time). These functions do allow for specifying manual offsets against UTC, but then you would need to keep track of those offsets - which PascalTZ does for you. | |
| 72 | + | ||
| 73 | + | --- | |
| 74 | + | *From the Free Pascal wiki, page "PascalTZ", as it stood on 2020-07-09 after a change by Zoltanleo, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 75 | + | Category: Components | |
| 76 | + | Category: FPC | |
| 77 | + | Category: Lazarus | |
| 78 | + | Category: Lazarus-CCR |
