Page 2 of 2

Re: Extending the date range of the date gadget?

Posted: Thu Dec 22, 2011 12:30 pm
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

Re: Thanks but...

Posted: Thu Dec 22, 2011 1:06 pm
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?

Re:

Posted: Sat May 18, 2019 6:13 am
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.

Re: Extending the date range of the date gadget?

Posted: Sat May 18, 2019 11:41 am
by mk-soft
The last parameter for Get and Set Date is ByRef.
Thus the pointer to the memory with the structure of SYSTEMTIME

Re: Extending the date range of the date gadget?

Posted: Sat May 18, 2019 1:11 pm
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)

Re: Extending the date range of the date gadget?

Posted: Sat May 18, 2019 4:59 pm
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)

Re: Extending the date range of the date gadget?

Posted: Sun May 19, 2019 12:23 am
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

Re: Extending the date range of the date gadget?

Posted: Sun May 19, 2019 7:59 am
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

Re: Extending the date range of the date gadget?

Posted: Sun May 19, 2019 11:19 am
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. :(

Re: Extending the date range of the date gadget?

Posted: Sun May 19, 2019 12:25 pm
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.

Re: Extending the date range of the date gadget?

Posted: Sun May 19, 2019 12:56 pm
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.