From b3b93191002f92b19c069b9815a8261d6edbc5ec Mon Sep 17 00:00:00 2001 From: beware Date: Wed, 15 Aug 2012 14:23:43 +0000 Subject: [PATCH] added ISO style date/time and UTC date/time strings, add comments to document output of time strings git-svn-id: file:///svnroot/lcore/trunk@119 b1de8a11-f9be-4011-bde0-cc7ace90066a --- btime.pas | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/btime.pas b/btime.pas index e0b0c4b..2a4b267 100644 --- a/btime.pas +++ b/btime.pas @@ -50,8 +50,10 @@ procedure gettimezone; procedure timehandler; procedure init; -function timestring(i:tunixtimeint):string; -function timestrshort(i:tunixtimeint):string; +function timestring(i:tunixtimeint):string; // Wednesday August 15 2012 -- 16:21:09 +02:00 +function timestrshort(i:tunixtimeint):string; // Wed Aug 15 16:21:09 2012 +function timestriso(i:tunixtimeint):string; // 2012-08-15 16:21:09 +function timestrisoutc(i:float):string; // 2012-08-15T14:21:09.255553Z {$ifdef win32} function unixtimefloat_systemtime:float; @@ -688,6 +690,40 @@ begin timezonestr; end; +function timestriso(i:tunixtimeint):string; +var + y,m,d,h,min,sec,ms:word; + t:tdatetime; +begin + t := unixtoole(i+timezone); + decodedate(t,y,m,d); + decodetime(t,h,min,sec,ms); + result := inttostr(y)+'-'+inttostr(m div 10)+inttostr(m mod 10)+'-'+inttostr(d div 10)+inttostr(d mod 10)+' '+inttostr(h div 10)+inttostr(h mod 10)+':'+inttostr(min div 10)+inttostr(min mod 10)+':'+inttostr(sec div 10)+inttostr(sec mod 10); +end; + +function timestrisoutc(i:float):string; +var + y,m,d,h,min,sec,ms:word; + t:tdatetime; + fr:float; +begin + t := unixtoole(i); + decodedate(t,y,m,d); + decodetime(t,h,min,sec,ms); + result := inttostr(y)+'-'+inttostr(m div 10)+inttostr(m mod 10)+'-'+inttostr(d div 10)+inttostr(d mod 10)+'T'+inttostr(h div 10)+inttostr(h mod 10)+':'+inttostr(min div 10)+inttostr(min mod 10)+':'+inttostr(sec div 10)+inttostr(sec mod 10); + fr := frac(i); + + result := result + '.'+ + inttostr(trunc(fr*10) mod 10)+ + inttostr(trunc(fr*100) mod 10)+ + inttostr(trunc(fr*1000) mod 10)+ + inttostr(trunc(fr*10000) mod 10)+ + inttostr(trunc(fr*100000) mod 10)+ + inttostr(trunc(fr*1000000) mod 10)+'Z'; + +end; + + procedure init; begin {$ifdef win32}timebeginperiod(1);{$endif} //ensure stable unchanging clock -- 2.30.2