[PB6.11] assembler backend (x86+x64) _DateUTC() bug

Just starting out? Need help? Post your questions and find answers here.
benubi
Enthusiast
Enthusiast
Posts: 219
Joined: Tue Mar 29, 2005 4:01 pm

[PB6.11] assembler backend (x86+x64) _DateUTC() bug

Post by benubi »

Hello, I don't know where to post it in the bug section so I post it here.

The program Atomic Webserver 3 uses _DateUTC() and on Windows (x86 and x64 - assembler backend) PB6.11 the imported procedure fails and returns a pointer or some other unusable value when called.

Would be nice if it could be used again in the next PB version as I started to play around with UTC dates and I'd like to write something that needs precise UTC date/time ;) & course it would be even better if we had a DateUTC() one day in PB's date library instead of using internals/API.

It still works fine on the Linux versions I tested and on the C backend (but it makes it more complicated to select/unselect the compiler in the options manually for every compilation when transferring/opening the source on the other OS'es IDE's - the Linux IDE's can't find the selected compiler).
CompilerSelect #PB_Compiler_OS ;for compatiblity with 6.04lts
CompilerCase #PB_OS_Windows
CompilerIf #PB_Compiler_32Bit
ImportC ""
_DateUTC.q(t = #Null) As "_time"
EndImport
CompilerElse
ImportC ""
_DateUTC.q(t = #Null) As "time"
EndImport
CompilerEndIf
CompilerCase #PB_OS_Linux
Procedure.q _DateUTC()
ProcedureReturn time_(#Null)
EndProcedure
CompilerCase #PB_OS_MacOS
ImportC ""
CFAbsoluteTimeGetCurrent.d()
EndImport
Procedure.q _DateUTC()
ProcedureReturn CFAbsoluteTimeGetCurrent() + Date(2001, 1, 1, 0, 0, 0)
EndProcedure
CompilerEndSelect
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: [PB6.11] assembler backend (x86+x64) _DateUTC() bug

Post by freak »

quidquid Latine dictum sit altum videtur
User avatar
idle
Always Here
Always Here
Posts: 5886
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: [PB6.11] assembler backend (x86+x64) _DateUTC() bug

Post by idle »

The function is only supposed to be imported for compatibility for pb6.04 and earlier
I will post the fix later today thanks.

Code: Select all

CompilerIf #PB_Compiler_Version <= 604 
  CompilerSelect #PB_Compiler_OS ;for compatiblity with 6.04lts mk-soft
    CompilerCase #PB_OS_Windows
      CompilerIf #PB_Compiler_32Bit
        ImportC "" 
          DateUTC.q(t=0) As "_time"  
        EndImport 
      CompilerElse   
        ImportC "" 
          DateUTC.q(t=0) As "time"  
        EndImport 
      CompilerEndIf
    CompilerCase #PB_OS_Linux
      Procedure.q DateUTC()
        ProcedureReturn time_(#Null)
      EndProcedure
    CompilerCase #PB_OS_MacOS
      ImportC ""
        CFAbsoluteTimeGetCurrent.d()
      EndImport
      Procedure.q DateUTC()
        ProcedureReturn CFAbsoluteTimeGetCurrent() + Date(2001, 1, 1, 0, 0, 0)
      EndProcedure
  CompilerEndSelect
CompilerEndIf 
benubi
Enthusiast
Enthusiast
Posts: 219
Joined: Tue Mar 29, 2005 4:01 pm

Re: [PB6.11] assembler backend (x86+x64) _DateUTC() bug

Post by benubi »

OMG it already exists :mrgreen: :lol:

Well, that's much better than I imagined.
I had it all backwards here.

Sorry & thanks to everybody :)
User avatar
idle
Always Here
Always Here
Posts: 5886
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: [PB6.11] assembler backend (x86+x64) _DateUTC() bug

Post by idle »

benubi wrote: Fri Jun 14, 2024 11:24 am OMG it already exists :mrgreen: :lol:

Well, that's much better than I imagined.
I had it all backwards here.

Sorry & thanks to everybody :)
Thank you, I didn't spot it as I'm mostly testing on Linux.
Mikes
New User
New User
Posts: 1
Joined: Tue May 14, 2024 10:11 am

Re: [PB6.11] assembler backend (x86+x64) _DateUTC() bug

Post by Mikes »

The ConvertDate function for 6.04 and below

Code: Select all

CompilerIf #PB_Compiler_Version <= 604 
  #PB_Date_LocalTime = 0
  #PB_Date_UTC = 1
  Procedure.q ConvertDate(ParmDate.q, ParmFormat.b) 
    If ParmFormat
      ProcedureReturn ParmDate - (Date() - DateUTC())
    Else
      ProcedureReturn ParmDate + (Date() - DateUTC())
    EndIf
  EndProcedure
CompilerEndIf
Test code

Code: Select all

EnableExplicit
Define UTCDateTime.q, LocalDateTime.q

UTCDateTime = DateUTC()
LocalDateTime = ConvertDate(UTCDateTime, #PB_Date_LocalTime)

Debug FormatDate("UTC time: %mm/%dd/%yyyy %hh:%ii:%ss", UTCDateTime)
Debug FormatDate("Local time: %mm/%dd/%yyyy %hh:%ii:%ss", LocalDateTime)
Debug FormatDate("Test Local back to UTC time: %mm/%dd/%yyyy %hh:%ii:%ss", ConvertDate(LocalDateTime, #PB_Date_UTC))
Post Reply