[Pas2js] DateTimeToIso8601 issue

warleyalex warleyalex at yahoo.com.br
Mon Nov 25 15:05:24 CET 2019


mORMot server computes a nounce client and uses the NowToIso8601 method to
compute the nonce, so
apparently, this method in pas2js returns this format:
NowToIso8601();  //-->  2019-11-2509:5809:58:05

but we want this expected result:
2019-11-25T09:58:09

I could find a way to get this format, hum I had to edit The SysUtils unit |
the function FormatDateTime and modify to:

            'T': if Count = 1 then
	//	   StoreFormat(ShortTimeFormat, Nesting+1, True)
               StoreString('T')
                 else
	          StoreFormat(LongTimeFormat, Nesting+1, True);


[code]
function NowToIso8601: string;
begin
  result := DateTimeToIso8601(Now);
end;

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{,DateTimeZone.UTC}) else
  if trunc(Value)=0 then
    result := FormatDateTime('Thh:nn:ss',Value{,DateTimeZone.UTC}) else
    result :=
FormatDateTime('yyyy-mm-ddThh:nn:ss',Value{,DateTimeZone.UTC});
end;   
[/code]




--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list