Page 1 of 1

Update of the Date library

Posted: Wed Apr 11, 2012 3:03 pm
by Mesa
An Update of the Date library with calculation on dates.


See my post here : (all OS)
http://www.purebasic.fr/english/viewtop ... 12&t=49665

in french
http://www.purebasic.fr/french/viewtopi ... =6&t=12710

Thanx.

Mesa.

Re: Update of the Date library

Posted: Wed Apr 11, 2012 6:26 pm
by IdeasVacuum
+1 :mrgreen:

Re: Update of the Date library

Posted: Wed Apr 11, 2012 10:19 pm
by Seymour Clufley
I think we definitely need a date library that can handle a much greater range than 1970-2038.

Re: Update of the Date library

Posted: Wed May 09, 2012 12:20 am
by ozzie
+1. Just got caught out with Date(), trying to use a date in 1944 and finding Date() returned Jan 1 1970 :(

Re: Update of the Date library

Posted: Wed May 09, 2012 8:03 am
by jesperbrannmark
Oh yes. That would be *awsome*. Please also if this is done include the dategadget update and calendargadget (in Win it cant do before 1970 unless using bad hacks. in mac it does before, but could probably also need some pampering)

Re: Update of the Date library

Posted: Wed Jun 27, 2012 6:03 am
by c4s
ozzie wrote:+1. Just got caught out with Date(), trying to use a date in 1944 and finding Date() returned Jan 1 1970 :(
Me too! It's really annoying if you have to work with e.g. birthdays...

I don't think you have to change the existing date library though. Just add a new "DateQ" lib with exactly the same functionality (maybe with some kind of an offset?!) and there wouldn't even be any issue with backward compatibility etc!

Re: Update of the Date library

Posted: Mon Apr 08, 2013 7:50 pm
by Michael Vogel
I would be happy, if the available range for valid dates would be increased to support 1970 to 2106 or so. This would be possible, if the used long numbers would be used like unsigned values.

Code: Select all

;a.l

a=Date(2038,1,19,3,14,7)
Debug a
Debug FormatDate("%yyyy,%mm,%dd,%hh,%ii,%ss",a)

Debug "· · · · · · · · · · · ·"
a+1
Debug a
Debug FormatDate("%yyyy,%mm,%dd,%hh,%ii,%ss",a)

Re: Update of the Date library

Posted: Tue Apr 09, 2013 9:49 pm
by Ulix
google translation!

+1, +10, +100 ....

Already ask! (and I still cry over and over again) :cry:

Do we not say: hope is alive! :mrgreen:

Ulix

Re: Update of the Date library

Posted: Wed Apr 10, 2013 1:55 pm
by Michael Vogel
Michael Vogel wrote:

Code: Select all

a=Date(2038,1,19,3,14,7)
Debug a
Debug FormatDate("%yyyy,%mm,%dd,%hh,%ii,%ss",a)
Interestingly, the code above presents a correct result for the (first) date when using PB5.0, but not with 5.11 :shock: So I am not sure, if the following routines will work for all PB versions (I didn't find any problems for now):

Code: Select all

; Define

	; Date Functions - Version 1.o by Michael Vogel
	; ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
	; should work for the range 1970/1/1-2099/12/31

	#DaySeconds=86400

	Procedure.l _Seconds(Date.l)

		Date%#DaySeconds
		If Date<0
			ProcedureReturn (109696+Date)%#DaySeconds;	adapt seconds
		Else
			ProcedureReturn Date
		EndIf

	EndProcedure
	Procedure.l _Days(Date.l)

		If Date<0
			Date=(109697+Date)/#DaySeconds;					adapt seconds
			ProcedureReturn Date+49708;						change direction
		Else
			Date/#DaySeconds
			ProcedureReturn Date
		EndIf

	EndProcedure
	Procedure Day_(Date.l)

		If Date<0
			Date-#DaySeconds*24837;	68 years earlier
		EndIf
		ProcedureReturn Day(Date)

	EndProcedure
	Procedure Month_(Date.l)

		If Date<0
			Date-#DaySeconds*24837;	68 years earlier
		EndIf
		ProcedureReturn Month(Date)

	EndProcedure
	Procedure Year_(Date.l)

		If Date<0
			ProcedureReturn Year(Date-#DaySeconds*24837)+68;	68 years earlier
		Else
			ProcedureReturn Year(Date)
		EndIf

	EndProcedure
	Procedure Hour_(Date.l)
		ProcedureReturn Hour(_Seconds(Date))
	EndProcedure
	Procedure Minute_(Date.l)
		ProcedureReturn Minute(_Seconds(Date))
	EndProcedure
	Procedure Second_(Date.l)
		ProcedureReturn Second(_Seconds(Date))
	EndProcedure

	Procedure Date_(Year,Month,Day,Hour,Minute,Second)

		Protected n

		n=Date(Year,Month,Day,Hour,Minute,Second)
		If n<0 And Year>2037 And Year<2100
			n=Date(Year-68,Month,Day,Hour,Minute,Second)-2149050496
		EndIf

		ProcedureReturn n

	EndProcedure
	Procedure.s FormatDate_(Mask$,Date.l)

		Mask$=ReplaceString(Mask$,"%yyyy",RSet(Str(Year_(Date)),4,"0"))
		Mask$=ReplaceString(Mask$,"%mm",RSet(Str(Month_(Date)),2,"0"))
		Mask$=ReplaceString(Mask$,"%dd",RSet(Str(Day_(Date)),2,"0"))
		Mask$=ReplaceString(Mask$,"%hh",RSet(Str(Hour_(Date)),2,"0"))
		Mask$=ReplaceString(Mask$,"%ii",RSet(Str(Minute_(Date)),2,"0"))
		Mask$=ReplaceString(Mask$,"%ss",RSet(Str(Second_(Date)),2,"0"))

		ProcedureReturn Mask$

	EndProcedure

; EndDefine

Procedure DebugDate(a.l)
	
	If 0
		Debug FormatDate_("%yyyy-%mm-%dd  %hh:%ii:%ss",a)+" ~ "+Str(a)+"/x"+Hex(a,#PB_Long)+" ~  day: "+Str(_Days(a))+" ~ sec: "+Str(_Seconds(a))
	Else
		Debug FormatDate_("%yyyy-%mm-%dd  %hh:%ii:%ss",a)
	EndIf

EndProcedure


a.l

a=Date(2038,1,18,23,59,59);			Classic 'Date' function (PB Version 5.11)
DebugDate(a)
a+1
DebugDate(a)

a+86399
DebugDate(a)
a+1
DebugDate(a)

a+86399
DebugDate(a)
a+1
DebugDate(a)

For y=2038 To 2040
	a=Date_(y,2,28,1,2,3);			New 'Date' function...
	Debug FormatDate_("*%yyyy*",a)
	For i=1 To 3
		DebugDate(a)
		a+#DaySeconds
	Next i
Next y
PS: still would like to see something like that within PB :wink:

Re: Update of the Date library

Posted: Thu Apr 11, 2013 12:37 am
by BorisTheOld
Many applications require the ability to work with long time spans. We get around PB's restrictive Date library by using the FreeBasic date functions wrapped in a small dynamic library -- "FBdate.so" for Linux, and "FBdate.dll" for Windows.

This is a quick and easy technique that can be used for getting around the problem of PB not having features that exist in other Basic dialects. We do this for file sharing, dates, and various other language features.

We will eliminate these libraries as PB is upgraded to include the missing features.