Getting Started with ChronoKit-FP

This guide gets a Free Pascal or Lazarus project to its first useful date calculation. It deliberately starts with calendar dates; business calendars, timezones, and DST are separate topics.

Install ChronoKit#

Choose one path:

  • Lazarus: Open packages/lazarus/chronokit_fp.lpk, select Compile,

then select Use → Add to Project.

  • Source-based project: Compile with the repository's src/ directory in

the unit search path. For example, on Windows:

``powershell fpc "-FuC:\path\to\chronokit-fp\src" MyProgram.lpr ``

Both paths make the ChronoKit unit available to the project.

Your first program#

Create FirstChronoKitProgram.lpr with the following content:

Pascal
program FirstChronoKitProgram;

{$mode objfpc}{$H+}{$J-}

uses
  SysUtils,
  ChronoKit;

var
  CreatedDate, ParsedDate, NextWeek: TDateTime;
begin
  CreatedDate := EncodeDate(2026, 8, 10);
  WriteLn('Created: ', TChronoKit.FormatDateTime(CreatedDate, 'yyyy-mm-dd'));

  ParsedDate := TChronoKit.ParseDateTime('2026-08-10', 'yyyy-mm-dd');
  NextWeek := TChronoKit.AddDays(ParsedDate, 7);
  WriteLn('One week later: ',
    TChronoKit.FormatDateTime(NextWeek, 'yyyy-mm-dd'));
end.

Compile it using the source-based command above, substituting the program file name. Its output is:

Expected output
Created: 2026-08-10
One week later: 2026-08-17

Choose the right starting point#

NeedStart with
A calendar date with no timeEncodeDate or TChronoKit.GetToday
The computer's current local date and timeTChronoKit.GetNow
A date/time entered as textTChronoKit.ParseDateTime with an explicit format
Text formatted for display or outputTChronoKit.FormatDateTime with an explicit format
A date a fixed number of days awayTChronoKit.AddDays
Workdays in an inclusive date periodTChronoKit.BusinessDaysBetween
The same instant represented in a named timezoneTChronoKit.SystemLocalToTimeZone
A wall clock that should be interpreted in a named timezoneTChronoKit.TimeZoneToSystemLocal
A named source clock shown in another named timezoneTChronoKit.ConvertBetweenTimeZones

ChronoKit uses Free Pascal's TDateTime type. A date is conventionally a TDateTime at midnight. A local date/time is a wall-clock value such as the value returned by GetNow. A timezone conversion is an explicit operation—use SystemLocalToTimeZone only when the target timezone matters. The result is still a TDateTime; keep the intended timezone alongside the value in your application when it must be known later. UTC is the only portable timezone identifier. Before converting named zones, read the timezone contract for Windows/Linux identifier mappings and DST-boundary errors.

Convert a timezone value#

SystemLocalToTimeZone starts with a system-local wall clock and returns the same instant displayed in the target zone. This portable example converts the current local time to UTC:

Pascal
var
  LocalValue, UTCValue: TDateTime;
begin
  LocalValue := TChronoKit.GetNow;
  UTCValue := TChronoKit.SystemLocalToTimeZone(LocalValue, 'UTC');
  WriteLn(TChronoKit.FormatDateTime(UTCValue, 'yyyy-mm-dd hh:nn:ss'));
end;

TimeZoneToSystemLocal starts with clock fields that belong to the named source zone. It returns the equivalent clock in the computer's system zone. Names are platform-native: use America/New_York on Linux or Eastern Standard Time on Windows for New York.

When both zones are named, use ConvertBetweenTimeZones instead of routing through the computer's system timezone. The source wall clock is resolved once and the result is the target-zone wall clock for the same instant. See the named-timezone learning program.

Both operations raise ETimeZoneError when a source wall clock falls in a DST gap or overlap. Catch the exception rather than letting the library select an occurrence silently:

Pascal
try
  SystemValue := TChronoKit.TimeZoneToSystemLocal(InputValue, SourceTimeZone);
except
  on E: ETimeZoneError do
    WriteLn('Choose another local time: ', E.Message);
end;

Formats#

Always pass the format when parsing user or file input. The common tokens are:

TokenMeaning
yyyyFour-digit year
mmMonth
ddDay of month
hhHour
nnMinute
ssSecond

For example, parse 2026-08-10 09:30 with 'yyyy-mm-dd hh:nn'. Notice that minutes use nn, not mm.

The original 1.x formatting and parsing names remain source compatible but are deprecated. New code should use FormatDateTime and ParseDateTime, which use the same behavior and errors. See the v1.6 migration guide.

Next steps#

weeks, deadlines, reporting periods, and date ranges.

issues.

DST rules.

or keyword.