From 400bf62abaf51322b7426ec2845a8e60340efa65 Mon Sep 17 00:00:00 2001 From: bigchimp Date: Fri, 24 Jan 2014 10:32:23 +0000 Subject: [PATCH] * OpenDocument/OpenOffice/LibreOffice date/time read fix; code adapted from curtisnewton, thanks a lot! Fixes mantis issue #25585 git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2890 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/fpsgrid/fpsgrid.lpi | 118 ++++++++++-------- components/fpspreadsheet/fpsopendocument.pas | 18 ++- 2 files changed, 80 insertions(+), 56 deletions(-) diff --git a/components/fpspreadsheet/examples/fpsgrid/fpsgrid.lpi b/components/fpspreadsheet/examples/fpsgrid/fpsgrid.lpi index b433c01a4..e40b049ad 100644 --- a/components/fpspreadsheet/examples/fpsgrid/fpsgrid.lpi +++ b/components/fpspreadsheet/examples/fpsgrid/fpsgrid.lpi @@ -38,7 +38,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -59,19 +59,18 @@ - + - - + @@ -80,11 +79,11 @@ - + - + @@ -129,144 +128,155 @@ - + - + - + - + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - + + + + + + + + - + - + - - + + diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 1af762647..26d01ff4b 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -275,11 +275,25 @@ end; procedure TsSpreadOpenDocReader.ReadDate(ARow: Word; ACol : Word; ACellNode : TDOMNode); var - Value: String; dt:TDateTime; + Value: String; + Fmt : TFormatSettings; + PointPos : integer; begin + // Format expects ISO 8601 type date string + fmt.ShortDateFormat:='yyyy-mm-dd'; + fmt.DateSeparator:='-'; + fmt.LongTimeFormat:='hh:nn:ss'; + fmt.TimeSeparator:=':'; Value:=GetAttrValue(ACellNode,'office:date-value'); - dt:=StrToDate(Value,'yyyy-mm-dd','-'); + Value:=StringReplace(Value,'T',' ',[rfIgnoreCase,rfReplaceAll]); + // Strip milliseconds? + PointPos:=Pos('.',Value); + if (PointPos>1) then + begin + Value:=Copy(Value,1,PointPos-1); + end; + dt:=StrToDateTime(Value,Fmt); FWorkSheet.WriteDateTime(Arow,ACol,dt); end;