Page 1 of 2

Date Extended

Posted: Wed Dec 10, 2014 8:34 pm
by es_91
Dear Fred,

many people use the Date library, however, you once decided to make it not support the dates before 1970. I do not know wheter this is an official limitation dictated by the creators of the Unix Time Stamp, but it is odd if you want to store birth dates, etc. that may be before 1970.

Also you must be aware of the 2038-problem.

Would it not be time, since many people now use and are common to 64 Bit, to use a 64 time stamp? I know it might seem like overkill, but the 136 years of 32 Bit are too few!

Also think about enabling the years before 1970 so that the Date library can be usefull at all. In fact, I propably had not made this post if the possible range of the 32 Bit stamp would be completely used, providing date support back until 1902.

Thanks.

Re: Date Extended

Posted: Sat Dec 13, 2014 3:21 pm
by lule
+1

Re: Date Extended

Posted: Sat Dec 13, 2014 3:46 pm
by davido
+1

Re: Date Extended

Posted: Wed Dec 16, 2015 1:12 am
by Kurzer
I also vote for extending the the date functions to 64 bit.
The limit to the year 2038 makes the current lib unusable for many applications. The limitation applies also to the DateGadget(). :(

Re: Date Extended

Posted: Wed Dec 16, 2015 8:21 am
by mhs
+1

In fact, birthdays < 1970 are not rare...

Re: Date Extended

Posted: Wed Dec 16, 2015 10:03 am
by Dude
kurzer wrote:The limitation applies also to the DateGadget(). :(
Workaround: http://www.purebasic.fr/english/viewtop ... 08#p105008

Re: Date Extended

Posted: Wed Dec 16, 2015 4:05 pm
by HanPBF
Hello,

I had the problem storing a timestamp in MS SQL Server which has 64bit-signed numbers.

The codes below are not for copy'n'paste'n'run as usual; but You don't want to use them either without checking.

Here is the mapping:

Code: Select all

Procedure.q new63bitDT(PYear=0, PMonth=0, PDay=0, PHour=0, PMinute=0, PSecond=0, PMilliSecond=0, PTick=0)
	Protected	R.q = 0
	
	Protected		Y.q		= PYear 				<< 49,
							Mo.q	= PMonth				<< 45,
							D.q		= PDay					<< 40,
							H.q		= PHour					<< 35,
							Mi.q	= PMinute				<< 29,
							S.q		=	PSecond				<< 23,
							Ms.q	= PMilliSecond	<< 13,
							Ti.q	= PTick
							
	R = Y + Mo + D + H + Mi + S + Ms + Ti
	
	;debug "P; Y:" + Str(PYear) + "; Mo:" + Str(PMonth) + "; D:" + Str(PDay) + "; H:" + Str(PHour) + ";" + 
	;			" Mi:" + Str(PMinute) + "; S:" + Str(PSecond) + "; Ms:" + Str(PMilliSecond) + "; Ti:" + Str(PTick)
	
	;debug "Y:" + Str(Y) + "; Mo:" + Str(Mo) + "; D:" + Str(D) + "; H:" + Str(H) + "; Mi:" + Str(Mi) + "; S:" + Str(S) + "; Ms:" + Str(Ms) + "; Ti:" + Str(Ti)	+ "; R:" + Str(R)

	ProcedureReturn R
EndProcedure
63bits are used -> signed! (one bit for upper or lower 0).


The following one uses ticks as re-get timestamp in one millisecond (approx. 100 possible, 8191 available):

Code: Select all

Procedure.q new63bitTS(UseTicks=#True)
	static 	LastR.q		= 0,	; store last given TS for tick check
					LastTicks	= 0
	
	
	Protected	R.q = 0,
						Now = Date(),
						Y = Year(Now),
						Mo= Month(Now),
						D	= Day(Now),
						H = Hour(Now),
						Mi= Minute(Now),
						S	= Second(Now),
						Ms= get_Milliseconds(),
						Ti=0
	
	R = new63bitDT(Y, Mo, D, H, Mi, S, Ms)
						
	if UseTicks								;debug Str(LastR) + ";" + Str(R | 8191)
		if LastR = (R | 8191)		; same until ms
			LastTicks + 1
			R = R | LastTicks
			
		else
			LastTicks=0			
		endif
	endif
	
	LastR = R | 8191
	
	ProcedureReturn R	
EndProcedure
Another procedure:

Code: Select all

Procedure.q DateTime_to63bit(P)
	Protected	R.q,
						Y  = Year(P),
						Mo = Month(P),
						D	 = Day(P),
						H  = Hour(P),
						Mi = Minute(P),
						S	 = Second(P),
						Ms = 0,
						Ti = 0
						
	Protected		qY.q	= Y 	<< 49,
							qMo.q	= Mo	<< 45,
							qD.q	= D		<< 40,
							qH.q	= H		<< 35,
							qMi.q	= Mi	<< 29,
							qS.q	=	S		<< 23,
							qMs.q	= Ms	<< 13,
							qTi.q	= Ti
							
	R = qY + qMo + qD + qH + qMi + qS + qMs + qTi
	
	ProcedureReturn R
EndProcedure
The MS SQL Server does not support static variables for the ticks nor global variables.
But with functions, it works; but the ticks have to be created from PB.
The problem came around when I tried to write 64bit from MS Access/MS Excel -> not possible...


Regards

Re: Date Extended

Posted: Wed Dec 16, 2015 4:07 pm
by HanPBF
And converting back...

Code: Select all

Procedure yearFrom63bitDT(DT.q)		
	procedureReturn (DT & (4095 << 49)) >> 49
EndProcedure

Procedure monthFrom63bitDT(DT.q)
	procedureReturn (DT & (15 << 45)) >> 45
EndProcedure

Procedure dayFrom63bitDT(DT.q)
	procedureReturn (DT & (31 << 40)) >> 40
EndProcedure

Procedure hourFrom63bitDT(DT.q)
	ProcedureReturn (DT & (31 << 35)) >> 35
EndProcedure

Procedure minuteFrom63bitDT(DT.q)
	procedureReturn (DT & (63 << 29)) >> 29
EndProcedure

Procedure secondFrom63bitDT(DT.q)
	procedureReturn (DT & (63 << 23)) >> 23
EndProcedure

Procedure.q minute_To63bit(Value.i)
	Protected R.q
	
	R = Value << 29
	
	ProcedureReturn R
EndProcedure

Procedure millisecondFrom63bitDT(DT.q)
	procedureReturn (DT & (1023 << 13)) >> 13
EndProcedure

Procedure tickFrom63bitDT(DT.q)
	procedureReturn (DT & 8191)
EndProcedure

Re: Date Extended

Posted: Wed Dec 16, 2015 7:56 pm
by normeus
+1
Leave date() library alone and create a new date64() library:

Code: Select all

AddDate64()
Date64()
Day64()
DayOfWeek64()
DayOfYear64()
FormatDate64()
Hour64()
Minute64()
Month64()
ParseDate64()
Second64()
Year64()
and don't forget visual: ( gadgets )

Code: Select all

DateGadget64()
SetGadgetState64()
SetGadgetText64()
GetGadgetState64() 
GetGadgetText64()
GetGadgetAttribute64()
SetGadgetAttribute64()
SetGadgetColor64()
GetGadgetColor64()
I think it will be easier to create a new library instead of breaking old code that works.
I know if you search the forums you'll find bits and pieces of all this stuff but if you are new to PureBasic you dont want to run around looking for a date library that handles < 1970. Adding this would make PureBasic a more accesible compiler.

Re: Date Extended

Posted: Thu Dec 17, 2015 1:30 am
by kpeters58
+1 !!!!

Re: Date Extended

Posted: Thu Dec 17, 2015 5:36 am
by fromVB
Any cross-platform way to solve this?

<1970 and >2038 :?:

The available workarounds do not include the date gadget.

Re: Date Extended

Posted: Thu Dec 17, 2015 9:27 am
by davido
Would this masterpiece by wilbert be of interest?
http://www.purebasic.fr/english/viewtop ... 31#p421423

Re: Date Extended

Posted: Thu Dec 17, 2015 10:42 am
by Ulix
Translated by google.

+ 1 For a cross-platform solution!

And how to use dates before our era? :cry:

Examples date for ancient history (wiki source) :
Around 3800 BC. - Copper Age.
Around 2500 BC. - Bronze Age.
Around 1200 BC. - Iron Age.
Around 3300 BC. - Sumerian civilization of Mesopotamia.
Around 3100 BC. - unification of Egypt by Narmer.
Around 2500 BC. - height of the Indus civilization.


And how to use geological dates? :cry: :x :x


En Français

+1 Pour une solution multiplate-formes !

Et comment traiter les dates avant notre ére ? :cry:

Exemples de date pour l'histoire antique (source wiki) :
Vers 3800 av. J.-C. - âge du cuivre.
Vers 2500 av. J.-C. - âge du bronze.
Vers 1200 av. J.-C. - âge du fer.
Vers 3300 av. J.-C. - la civilisation sumérienne de Mésopotamie.
Vers 3100 av. J.-C. - unification de l’Égypte par Narmer.
Vers 2500 av. J.-C. - apogée de la civilisation de l’Indus.

Et comment traiter les dates géologiques ? :cry: :x :x

Re: Date Extended

Posted: Thu Dec 17, 2015 4:48 pm
by Kurzer
davido wrote:Would this masterpiece by wilbert be of interest?
http://www.purebasic.fr/english/viewtop ... 31#p421423
Yes thanks, davido. I have my hands on it already. ;)

Re: Date Extended

Posted: Thu Dec 17, 2015 7:15 pm
by GPI
Ulix wrote:And how to use dates before our era? :cry:
Simple: Use a String :) or when you only save the year use an integer. The time and date measuring has changed during our history. So it doesn't make sence to use our current system with such old dates.

btw. DateQ would make more sence then Date64 :)