Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DateTime Native Format?
Message
De
01/10/2016 09:49:42
 
 
À
01/10/2016 04:56:39
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01641508
Message ID:
01641552
Vues:
43
>>You could convert to currency as the number of digits for the integer part of currency is 14.9649
>>
>>?log10($922337203685477)
>>
>>
>>But that is also taking 8 bytes - as the DateTime field
>
>Currency is a double integer and datetime is two integers.


Actually, I believe a DateTime is a double, where the seconds are stored in the fractional part

>Now there's some waste in there, as the seconds are stored as milliseconds, but Fox had trouble with those (in VFP5 it was pretty much impossible to compare datetimes as one would contain milliseconds and the other wouldn't but they'd look the same until you calculate the difference between them) so nowadays milliseconds are not stored at all. So there are only 86400 values to store in an integer. Also, out of 0xffffffff available days, we're looking at a range of, say, a century at most (unless your app does archaeology or astronomy), so it's about 36000 days. So, assuming we're dealing only with this limited precision and range, here it is:
>
>
**************************************************
>*-- Class:        app (m:\rad\vfprc\app.vcx)
>*-- ParentClass:  custom
>*-- BaseClass:    custom
>*-- Time Stamp:   07/08/06 11:52:02 AM
>
>* test code:
>
>o=createobject("t2s")
>lcD=o.t2s(datetime())
>?lcD, o.s2t(lcd)
>Define Class t2s As Custom
>
>	Name = "app"
>
>	starttime = { :}
>
>*-- need this for t2s and others.
>	trnN2S="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ()+-/#$%!"
>
>
>	Procedure Init
>	This.starttime=Datetime()
>
>
>
>*---------------------------------------------------
>	Procedure t2s(tt)
>	Local nDaynr, nSecs
>*-- dn 15/06/06
>	nDaynr=Ttod(tt)-{^1980-01-01}
>	nSecs=Int(tt-Dtot(Ttod(tt)))
>	Return This.n2s(nDaynr)+"_"+This.n2s(nSecs,3)
>*---------------------------------------------------
>	Procedure s2t(c)
>*-- dn 15/06/06
>	Local c, o, N, i, l, cCRS
>	cDate=Getwordnum(c,1,"_")
>	cTime=Getwordnum(c,2,"_")
>	dDate={^1980-01-01}+This.s2n(cDate)
>	tDt=Dtot(dDate)+This.s2n(cTime)
>	Return tDt
>
>
>*--------------------------------------------------- broj u string
>	Procedure n2s(tNR, nLen)
>	Local nMod, numdat, sl
>	nMod=Len(This.trnN2S)
>	numdat=tNR
>	sl=""
>	Do While numdat>0
>		ns=numdat%nMod
>		sl=Substr(This.trnN2S,ns+1,1)+sl
>		numdat=Int(numdat/nMod)
>	Enddo
>	If !Empty(nLen) And Len(sl)<nLen
>		sl=Padl(sl, nLen, Left(This.trnN2S,1))
>	Endif
>	Retu sl
>
>*--------------------------------------------------- string u broj
>	Procedure s2n(c)
>	Local nMod, N
>	nMod=Len(This.trnN2S)
>	N=0
>	For i= 1 To Len(c)
>		N = N*nMod+Atc(Substr(c, i, 1), This.trnN2S) -1
>	Endfor
>	Retu N
>
>Enddefine
>
>
>Adding more characters to the coding string may actually shorten the result even more - like adding lowercase, accented etc. Also, using fixed lengths for parts may remove the underscore (as the lengths of the date and seconds part will be known in advance). Initially, my coding string was much shorter, because I was also using this to generate filenames - had an old digital camera which didn't have continuous counting, so every time I wipe the card it starts from img_0001.jpg, but at least it stored the datetimes somewhere, so I dug that out and renamed the files as per those internal timestamps. The result had to conform to file naming conventions, so I couldn't add lowercase or punctuation to it - had just uppercase and digits, and the resulting string was, guess what, 8 bytes :). But at least it was printable.
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform