Strange timing

Just starting out? Need help? Post your questions and find answers here.
ALAN-MHz
User
User
Posts: 68
Joined: Fri Jul 29, 2005 11:47 am

Strange timing

Post by ALAN-MHz »

Dear all, i see a delphi application that have some strange system date management, i just want to know if i can replicate in purebasic, i cannot explain in detail but i can give some value examples:

$40E6000000000000 = 2023/05/10
$40E5000000000000 = 2017/09/30
$40E4000000000000 = 2012/02/21

can anyone help me ? Thanks!
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Strange timing

Post by kpeters58 »

That won't be easy :(

Delphi's time/date is based on:
http://docs.embarcadero.com/products/ra ... eTime.html

Purebasic unfortunately still uses the ancient UNIX 32bit time system that only supports dates between (roughly) 1970 and 2038.

You could write your own conversion routines if you can live with these limitations...
PB 5.73 on Windows 10 & OS X High Sierra
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Strange timing

Post by wilbert »

After a bit of experimenting, this seems to work

Code: Select all

Procedure.i ConvertDate(delphiDate.q)
  Protected *date.Double = @delphiDate
  ProcedureReturn (*date\d + 24142)*86400
EndProcedure

date = ConvertDate($40E6000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

date = ConvertDate($40E5000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

date = ConvertDate($40E4000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)
Windows (x64)
Raspberry Pi OS (Arm64)
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Strange timing

Post by firace »

wilbert wrote:After a bit of experimenting, this seems to work

Code: Select all

Procedure.i ConvertDate(delphiDate.q)
  Protected *date.Double = @delphiDate
  ProcedureReturn (*date\d + 24142)*86400
EndProcedure

date = ConvertDate($40E6000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

date = ConvertDate($40E5000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

date = ConvertDate($40E4000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

Not here:

Code: Select all

00/00/0000
00/00/0000
00/00/0000
(PB 5.62 x86)
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Strange timing

Post by firace »

Had to add Int() to make it work:

Code: Select all

Procedure.i ConvertDate(delphiDate.q)
  Protected *date.Double = @delphiDate
  ProcedureReturn (Int(*date\d) + 24142)*86400
EndProcedure

date = ConvertDate($40E6000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

date = ConvertDate($40E5000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

date = ConvertDate($40E4000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Strange timing

Post by wilbert »

:?
Strange that Int is required.
A bug ?
Windows (x64)
Raspberry Pi OS (Arm64)
fryquez
Enthusiast
Enthusiast
Posts: 362
Joined: Mon Dec 21, 2015 8:12 pm

Re: Strange timing

Post by fryquez »

On x86, you need to change the return type to quad.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Strange timing

Post by wilbert »

fryquez wrote:On x86, you need to change the return type to quad.
So if the integer conversion procedure would also be required on some OS, it would be like

Code: Select all

Procedure.q ConvertDate(delphiDate.q)
  Protected *date.Double = @delphiDate
  ProcedureReturn IntQ((*date\d + 24142)*86400)
EndProcedure

date = ConvertDate($40E6000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

date = ConvertDate($40E5000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)

date = ConvertDate($40E4000000000000)
Debug FormatDate("%mm/%dd/%yyyy", date)
Windows (x64)
Raspberry Pi OS (Arm64)
ALAN-MHz
User
User
Posts: 68
Joined: Fri Jul 29, 2005 11:47 am

Re: Strange timing

Post by ALAN-MHz »

Thanks to all, i'll try as soon as possible!

sorry, i try to understand the code, you take the pointer of quad value and insert as pointer in a double value (in fact if i read bytes from double contents i see the same of bytes of quad contents), but i don't understand *date\d, what conversion do ?
Post Reply