Author Topic: Request for next QB64 Release, Time Zone information  (Read 3433 times)

0 Members and 1 Guest are viewing this topic.

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Request for next QB64 Release, Time Zone information
« on: March 27, 2020, 08:14:00 pm »
I would like to put in a request for the next QB64 release.

Could a function be added to give the local time zone?
This would allow UTC to be computed by adding an offset to the computer's local time value.

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Request for next QB64 Release, Time Zone information
« Reply #1 on: March 27, 2020, 09:29:02 pm »
Microsoft documentation for the Time Zone Information structure

TIME_ZONE_INFORMATION structure
https://docs.microsoft.com/en-us/windows/win32/api/timezoneapi/ns-timezoneapi-time_zone_information

Perhaps a QB64 function could be added to the compiler that would return all of this available information?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Request for next QB64 Release, Time Zone information
« Reply #2 on: March 28, 2020, 06:39:03 am »
Hi. You won't wait:

Code: QB64: [Select]
  1.     FUNCTION GetUserDefaultLCID%
  2.     FUNCTION GetSystemDefaultLangID%
  3.     SUB GetTimeZoneInformation (a AS INTEGER)
  4.  
  5.  
  6.  
  7. PRINT "Your time zone is:"; GETTIMEZONE; "and your default language ID code is:"; GETLCID
  8. 'for LCID use this table https://www.science.co.il/language/Locale-codes.php  and 3th column.
  9.  
  10.  
  11. FUNCTION GETTIMEZONE
  12.     DIM b AS INTEGER
  13.     GetTimeZoneInformation b
  14.     GETTIMEZONE = b / -60 'so it return time zone in hours (+1 for Prague)
  15.  
  16. FUNCTION GETLCID
  17.     GETLCID = GetUserDefaultLCID%
  18.     IF GetUserDefaultLCID% = 0 AND GetSystemDefaultLangID% THEN GETLCID = GetSystemDefaultLangID%
  19.     IF GetUserDefaultLCID% = 0 AND GetSystemDefaultLangID% = 0 THEN GETLCID = -1 'error finding LCID
  20.  

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Request for next QB64 Release, Time Zone information
« Reply #3 on: March 28, 2020, 09:27:11 am »
Thank you Petr.
This is useful.

One question about your code.
Should the function GetTimeZoneInformation parameter be a pointer to a TIME_ZONE_INFORMATION structure?

https://docs.microsoft.com/en-us/windows/win32/api/timezoneapi/nf-timezoneapi-gettimezoneinformation

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Request for next QB64 Release, Time Zone information
« Reply #4 on: March 28, 2020, 11:08:20 am »
Hi EricE, no. This is not pointer to this structure, but parameter (a as INTEGER) return your time shift in minutes. You can try it, if you set other time zone in time settings in Windows.

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Request for next QB64 Release, Time Zone information
« Reply #5 on: March 28, 2020, 03:58:20 pm »
Here is a program for calling GetTimeZoneInformation with an INTEGER parameter.

Code: QB64: [Select]
  1.     SUB GetTimeZoneInformation (a AS INTEGER)
  2.  
  3. tz& = GETTIMEZONE
  4. PRINT "Your time zone is:"; tz&  
  5.  
  6. FUNCTION GETTIMEZONE
  7.     DIM b AS INTEGER
  8.        
  9.     GetTimeZoneInformation b
  10.     PRINT "GetTimeZoneInformation = ";b
  11.        
  12.     GETTIMEZONE = b / -60 'so it return time zone in hours (+1 for Prague)

On my computer this is the output:

GetTimeZoneInformation =  480
Your time zone is:-8


My location is on Pacific Time (UTC-7), so the correct time zone for me should be -7.





Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Request for next QB64 Release, Time Zone information
« Reply #6 on: March 28, 2020, 04:57:49 pm »
Here is a QB64 program that calls the GetTimeZoneInformation function in a way according to the Microsoft API documentation.
The output of the program for my location gives a value of -60 for the DayloghtBias, and using that value to adjust the Bias value of 480 gives the correct value for my local time zone.

time zone = (480-60)/(-60) = -7

Why does Petr's program give the correct value for the time zone bias (for my computer 480) when the GetTimeZoneInformation function is called differently from the way the Microsoft documentation indicates? It should not work, but it does.

Code: QB64: [Select]
  1. TYPE SYSTEMTIME
  2.   wMonth AS _UNSIGNED INTEGER
  3.   wDayOfWeek AS _UNSIGNED INTEGER
  4.   wMinute AS _UNSIGNED INTEGER
  5.   wSecond AS _UNSIGNED INTEGER
  6.   wMilliseconds AS _UNSIGNED INTEGER
  7.  
  8. TYPE TIME_ZONE_INFORMATION
  9.   Bias as LONG
  10.   StandardName AS String*64 'WCHAR      StandardName[32];
  11.   StandardDate AS SYSTEMTIME
  12.   StandardBias AS LONG
  13.   DaylightName AS STRING*64 'WCHAR      DaylightName[32];
  14.   DaylightDate AS SYSTEMTIME
  15.   DaylightBias AS LONG
  16.  
  17. ' Function prototype:
  18. ' DWORD GetTimeZoneInformation( LPTIME_ZONE_INFORMATION lpTimeZoneInformation);
  19.   FUNCTION GetTimeZoneInformation& (BYVAL lpTimeZoneInformation AS _UNSIGNED _OFFSET)
  20.  
  21. DIM tz_info AS TIME_ZONE_INFORMATION
  22.  
  23. retval& = GetTimeZoneInformation(_OFFSET(tz_info))
  24.  
  25. PRINT "Returned Value = ";retval&
  26. PRINT "TZ INFO"
  27. PRINT " Bias = ";tz_info.Bias
  28. print " StandardName = ";tz_info.StandardName
  29. PRINT " Standard Date"
  30. PRINT "   wYear        = ";tz_info.StandardDate.wYear
  31. PRINT "   wMonth       = ";tz_info.StandardDate.wMonth
  32. PRINT "   wDayOfWeek   = ";tz_info.StandardDate.wDayOfWeek
  33. PRINT "   wDay         = ";tz_info.StandardDate.wDay
  34. PRINT "   wHour        = ";tz_info.StandardDate.wHour
  35. PRINT "   wMinute      = ";tz_info.StandardDate.wMinute
  36. PRINT "   wSecond      = ";tz_info.StandardDate.wSecond
  37. PRINT "   wMillisecons = ";tz_info.StandardDate.wMilliseconds
  38. PRINT " StandardBias = ";tz_info.StandardBias
  39. PRINT "Press any key to continue"
  40. PRINT " DaylightName = ";tz_info.DaylightName
  41. PRINT " DaylightDate"
  42. PRINT "   wYear        = ";tz_info.DaylightDate.wYear
  43. PRINT "   wMonth       = ";tz_info.DaylightDate.wMonth
  44. PRINT "   wDayOfWeek   = ";tz_info.DaylightDate.wDayOfWeek
  45. PRINT "   wDay         = ";tz_info.DaylightDate.wDay
  46. PRINT "   wHour        = ";tz_info.DaylightDate.wHour
  47. PRINT "   wMinute      = ";tz_info.DaylightDate.wMinute
  48. PRINT "   wSecond      = ";tz_info.DaylightDate.wSecond
  49. PRINT "   wMillisecons = ";tz_info.DaylightDate.wMilliseconds
  50. PRINT " DaylightBias = ";tz_info.DaylightBias
« Last Edit: March 28, 2020, 05:14:20 pm by EricE »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Request for next QB64 Release, Time Zone information
« Reply #7 on: March 28, 2020, 05:22:09 pm »
Thank you for the information, in fact, you are the first, which test this with me. :)

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Request for next QB64 Release, Time Zone information
« Reply #8 on: March 28, 2020, 05:56:45 pm »
Petr,

I have started a new thread regarding the GetTimeZoneInformation function.
It is important we understand as it involves how to call a Win32 API function.

Also, testing is fun! :)