Skip to main content

DaysInAYear

Function DaysInAYear(const AYear: Word): Word

Example

procedure ScriptEvent(var Value: variant);
begin
Value := DaysInAYear(2024); // 366
end;

Usage

DaysInAYear returns 365 or 366 for a supplied year according to Gregorian leap-year rules.

Parameters

NameTypeDescription
AYearWord, constYear to evaluate. Use 1..9999 when it must correspond to an encodeable Velox date.

Returns

366 when AYear is divisible by 400 or divisible by 4 but not 100; otherwise 365.

Behaviour

The function evaluates only the numeric year and has no date/time, locale or timezone dependency.

Errors

No exception path for any Word input.

Additional Technical Info

DaysInAYear returns the Gregorian length of the supplied year: 366 for a leap year and 365 otherwise.

The example is fictional, deterministic and source-reviewed. It was not executed by the documentation workflow.

Implementation

The DateUtils import binds to Delphi 37.0 System.DateUtils.DaysInAYear. It calls IsLeapYear(AYear) and uses that Boolean to index the two-element DaysPerYear table.

Edge cases and quirks

  • The signature accepts every Word value (0..65535), but Delphi TDateTime calendar dates are limited to years 1..9999. Out-of-range years still receive a mathematical 365/366 result instead of a validation error; year 0 satisfies the divisibility test and returns 366.
  • This is a Gregorian leap-year rule and does not model historical adoption of Gregorian calendars by jurisdiction.
  • The Free Pascal reference currently contains a wording typo saying "weeks" in one sentence; its declared result and examples still show 365/366 days. Velox behaviour is established from Delphi source.

Side effects

None.

Performance and concurrency

Constant-time integer arithmetic/table lookup with no allocation or shared state.

Related entries

External references

Created 2026-07-15