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
| Name | Type | Description |
|---|---|---|
AYear | Word, const | Year 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
Wordvalue (0..65535), but DelphiTDateTimecalendar dates are limited to years1..9999. Out-of-range years still receive a mathematical 365/366 result instead of a validation error; year0satisfies the divisibility test and returns366. - 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
DaysInYearderives the year from aTDateTime.DaysInAMonthapplies the leap result to February.DayOfTheYearreturns a date's ordinal within the year.
External references
- Embarcadero
System.DateUtils.DaysInAYear- documents the exact Delphi routine. - Free Pascal
DaysInAYear- documents the compatible declaration/result; its isolated wording typo does not define Velox.