OptEncodeDateI Function |
Unit
QESBPCSDateTime
Declaration
Function OptEncodeDateI(Year, Month, Day: Integer): TDateTime;
Description
If you need Words rather than Integers use the slightly slower OptEncodeDateW.
Category
Date/Time Conversion RoutinesImplementation
function OptEncodeDateI (Year, Month, Day: Integer): 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 + IntToStr (Year) + '-' + IntToStr (Month) + '-' + IntToStr (Day)); End; |
|