[Module] Calendar - Module (all OS)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1265
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

[Module] Calendar - Module (all OS)

Post by Thorsten1867 »

Calendar Gadget - Module (all OS / DPI / 64Bit)

Calendar is the light version of CalendarEx and is only intended for selecting a date.
  • support of Date64
  • automatic size adjustment
  • support of GUI themes (needs ModuleEx.pbi)
Image

Code: Select all

; Calendar::DefaultCountry()     - set default language for all gadgets
; Calendar::Disable()            - similar to 'DisableGadget()'
; Calendar::DisableReDraw()      - disable/enable redrawing of the gadget
; Calendar::Gadget()             - similar to 'CalendarGadget()'
; Calendar::GetAttribute()       - similar to 'GetGadgetAttribute()'
; Calendar::GetData()            - similar to 'GetGadgetData()'
; Calendar::GetDate()            - similar to 'Date()', but 64Bit
; Calendar::GetDay()             - returns selected day
; Calendar::GetID()              - similar to 'GetGadgetData()', but string instead of quad
; Calendar::GetMonth()           - returns selected month
; Calendar::GetState()           - similar to 'GetGadgetState()'
; Calendar::GetText()            - similar to 'GetGadgetText()'
; Calendar::GetYear()            - returns selected year
; Calendar::Hide()               - similar to 'HideGadget()'
; Calendar::MonthName()          - returns name of month in the current language
; Calendar::SetAutoResizeFlags() - [#MoveX|#MoveY|#Width|#Height]
; Calendar::SetColor()           - similar to 'SetGadgetColor()'
; Calendar::SetData()            - similar to 'SetGadgetData()'
; Calendar::SetDate()            - set date
; Calendar::SetFont()            - similar to 'SetGadgetFont()'
; Calendar::SetID()              - similar to 'SetGadgetData()', but string instead of quad
; Calendar::SetState()           - similar to 'SetGadgetState()'
; Calendar::WeekDayName()        - returns name of weekday in the current language
Download: CalendarModule.pbi
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]
Bitblazer
Enthusiast
Enthusiast
Posts: 443
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: [Module] Calendar - Module (all OS)

Post by Bitblazer »

Great modules, thanks :)

A little warning though - it all relies on the date64 functions and at the bottom of them, they have a system call which works great in win10, but in win7, the date times are limited from 1970 upwards.
If the calendargadget shows a year below 1970, some calls will return 1.1.1970 as that is the lowest time the used windows API call knows (1.1.1970 is 0 in windows 7, it is the unix/posix epoch time beginning).
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 452
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: [Module] Calendar - Module (all OS)

Post by Sicro »

Bitblazer wrote:A little warning though - it all relies on the date64 functions and at the bottom of them, they have a system call which works great in win10, but in win7, the date times are limited from 1970 upwards.
If the calendargadget shows a year below 1970, some calls will return 1.1.1970 as that is the lowest time the used windows API call knows (1.1.1970 is 0 in windows 7, it is the unix/posix epoch time beginning).
I have just tested it on Windows 7 x64 and can't find any 1970 limit. Do you have a sample code that demonstrates the problem? Note that this module draws its own calendar gadget and does not use the calendar gadget from PureBasic.

The Date64 module supports the following date range under Windows:
  • Minimum: 01.01.1601 00:00:00
  • Maximum: 31.12.9999 23:59:59
Image
Why OpenSource should have a license :: DarkColor-Scheme for PureBasic
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Any help is welcome!
Manjaro Xfce x64 (Main system) :: Windows 7 x64 (VirtualBox) :: Newest PureBasic version
Bitblazer
Enthusiast
Enthusiast
Posts: 443
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: [Module] Calendar - Module (all OS)

Post by Bitblazer »

I guess it depends which system function you trigger with a date64 call. I requested the state of a calendar gadget with a date in 1966 and calculated the year to display it. During that process, a windows system function was called. So i used CalendarEx::GetState() and then the CalendarEX::Year() function triggered a system call and that returned 1.1.1970 due to a request outside the supported range. It is actually documented here and this limitation seems to come from some of the supported operating systems (1.1.1970 is the Posix epoch time).
It showed up in my windows 7 english ultimate 64-Bit MSDN version and is gone in windows 10. So i guess it is useful for operating system fingerprinting ;)

It might depend on the actual win7 version (oem, retail, S, home, professional, ultimate etc.)

I discussed it a bit on the purebasic discord server where i also pasted some MSDN/wikipedia references.

IT/CS can be a real mess. No matter if you explore DPI, Date, Font, Image or archive formats. The deeper you dig, the uglier it gets. For fun: https://en.wikipedia.org/wiki/Unix_time

ps: 2038 will be a glorious year for software developers and newspapers, probably not for the computer users ;)
pps: more date fun and many widely used programming languages actually have the same limitation
Last edited by Bitblazer on Sat Jul 11, 2020 3:10 pm, edited 1 time in total.
Bitblazer
Enthusiast
Enthusiast
Posts: 443
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: [Module] Calendar - Module (all OS)

Post by Bitblazer »

Sicro wrote:The Date64 module supports the following date range under Windows:
  • Minimum: 01.01.1601 00:00:00
  • Maximum: 31.12.9999 23:59:59
Thats actually why i posted this little warning. This problem lurks in the background and is only triggered by some conversion functions of the operating system. I could compile a test binary and then debug it to pinpoint the windows 7 system call, but it seems to depend on my specific windows 7 version. I am glad i noticed it on my system before it happened on a customer machine.

The windows it happened on, was windows7 ultimate english 64bit with all patches up to date.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 452
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: [Module] Calendar - Module (all OS)

Post by Sicro »

Bitblazer wrote:So i used CalendarEx::GetState() and then the CalendarEX::Year() function triggered a system call and that returned 1.1.1970 due to a request outside the supported range.

Code: Select all

; CalendarEx::GetState()           - returns selected date

[...]

Declare.i GetState(GNum.i)
At first I suspected that the problem arises with you because of the above mistake. GetState() must return a quad value to support the full date range of Date64. But for you the error can't be the culprit if I read this:
Bitblazer wrote:It showed up in my windows 7 english ultimate 64-Bit
Did you maybe compile the program as 32-bit?
Bitblazer wrote:1.1.1970 is the Posix epoch time
Yes, but dates before that are still possible by returning a negative seconds value.
Bitblazer wrote:ps: 2038 will be a glorious year for software developers and newspapers, probably not for the computer users ;)
Many systems have switched to 64-bit Unix timestamps. Windows does not use Unix timestamps and is therefore not affected by the problem.
Windows
1 January 1601 to 14 September 30,828
https://en.wikipedia.org/wiki/System_ti ... ng_systems
Bitblazer wrote:This problem lurks in the background and is only triggered by some conversion functions of the operating system. I could compile a test binary and then debug it to pinpoint the windows 7 system call, but it seems to depend on my specific windows 7 version.
These are the best bugs (which can't be tested properly). :(
Image
Why OpenSource should have a license :: DarkColor-Scheme for PureBasic
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Any help is welcome!
Manjaro Xfce x64 (Main system) :: Windows 7 x64 (VirtualBox) :: Newest PureBasic version
Bitblazer
Enthusiast
Enthusiast
Posts: 443
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: [Module] Calendar - Module (all OS)

Post by Bitblazer »

Just for fun, i digged a bit deeper into this problem. The problem is not a date function limitation of my win7 version, but this call's parameter

http://bitblazer.de/files/date64problem.jpg

It is 0 with my win7 installation. The Gadget number (GNum) is correct and the map element is found, but this line results in a parameter of 0 for the Day_() call. And 0 is correctly decoded as 1.1.1970 :)

So the problem is the Calendar()\Current\Focus reference.

ps: sorry, but the forum software didnt let me include the image because "It is not possible to determine the dimensions of the image.". So i can just provide this link. (forum update/fix time?)
Post Reply