|Posted by:||Nathan Sutcliffe (nsutclif…@speedlinesolutions.com)|
|Date:||Tue, 14 Aug 2007|
I've been using this class to do conversions between TDateTime and dates in ISO 8601 format.
First, if anyone ever removes the "to do" exception from ValidateTimeStamp, the TimeStampToDateTime should use ATimeStamp.DayOfMonth instead of ATimeStamp.Day.
Second, there is a bug in AddMonths that affects the parsing of ISO 8601 dates (and probably other operations too). If you use TIdDateTimeStamp.SetFromISO8601 to parse the date 2007-07-29, you'll end up with the date 2007-08-01 instead. It looks like AddMonths works by adding the number of days in each month to FDay. The problem is that the second time through the loop, it adds March's days instead of February's. Here's what I did to try to fix the problem:
i : Integer;
i := ANumber div IdMonthsInYear;
Dec(ANumber, i * IdMonthsInYear);
// Fixed by SpeedLine
i := MonthOfYear;
while ANumber > 0 do begin
if i = 12 then begin
i := 1;
if (i = 2) and (IsLeapYear) then begin
AddDays(IdDaysInMonth[i] + 1);
end else begin
Inc( i );
I don't know if this would cause any bad side effects in parts of the class I don't use, but it does fix the ISO 8601 parsing.