Set-/GetGadgetState on DateGadget without time
Posted: Wed Nov 22, 2023 11:15 pm
I ran into a minor inconvenience today: It is possible to assign dates including times (which are not shown within the gadget) to DateGadgets (at least on Windows). I didn't know this and assumed that all operations cut off the times and made the "midnight time" out of the value. So I created a workaround, maybe this is somehow useful to someone else. Just include this code before any Set-/GetGadgetState-call.
Code: Select all
Procedure __SetGadgetState(Gadget.i,State.q)
If GadgetType(Gadget)=#PB_GadgetType_Calendar
State=Date(Year(State),Month(State),Day(State),0,0,0)
EndIf
ProcedureReturn SetGadgetState(Gadget,State)
EndProcedure
Macro SetGadgetState(ThisGadget,ThisState)
__SetGadgetState(ThisGadget,ThisState)
EndMacro
Procedure __GetGadgetState(Gadget.i)
Protected Temp.q=GetGadgetState(Gadget)
If GadgetType(Gadget)=#PB_GadgetType_Calendar
Temp=Date(Year(Temp),Month(Temp),Day(Temp),0,0,0)
EndIf
ProcedureReturn Temp
EndProcedure
Macro GetGadgetState(ThisGadget)
__GetGadgetState(ThisGadget)
EndMacro