Date Extended

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
es_91
Enthusiast
Enthusiast
Posts: 242
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Date Extended

Post 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.
lule
User
User
Posts: 29
Joined: Fri Sep 17, 2010 8:22 pm

Re: Date Extended

Post by lule »

+1
Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy.
PureBasic 6.02 LTS (Linux - x64)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Date Extended

Post by davido »

+1
DE AA EB
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Date Extended

Post 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(). :(
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
mhs
Enthusiast
Enthusiast
Posts: 101
Joined: Thu Jul 02, 2015 4:53 pm
Location: Germany
Contact:

Re: Date Extended

Post by mhs »

+1

In fact, birthdays < 1970 are not rare...
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Date Extended

Post by Dude »

kurzer wrote:The limitation applies also to the DateGadget(). :(
Workaround: http://www.purebasic.fr/english/viewtop ... 08#p105008
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

Re: Date Extended

Post 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
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

Re: Date Extended

Post 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
normeus
Enthusiast
Enthusiast
Posts: 415
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Date Extended

Post 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.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Date Extended

Post by kpeters58 »

+1 !!!!
PB 5.73 on Windows 10 & OS X High Sierra
fromVB
User
User
Posts: 81
Joined: Sun Jul 29, 2012 2:27 am

Re: Date Extended

Post by fromVB »

Any cross-platform way to solve this?

<1970 and >2038 :?:

The available workarounds do not include the date gadget.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Date Extended

Post by davido »

Would this masterpiece by wilbert be of interest?
http://www.purebasic.fr/english/viewtop ... 31#p421423
DE AA EB
Ulix
User
User
Posts: 48
Joined: Wed Jan 23, 2008 12:45 pm
Location: France, Montpellier

Re: Date Extended

Post 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
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Date Extended

Post 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. ;)
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Date Extended

Post 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 :)
Post Reply