View Issue Details

IDProjectCategoryView StatusLast Update
0034405FPCRTLpublic2018-10-10 10:39
ReporterwpAssigned ToMarco van de Voort 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product VersionProduct Build 
Target VersionFixed in Version3.3.1 
Summary0034405: ScanDateTime failing if format string ends with quotes
DescriptionThe function "ScanDateTime" is the inversion of "FormatDateTime" and accepts a format string to specify the data format. For the ISO date format 'yyyy-mm-dd"T"hh:nn:ss"Z"', however, it fails with the error:

  Project project1 raised exception class 'EConvertError' with message:
  Couldn't match entire pattern string. Input too short at pattern position 24.

Steps To ReproduceThis is a simple project to show the bug:

program Project1;

{$mode objfpc}{$H+}

uses
  DateUtils;

var
  dt: TDateTime;
begin
  dt := ScanDateTime('yyyy-mm-dd"T"hh:nn:ss"Z"', '2008-11-09T17:36:59Z');
  WriteLn(dt);
end.
Additional InformationThe issue apparently is in the trailing quoted character and in particular in the final quotation character. If that is dropped then the expression is accepted:

  dt := ScanDateTime('yyyy-mm-dd"T"hh:nn:ss"Z', '2008-11-09T17:36:59Z');
TagsNo tags attached.
Fixed in Revision39910
FPCOldBugId
FPCTarget
Attached Files
  • dateutil.inc.patch (618 bytes)
    Index: packages/rtl-objpas/src/inc/dateutil.inc
    ===================================================================
    --- packages/rtl-objpas/src/inc/dateutil.inc	(revision 39909)
    +++ packages/rtl-objpas/src/inc/dateutil.inc	(working copy)
    @@ -2616,7 +2616,7 @@
                     matchchar(ptrn[pind]);
                 end;
          end;
    -   if (pind<plen) and (plen>0) and (ptrn[plen-1]<>#9) then  // allow omission of trailing whitespace
    +   if (pind<plen) and (plen>0) and not (ptrn[plen-1] in [#9, '"']) then  // allow omission of trailing whitespace
          RaiseException(format(SFullpattern,[poffs+pind+1]));
     end;
     
    
    dateutil.inc.patch (618 bytes)

Activities

wp

2018-10-10 09:21

reporter  

dateutil.inc.patch (618 bytes)
Index: packages/rtl-objpas/src/inc/dateutil.inc
===================================================================
--- packages/rtl-objpas/src/inc/dateutil.inc	(revision 39909)
+++ packages/rtl-objpas/src/inc/dateutil.inc	(working copy)
@@ -2616,7 +2616,7 @@
                 matchchar(ptrn[pind]);
             end;
      end;
-   if (pind<plen) and (plen>0) and (ptrn[plen-1]<>#9) then  // allow omission of trailing whitespace
+   if (pind<plen) and (plen>0) and not (ptrn[plen-1] in [#9, '"']) then  // allow omission of trailing whitespace
      RaiseException(format(SFullpattern,[poffs+pind+1]));
 end;
 
dateutil.inc.patch (618 bytes)

wp

2018-10-10 09:21

reporter   ~0111351

The attached patch fixes the issue.

wp

2018-10-10 10:39

reporter   ~0111353

Thanks

Issue History

Date Modified Username Field Change
2018-10-10 07:22 wp New Issue
2018-10-10 09:21 wp File Added: dateutil.inc.patch
2018-10-10 09:21 wp Note Added: 0111351
2018-10-10 10:24 Marco van de Voort Fixed in Revision => 39910
2018-10-10 10:24 Marco van de Voort Status new => resolved
2018-10-10 10:24 Marco van de Voort Fixed in Version => 3.3.1
2018-10-10 10:24 Marco van de Voort Resolution open => fixed
2018-10-10 10:24 Marco van de Voort Assigned To => Marco van de Voort
2018-10-10 10:39 wp Note Added: 0111353
2018-10-10 10:39 wp Status resolved => closed