Update of the Date library
Update of the Date library
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.
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.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Update of the Date library
+1 

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: Update of the Date library
I think we definitely need a date library that can handle a much greater range than 1970-2038.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
-
- Enthusiast
- Posts: 443
- Joined: Sun Apr 06, 2008 12:54 pm
- Location: Brisbane, Qld, Australia
- Contact:
Re: Update of the Date library
+1. Just got caught out with Date(), trying to use a date in 1944 and finding Date() returned Jan 1 1970 

-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Update of the Date library
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
Me too! It's really annoying if you have to work with e.g. birthdays...ozzie wrote:+1. Just got caught out with Date(), trying to use a date in 1944 and finding Date() returned Jan 1 1970
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!
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
- Michael Vogel
- Addict
- Posts: 2798
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Update of the Date library
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
google translation!
+1, +10, +100 ....
Already ask! (and I still cry over and over again)
Do we not say: hope is alive!
Ulix
+1, +10, +100 ....
Already ask! (and I still cry over and over again)

Do we not say: hope is alive!

Ulix
- Michael Vogel
- Addict
- Posts: 2798
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Update of the Date library
Interestingly, the code above presents a correct result for the (first) date when using PB5.0, but not with 5.11Michael Vogel wrote:Code: Select all
a=Date(2038,1,19,3,14,7) Debug a Debug FormatDate("%yyyy,%mm,%dd,%hh,%ii,%ss",a)

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

-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: Update of the Date library
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.
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.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan