Set-/GetGadgetState on DateGadget without time

Share your advanced PureBasic knowledge/code with the community.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Set-/GetGadgetState on DateGadget without time

Post by jacdelad »

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
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Set-/GetGadgetState on DateGadget without time

Post by BarryG »

jacdelad wrote: Wed Nov 22, 2023 11:15 pmIt is possible to assign dates including times (which are not shown within the gadget) to DateGadgets
Times have always been shown in the DateGadget; it just depends on the width of the gadget. Too small and they get cropped.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Set-/GetGadgetState on DateGadget without time

Post by jacdelad »

Oh really? I never tried that. I use the dialog library and it doesn't even try to show times. Good to know, thanks.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
HeX0R
Addict
Addict
Posts: 1204
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Set-/GetGadgetState on DateGadget without time

Post by HeX0R »

Code: Select all

Procedure.s GetXMLString()
	Protected XML$

	XML$ + "<?xml version='1.0' encoding='UTF-16'?>"
	XML$ + ""
	XML$ + "<dialogs><!--Created by Dialog Design0R V1.85 => get it from: https://hex0rs.coderbu.de/en/sdm_downloads/dialogdesign0r/-->"
	XML$ + "  <window flags='#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered' name='window_1' xpos='16' ypos='157'>"
	XML$ + "    <vbox>"
	XML$ + "      <date name='date_1' text='%dd.%mm.%yyyy %hh:%ii'/>"
	XML$ + "    </vbox> "
	XML$ + "  </window>"
	XML$ + "</dialogs><!--DDesign0R Definition: PureBasic|1|1|1|_|example_with_declares|0|AddOn:3:0-->"

	ProcedureReturn XML$
EndProcedure
;Test it
a$ = GetXMLString()
ParseXML(0, a$)
CreateDialog(0)
OpenXMLDialog(0, 0, "window_1")
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
Post Reply