OptEncodeDateW Function |
Unit
QESBPCSDateTime
Declaration
Function OptEncodeDateW(Year, Month, Day: Word): TDateTime;
Description
If you want even faster results and are happy to use Integers than use the slightly slower OptEncodeDateI.
Category
Date/Time Conversion RoutinesImplementation
function OptEncodeDateW (Year, Month, Day: Word): TDateTime; var DayTable: PDayTable; begin if (Month < 1) or (Month > 12) then raise EConvertError.Create (rsInvalidMonth); DayTable := @MonthDays [IsLeapYear (Year)]; if (Day <= DayTable^ [Month]) and (Year >= 1) and (Year < 10000) and (Month < 13) and (Day > 0) then begin if Month > 2 then Dec (Month, 3) else if (Month > 0) then begin Inc (Month, 9); Dec (Year); end else // Month <= 0 raise EConvertError.Create (rsInvalidDate); Result := (146097 * (Year div 100)) shr 2 + (1461 * (Year - 100 * (Year div 100))) shr 2 + (153 * Month + 2) div 5 + Day - 693900; end else raise EConvertError.Create (rsInvalidDate); End; |
|