To set the Gadget Calendar to an "old" date You would need a procedure like this:
Code: Select all
Procedure.q SetDate64(gadget, year, month, day, hour=0, minute=0, second=0)
Protected sTime.SYSTEMTIME
Protected fTime.FILETIME
sTime\wYear = year
sTime\wMonth = month
sTime\wDay = day
sTime\wHour = hour
sTime\wMinute = minute
sTime\wSecond = second
SystemTimeToFileTime_(sTime, @fTime)
FileTimeToSystemTime_(fTime, @sTime)
SendMessage_(GadgetID(gadget), #DTM_SETSYSTEMTIME, #GDT_VALID, sTime)
EndProcedure
If OpenWindow(0, 0, 0, 250, 200, "CalendarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CalendarGadget(0, 10, 10, 230, 180)
Setdate64(0,1949,12,12) ; This is and OLD Date!
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
now if you think thats easy enough get the full date64 library from german forums ( it might be here too but I havent looked for it )
http://www.purebasic.fr/german/viewtopi ... 20#p334520
This is a module you can include in your programs. you'll need to add these procedures to handle gadgets:
first inside the declare module just before EndDeclareModule add
Code: Select all
Declare.q LocalDateAsUTC64() ; extra function to get local time
;- FUNCTIONS FOR GADGETS THAT USE date()
Declare.q SetDate64(gadget, year, month, day, hour, minute, second)
Declare SetDateQ64(gadget,qt.q)
Declare GetDate64(gadget,part=#PB_Date_Year)
Declare.q GetDateQ64(gadget)
now at the end of the module add these procedures:
Code: Select all
Procedure.q SetDate64(gadget, year, month, day, hour, minute, second)
Protected sTime.SYSTEMTIME
Protected fTime.FILETIME
sTime\wYear = year
sTime\wMonth = month
sTime\wDay = day
sTime\wHour = hour
sTime\wMinute = minute
sTime\wSecond = second
SystemTimeToFileTime_(sTime, @fTime)
FileTimeToSystemTime_(fTime, @sTime)
SendMessage_(GadgetID(gadget), #DTM_SETSYSTEMTIME, #GDT_VALID, sTime)
EndProcedure
Procedure SetDateQ64(gadget,qt.q)
Protected sTime.FILETIME
qt = qt * #HundredNanosecondsInOneSecond + #HundredNanosecondsFrom_1Jan1601_To_1Jan1970
FileTimeToSystemTime_(@qt,sTime)
SendMessage_(GadgetID(gadget), #DTM_SETSYSTEMTIME, #GDT_VALID, sTime)
EndProcedure
Procedure GetDate64(gadget,part=#PB_Date_Year)
Protected sTime.SYSTEMTIME
Protected fTime.FILETIME
Protected result
SendMessage_(GadgetID(gadget),#DTM_GETSYSTEMTIME,#GDT_VALID,sTime)
SystemTimeToFileTime_(sTime,@fTime)
FileTimeToSystemTime_(fTime,@sTime)
Select part
Case #PB_Date_Day
result=sTime\wDay
Case #PB_Date_Month
result=sTime\wMonth
Case #PB_Date_Hour
Default
result=sTime\wYear
EndSelect
ProcedureReturn result
EndProcedure
Procedure.q GetDateQ64(gadget)
Protected sTime.SYSTEMTIME
Protected fTime.FILETIME
SendMessage_(GadgetID(gadget),#DTM_GETSYSTEMTIME,#GDT_VALID,sTime)
SystemTimeToFileTime_(sTime,@fTime)
FileTimeToSystemTime_(fTime,@sTime)
ProcedureReturn (PeekQ(@fTime) - #HundredNanosecondsFrom_1Jan1601_To_1Jan1970) / #HundredNanosecondsInOneSecond
EndProcedure
Procedure.q LocalDateAsUTC64()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Protected.SYSTEMTIME st
Protected.FILETIME ft
GetSystemTime_(@st)
SystemTimeToFileTime_(@st, @ft)
ProcedureReturn (PeekQ(@ft) - #HundredNanosecondsFrom_1Jan1601_To_1Jan1970) / #HundredNanosecondsInOneSecond
CompilerElse
ProcedureReturn time_(0)
CompilerEndIf
EndProcedure
after this you should be able to handle OLD dates, NEW dates, mortgage dates ( 50 years! of debt for some ) or day you were born ( not this century for me ) etc...
I know it craps out on dates before 1400's in wester calendar but I am happy if it gets 1492 to 2400 right.
Yes it should be native to the language but it is not.
Norm.