You are not logged in.
Hi Arnaud today i found a bug in SCPS.pas
In FormatDateTime you use yyyy-mm-ddThh:nn:ss where the T would be expanded like t to Clocktime in ShortTimeFormat
Patch:
function DateTimeToIso8601(Value: TDateTime): string;
begin // e.g. YYYY-MM-DD Thh:mm:ss or YYYY-MM-DDThh:mm:ss
if Value<=0 then
result := '' else
if frac(Value)=0 then
result := FormatDateTime('yyyy-mm-dd',Value) else
if trunc(Value)=0 then
result := 'T' + FormatDateTime('hh:nn:ss',Value) else
result := FormatDateTime('yyyy-mm-dd',Value) + 'T' + FormatDateTime('hh:nn:ss',Value);;
end;
Rad Studio 12.1 Santorini
Offline
patch for SynCrossPlatformJSON:
function DateTimeToIso8601(Value: TDateTime): string;
begin // e.g. YYYY-MM-DD Thh:mm:ss or YYYY-MM-DDThh:mm:ss
if Value=0 then
result := '' else
if frac(Value)=0 then
result := FormatDateTime('yyyy"-"mm"-"dd',Value) else
if trunc(Value)=0 then
result := '"T' + FormatDateTime('"hh":"nn":"ss',Value) else
result := FormatDateTime('yyyy"-"mm"-"dd"',Value) + 'T' + FormatDateTime('"hh":"nn":"ss',Value);
end;
Rad Studio 12.1 Santorini
Offline
I found one place with FormatDateTime in mormot.pas where i don't know if customformat can contain 't'.
If this could be the case the output will be malformatted.
Last edited by itSDS (2015-03-12 11:50:49)
Rad Studio 12.1 Santorini
Offline
Are you talking about TSQLTable.ExpandAsString?
In this method, the format is the raw value, to be customized in the end user application as expected by the UI.
So I guess it is safe as such.
About SynCrossPlatformSpecific.pas, this function is specific to SMS, and in SMS RTL, the FormatDateTime() function does not have any process about 'T' so there should be no problem.
But for SynCrossPlatformJSON.pas, I guess that since we use "T" in the format string, it will be written directly (thanks to the double quotes), so there is no issue with the current implementation, isn't it?
Offline
1. yes i made a textsearch for FormatDateTime and there it is used.
2. OK - I modified SynCrossPlatformSpecific.pas to use DateTimeToIso8601 for windows - that's the reason i get that error.
But this function is needed cause it is in wrapper generated code for a record using TDateTime as field.
3. I do not know that. But if "mm" is transformed then "T" would also be transformed.
Rad Studio 12.1 Santorini
Offline
hm... you're right
I just checked it and a T in "T" will be printed as T
You only have to add the " to the t in "SCPS".pas
Last edited by itSDS (2015-03-12 17:47:36)
Rad Studio 12.1 Santorini
Offline
But nevertheless there is a problem with SynCrossPlatformSpecific. Let me explain:
I have a interfacefunction with a record as parameter.
RExample = packed record
textvalue : String;
datevalue : TDateTime;
....
end;
Now i create my crossplatformwrapper and it contains this 2 function:
function Variant2RExample(_variant: variant): RExample;
begin
result.textvalue := _variant.textvalue;
result.datevalue := Iso8601ToDateTime(_variant.datevalue);
end;
function RExample2Variant(const _record: RExample): variant;
var
res: TJSONVariantData;
begin
res.Init;
res.SetPath('textvalue',_record.textvalue);
res.SetPath('datevalue',DateTimeToIso8601(_record.datevalue));
result := variant(res);
end;
If i compile this with your version the both Date - Function are missing -> Compiler Error.
==> We need both function also for Windows (and Firemonkey)
I modified my Version and can compile. I send it via email to you.
Rad Studio 12.1 Santorini
Offline
I do not understand exactly.
AFAIK Iso8601ToDateTime and DateTimeToIso8601 functions are defined in SynCrossPlatformJSON.pas, which is part of the generated mORMotClient.pas unit.
From what you sent to me, it sounds like if your SynCrossPlatform*.pas units and the *.mustache templates may be a bit outdated.
Are you using the latest revision?
Offline
Tyvm arnaud - now i understand.
Looking for the date functions i found the first occurence in SynCrossPlatformSpecific.pas and thougth you forgot to declare it for Windows. Didn't take a look in SynCrossPlatformJSON.
I have changed the units now and it works fine again - without my "Patch"
Rad Studio 12.1 Santorini
Offline