PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CPowerTime Class  (Read 146 times)

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3147
    • Jos
CPowerTime Class
« 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
« Last Edit: February 03, 2019, 08:08:00 PM by Josť Roca »
Logged

Wilko Verweij

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 160
  • PB10 - FF3.7 User; Win 10
    • CHEAQS
Re: CPowerTime Class
« Reply #1 on: February 03, 2019, 04:26:30 PM »

Thanks! Wilko
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8736
  • Windows 10
    • PlanetSquires Software
Re: CPowerTime Class
« Reply #2 on: February 03, 2019, 04:51:46 PM »

Awesome! Thanks so much.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8736
  • Windows 10
    • PlanetSquires Software
Re: CPowerTime Class
« Reply #3 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?
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3147
    • Jos
Re: CPowerTime Class
« Reply #4 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.

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3147
    • Jos
Re: CPowerTime Class
« Reply #5 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")
« Last Edit: February 03, 2019, 08:58:59 PM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3147
    • Jos
Re: CPowerTime Class
« Reply #6 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")
« Last Edit: February 03, 2019, 08:31:05 PM by Josť Roca »
Logged

Joerg Buckel

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 61
  • FF3 and WinFBE+WinFBX User
Re: CPowerTime Class
« Reply #7 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. :-))
« Last Edit: February 04, 2019, 02:55:53 PM by Joerg Buckel »
Logged
Greeting from Germany

Joerg