Extending the date range of the date gadget?

Just starting out? Need help? Post your questions and find answers here.
epog10
User
User
Posts: 90
Joined: Sat May 29, 2010 11:46 am
Location: UK

Re: Extending the date range of the date gadget?

Post by epog10 »

Incidentally, if you manually change the year component of the date gadget i.e. the line giving dd/mm/yyyy, then when you open the date gadget calendar it will have the correct year.

The only problem is that the day of week will be wrong if you then extract a required date.

My solution was:-

Code: Select all

Procedure TexDay()
  y = iyear                                                     ;Save the year (in case modified)
  If y < 1970
    y = y + 56                                                  ;Adjust year if out of Unix range
  EndIf
  X = DayOfWeek(Date(Y,iMONTH,iDAY,0,0,0))
  Select X
     Case 0
       aNS1 = "Sun"
     Case 1
       aNS1 = "Mon"
     Case 2
       aNS1 = "Tue"
     Case 3
       aNS1 = "Wed"
     Case 4
       aNS1 = "Thu"
     Case 5
       aNS1 = "Fri"
     Case 6
       aNS1 = "Sat"
  EndSelect
EndProcedure
By adding 56 it brings the (birth)day within the 1970 year, corrected for leap years etc..

So that takes you to 1914 which should cater for most birthdays. Presumably adding 112 will cater for even older dates but you may need to test for number year range otherwise adding the 112 range to all dates might take you 'over the top' in the other direction!

Regards,

Ernest
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Thanks but...

Post by MachineCode »

c4s wrote:If you sum up every second from 1970 on, a LONG variable will be filled in 2038.
So, is it just a matter of PureBasic using a QUAD variable instead, or does Windows not support that for dates either?
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
BarryG
Addict
Addict
Posts: 3333
Joined: Thu Apr 18, 2019 8:17 am

Re:

Post by BarryG »

freak wrote:Now getting and setting the dates in the DateGadget is quite easy:

Code: Select all

SendMessage_(GadgetID(#YourGadget), #DTM_GETSYSTEMTIME, 0, @CurrentDate.SYSTEMTIME)
Easy? I don't know about that. How do I get the result of SendMessage into a variable? Thank you.
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Extending the date range of the date gadget?

Post by mk-soft »

The last parameter for Get and Set Date is ByRef.
Thus the pointer to the memory with the structure of SYSTEMTIME
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 3333
Joined: Thu Apr 18, 2019 8:17 am

Re: Extending the date range of the date gadget?

Post by BarryG »

mk-soft wrote:The last parameter for Get and Set Date is ByRef.
Thus the pointer to the memory with the structure of SYSTEMTIME
https://youtu.be/okiMnLyCMbA?t=62

Not sure what you mean. I've tried this, but it doesn't work:

Code: Select all

SendMessage_(calendar,#DTM_GETSYSTEMTIME,0,@calchoice.SYSTEMTIME)
calendarsel=Date(calchoice\wYear,calchoice\wMonth,calchoice\wDay,0,0,0)
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Extending the date range of the date gadget?

Post by Sicro »

Code: Select all

calendar = DateGadget(#PB_Any, ...)
SendMessage_(GadgetID(calendar),#DTM_GETSYSTEMTIME,0,@calchoice.SYSTEMTIME)
or

Code: Select all

DateGadget(0, ...)
SendMessage_(GadgetID(0),#DTM_GETSYSTEMTIME,0,@calchoice.SYSTEMTIME)
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
BarryG
Addict
Addict
Posts: 3333
Joined: Thu Apr 18, 2019 8:17 am

Re: Extending the date range of the date gadget?

Post by BarryG »

Sirco, I don't understand. I can easily SET the CalendarGadget to any date after the year 2038, but I can't GET the selected date when the user is browsing the gadget past the year 2038 (such as when they click 20 January 2038). That's what I'm trying to do. I'm using the Date64 lib. See this post for an example: viewtopic.php?p=536713#p536713
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Extending the date range of the date gadget?

Post by Kurzer »

Barry, in 2017 I extended the Date64 module of wilbert / davodo with commands that allow the use of a 64 bit date with the PureBasic DateGadget and the CalendarGadget.

You are welcome to have a look at it. The module contains an example code that shows the function with both types of DateGadgets.

Image

Here you'll find the thread with the module source:
viewtopic.php?p=478507#p478507

Greeting
Kurzer
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
BarryG
Addict
Addict
Posts: 3333
Joined: Thu Apr 18, 2019 8:17 am

Re: Extending the date range of the date gadget?

Post by BarryG »

kurzer wrote:You are welcome to have a look at it. The module contains an example code that shows the function with both types of DateGadgets.
Hi Kurzer, I tried it but couldn't get it to work with my existing code (even when I used Macros to rename the Date64 names). I have no idea what I was doing wrong, because the example code works as a standalone demo.

To explain what I mean, this never gave me the date for anything in 2039 and beyond, but did work for 2038 and earlier:

Code: Select all

EnableDateGadgetEvent64()
calendarsel.q = Date64::GetDateGadget64(#calendar)
I'll have to look at it another day when I have more time. Thanks for trying to help, though.

Side-note: It doesn't support SetGadgetItemState() for setting calendar dates to bold.

I just wish the native Date functions could be updated to get with the times. :(
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Extending the date range of the date gadget?

Post by Kurzer »

Without seeing your code, I can't say much about it. But you can see that GetDateGadget64() works on the demo code.
BarryG wrote:Side-note: It doesn't support SetGadgetItemState() for setting calendar dates to bold.
That's correct, but that's where the procedure SetDateGadget64() comes in. This allows you to set a date in the calendar gadget. When you look at the demo code, you will notice that the date in the calendar is set to December 01, 2037 with exactly this command. This date will also be highlighted in the calendar.

Unfortunately the description of the procedure SetDateGadget64() by a copy/paste error is wrong. Don't let this irritate you.
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
BarryG
Addict
Addict
Posts: 3333
Joined: Thu Apr 18, 2019 8:17 am

Re: Extending the date range of the date gadget?

Post by BarryG »

kurzer wrote:you can see that GetDateGadget64() works on the demo code.
I know, so that's why it's something I've done wrong. I'm too tired to keep looking now, so I'll revisit in future. Thanks for the code, I'm sure I'll spot the problem one day.
Post Reply