PlanetSquires Forums

Support Forums => WinFBX - Windows Framework for FreeBASIC => Topic started by: Josť Roca on February 03, 2019, 03:28:10 PM

Title: CPowerTime Class
Post by: Josť Roca on February 03, 2019, 03:28:10 PM
A new class, CPowerTime, to easily work with date and time calculations.

Documentation:
https://github.com/JoseRoca/WinFBX/blob/master/docs/DateTime/CPowerTime%20Class.md
Title: Re: CPowerTime Class
Post by: Wilko Verweij on February 03, 2019, 04:26:30 PM
Thanks! Wilko
Title: Re: CPowerTime Class
Post by: Paul Squires on February 03, 2019, 04:51:46 PM
Awesome! Thanks so much.
Title: Re: CPowerTime Class
Post by: Paul Squires on February 03, 2019, 05:36:22 PM
I'm browsing through the class and thinking thoughts like, what if I have have a starting powertime and and ending powertime class how would I determine the difference between the two class instances. For example, let's say we want to profile a section of code or an algorithm. Maybe retrieve both using the GetFileTime property and do the difference calculation?
Title: Re: CPowerTime Class
Post by: Josť Roca on February 03, 2019, 06:28:58 PM
Yes. You can do:

Code: [Select]
DIM cpt AS CPowerTime
DIM cpt2 AS CPowerTime
cpt.Now
print "Press a key"
sleep
cpt2.Now
DIM nTime AS ULONGLONG = cpt2 - cpt
print nTime / CPowerTime_Millisecond
print nTime / CPowerTime_Second
print nTime

BTW there are two methods in the PowerBasic PowerTime object that I already haven't implemented: DateDiff and TimeDiff. Not sure how to code them.
Title: Re: CPowerTime Class
Post by: Josť Roca on February 03, 2019, 07:37:00 PM
I'm going to add these properties

Code: [Select]
' ========================================================================================
' Gets/sets the date and time as a FreeBasic date serial.
' ========================================================================================
PRIVATE PROPERTY CPowerTime.DateSerial () AS DOUBLE
   DIM ft AS FILETIME
   ft.dwLowDateTime = dwLowDateTime
   ft.dwHighDateTime = dwHighDateTime
   DIM dt AS DOUBLE, st AS SYSTEMTIME
   FileTimeToSystemTime(@ft, @st)
   SystemTimeToVariantTime @st, @dt
   RETURN dt
END PROPERTY
' ========================================================================================
' ========================================================================================
PRIVATE PROPERTY CPowerTime.DateSerial (BYVAL dTime AS DOUBLE)
   DIM st AS SYSTEMTIME
   VariantTimeToSystemTime dTime, @st
   DIM ft AS FILETIME
   SystemTimeToFileTime @st, @ft
   dwLowDateTime = ft.dwLowDateTime
   dwHighDateTime = ft.dwHighDateTime
END PROPERTY
' ========================================================================================

They will allow to use CPowerTime with the FreeBasic date serial procedures, e.g.:

Code: [Select]
DIM ct AS CPowerTime
ct.DateSerial = DateSerial(2019, 2, 4)
Print Format(ct.DateSerial, "yyyy/mm/dd hh:mm:ss")
Title: Re: CPowerTime Class
Post by: Josť Roca on February 03, 2019, 08:10:46 PM
I have added these properties and reuploaded the zip file. Now we can use the FreeBasic DateSerial, DateValue, TimeValue, TimeSerial, Now and Format procedures with CPowerTime.

Code: [Select]
DIM ct AS CPowerTime
ct.DateSerial = DateSerial(2019, 2, 4)
ct.DateSerial = DateValue("4/2/2019")
ct.DateSerial = TimeValue("11:59:59PM")
ct.DateSerial = Now
ct.DateSerial = DateSerial(2005, 11, 28) + TimeSerial(7, 30, 50)
Print Format(ct.DateSerial, "yyyy/mm/dd hh:mm:ss")
Title: Re: CPowerTime Class
Post by: Joerg Buckel on February 04, 2019, 02:48:11 PM
Hola JosŤ
Thank you for your expansion. I already appreciated this under PowerBasic.
Quote
BTW there are two methods in the PowerBasic PowerTime object that I already haven't implemented: DateDiff and TimeDiff. Not sure how to code them.

I'm sure you can think a solution. :-))